use of org.olat.modules.fo.Message in project openolat by klemens.
the class MessageListController method doReply.
private void doReply(UserRequest ureq, MessageView parent, boolean quote) {
// user has clicked on button 'reply'
if (foCallback.mayReplyMessage()) {
Message newMessage = forumManager.createMessage(forum, getIdentity(), guestOnly);
Message parentMessage = forumManager.getMessageById(parent.getKey());
if (parentMessage == null) {
handleEditError(ureq);
return;
}
String reString = "";
if (parent != null && parent.isThreadTop()) {
// add reString only for the first answer
reString = translate("msg.title.re");
}
newMessage.setTitle(reString + parentMessage.getTitle());
if (quote) {
// load message to form as quotation
StringBuilder quoteSb = new StringBuilder();
quoteSb.append("<p></p><div class=\"o_quote_wrapper\"><div class=\"o_quote_author mceNonEditable\">");
String date = formatter.formatDateAndTime(parentMessage.getCreationDate());
String creatorName;
if (StringHelper.containsNonWhitespace(parentMessage.getPseudonym())) {
creatorName = parentMessage.getPseudonym();
} else if (parentMessage.isGuest()) {
creatorName = translate("guest");
} else {
User creator = parentMessage.getCreator().getUser();
creatorName = creator.getProperty(UserConstants.FIRSTNAME, getLocale()) + " " + creator.getProperty(UserConstants.LASTNAME, getLocale());
}
quoteSb.append(translate("msg.quote.intro", new String[] { date, creatorName })).append("</div><blockquote class=\"o_quote\">").append(parentMessage.getBody()).append("</blockquote></div>").append("<p></p>");
newMessage.setBody(quoteSb.toString());
}
replyMessageCtrl = new MessageEditController(ureq, getWindowControl(), forum, foCallback, newMessage, parentMessage, EditMode.reply);
listenTo(replyMessageCtrl);
String title = quote ? translate("msg.quote") : translate("msg.reply");
cmc = new CloseableModalController(getWindowControl(), "close", replyMessageCtrl.getInitialComponent(), true, title);
listenTo(cmc);
cmc.activate();
} else {
showInfo("may.not.reply.msg");
}
}
use of org.olat.modules.fo.Message in project openolat by klemens.
the class ForumWebService method getAttachments.
/**
* Retrieves the attachments of the message
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The links to the attachments
* @response.representation.404.doc The message not found
* @param messageKey The key of the message
* @param uriInfo The URI information
* @return The attachments
*/
@GET
@Path("posts/{messageKey}/attachments")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getAttachments(@PathParam("messageKey") Long messageKey, @Context UriInfo uriInfo) {
// load message
Message mess = fom.loadMessage(messageKey);
if (mess == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
if (!forum.equalsByPersistableKey(mess.getForum())) {
return Response.serverError().status(Status.CONFLICT).build();
}
FileVO[] attachments = getAttachments(mess, uriInfo);
return Response.ok(attachments).build();
}
use of org.olat.modules.fo.Message in project openolat by klemens.
the class ForumController method doProcessSelectEvent.
private void doProcessSelectEvent(UserRequest ureq, SelectMessageEvent sme) {
Message thread = fm.getMessageById(sme.getMessageKey());
if (thread == null) {
logError("Thread doesn't exists: " + sme.getMessageKey(), new Exception());
reloadThreadList = true;
doThreadList(ureq);
} else {
Message scrollTo = null;
if (sme.getScrollToMessageKey() != null) {
scrollTo = fm.getMessageById(sme.getScrollToMessageKey());
}
if (SelectMessageEvent.SELECT_THREAD.equals(sme.getCommand())) {
doThreadView(ureq, thread, scrollTo);
} else if (SelectMessageEvent.SELECT_MARKED.equals(sme.getCommand())) {
doMarkedView(ureq, thread, scrollTo);
} else if (SelectMessageEvent.SELECT_NEW.equals(sme.getCommand())) {
doNewView(ureq, thread, scrollTo);
}
}
}
use of org.olat.modules.fo.Message in project openolat by klemens.
the class ForumController method activate.
@Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
if (entries == null || entries.isEmpty()) {
doThreadList(ureq);
} else {
String type = entries.get(0).getOLATResourceable().getResourceableTypeName();
if ("Message".equalsIgnoreCase(type)) {
Long resId = entries.get(0).getOLATResourceable().getResourceableId();
if (resId.longValue() != 0) {
Message message = fm.getMessageById(resId);
if (message != null) {
doThreadList(ureq);
Message thread = message.getThreadtop() == null ? message : message.getThreadtop();
if (focallback.mayEditMessageAsModerator() || !Status.getStatus(thread.getStatusCode()).isHidden()) {
String subType = null;
if (entries.size() > 1) {
subType = entries.get(1).getOLATResourceable().getResourceableTypeName();
}
if ("Marked".equalsIgnoreCase(subType)) {
doMarkedView(ureq, thread, message);
} else if ("New".equalsIgnoreCase(subType)) {
doMarkedView(ureq, thread, message);
} else {
doThreadView(ureq, thread, message);
}
}
}
}
} else if ("Identity".equalsIgnoreCase(type)) {
Long resId = entries.get(0).getOLATResourceable().getResourceableId();
doUserList(ureq);
if (resId.longValue() > 0) {
doUserMessageList(ureq, resId);
}
}
}
}
use of org.olat.modules.fo.Message in project openolat by klemens.
the class ForumManager method moveMessage.
/**
* Moves the current message from the current thread in another thread.
*
* @param msg
* @param topMsg
* @return the moved message
*/
public Message moveMessage(Message msg, Message topMsg) {
// one has to set a new parent for all children of the moved message
// first message of sublist has to get the parent from the moved message
List<Message> children = getMessageChildren(msg);
for (Message child : children) {
child.setParent(msg.getParent());
dbInstance.getCurrentEntityManager().merge(child);
}
// now move the message to the chosen thread
Message targetThread = topMsg.getThreadtop();
if (targetThread == null) {
targetThread = topMsg;
}
final Message oldMessage = getMessageById(msg.getKey());
Message message = persistMessageInAnotherLocation(msg, oldMessage.getForum(), targetThread, topMsg);
// move marks
OLATResourceable ores = OresHelper.createOLATResourceableInstance(Forum.class, msg.getForum().getKey());
markingService.getMarkManager().moveMarks(ores, msg.getKey().toString(), message.getKey().toString());
moveMessageContainer(oldMessage.getForum().getKey(), oldMessage.getKey(), message.getForum().getKey(), message.getKey());
deleteMessageRecursion(oldMessage.getForum().getKey(), oldMessage);
return message;
}
Aggregations