use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class MessageListController method doDeleteMessage.
private void doDeleteMessage(UserRequest ureq, MessageView message) {
boolean userIsMsgCreator = message.isAuthor();
if (foCallback.mayDeleteMessageAsModerator() || (userIsMsgCreator && forumManager.countMessageChildren(message.getKey()) == 0)) {
Message reloadedMessage = forumManager.getMessageById(message.getKey());
if (reloadedMessage != null) {
// this delete the topic / thread
if (reloadedMessage.getParent() == null) {
forumManager.deleteMessageTree(forum.getKey(), reloadedMessage);
// delete topics
ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_THREAD_DELETE, getClass(), LoggingResourceable.wrap(reloadedMessage));
// back to thread list
fireEvent(ureq, new DeleteThreadEvent());
ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.DELETED_THREAD, reloadedMessage.getKey(), reloadedMessage.getKey(), getIdentity());
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
} else {
Message threadTop = reloadedMessage.getThreadtop();
forumManager.deleteMessageTree(forum.getKey(), reloadedMessage);
threadTop = forumManager.updateMessage(threadTop, true);
if (thread != null) {
// update with the fresh version
thread = threadTop;
}
showInfo("deleteok");
ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_MESSAGE_DELETE, getClass(), LoggingResourceable.wrap(reloadedMessage));
// reload
reloadModelAfterDelete(ureq, message);
fireEvent(ureq, new DeleteMessageEvent());
ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.DELETED_MESSAGE, threadTop.getKey(), message.getKey(), getIdentity());
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
}
}
} else {
showWarning("may.not.delete.msg.as.author");
}
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class ThreadListController method doNewThread.
private void doNewThread(UserRequest ureq) {
removeAsListenerAndDispose(newThreadCtrl);
removeAsListenerAndDispose(cmc);
// user has clicked on button 'open new thread'.
Message m = forumManager.createMessage(forum, getIdentity(), guestOnly);
newThreadCtrl = new MessageEditController(ureq, getWindowControl(), forum, foCallback, m, null, EditMode.newThread);
listenTo(newThreadCtrl);
String title = translate("msg.create");
cmc = new CloseableModalController(getWindowControl(), "close", newThreadCtrl.getInitialComponent(), true, title);
listenTo(newThreadCtrl);
cmc.activate();
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class ForumArtefactHandler method prefillArtefactAccordingToSource.
/**
* @see org.olat.portfolio.EPAbstractHandler#prefillArtefactAccordingToSource(org.olat.portfolio.model.artefacts.AbstractArtefact, java.lang.Object)
*/
@Override
public void prefillArtefactAccordingToSource(AbstractArtefact artefact, Object source) {
super.prefillArtefactAccordingToSource(artefact, source);
if (source instanceof OLATResourceable) {
OLATResourceable ores = (OLATResourceable) source;
ForumManager fMgr = ForumManager.getInstance();
Message fm = fMgr.loadMessage(ores.getResourceableId());
String thread = fm.getThreadtop() != null ? fm.getThreadtop().getTitle() + " - " : "";
artefact.setTitle(thread + fm.getTitle());
VFSContainer msgContainer = fMgr.getMessageContainer(fm.getForum().getKey(), fm.getKey());
if (msgContainer != null) {
List<VFSItem> foAttach = msgContainer.getItems();
if (foAttach.size() != 0) {
artefact.setFileSourceContainer(msgContainer);
}
}
artefact.setSignature(70);
artefact.setFulltextContent(fm.getBody());
}
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
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();
}
Aggregations