Search in sources :

Example 11 with Message

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");
    }
}
Also used : User(org.olat.core.id.User) ErrorEditMessage(org.olat.modules.fo.ui.events.ErrorEditMessage) Message(org.olat.modules.fo.Message) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)

Example 12 with Message

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");
    }
}
Also used : ForumChangedEvent(org.olat.modules.fo.ForumChangedEvent) DeleteThreadEvent(org.olat.modules.fo.ui.events.DeleteThreadEvent) ErrorEditMessage(org.olat.modules.fo.ui.events.ErrorEditMessage) Message(org.olat.modules.fo.Message) DeleteMessageEvent(org.olat.modules.fo.ui.events.DeleteMessageEvent)

Example 13 with Message

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();
}
Also used : Message(org.olat.modules.fo.Message) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)

Example 14 with Message

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());
    }
}
Also used : Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable) ForumManager(org.olat.modules.fo.manager.ForumManager) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 15 with Message

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();
}
Also used : Message(org.olat.modules.fo.Message) FileVO(org.olat.restapi.support.vo.FileVO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Message (org.olat.modules.fo.Message)108 Identity (org.olat.core.id.Identity)18 OLATResourceable (org.olat.core.id.OLATResourceable)16 ErrorEditMessage (org.olat.modules.fo.ui.events.ErrorEditMessage)16 Forum (org.olat.modules.fo.Forum)14 ForumManager (org.olat.modules.fo.manager.ForumManager)12 Date (java.util.Date)8 HttpResponse (org.apache.http.HttpResponse)8 Test (org.junit.Test)8 VFSContainer (org.olat.core.util.vfs.VFSContainer)8 ICourse (org.olat.course.ICourse)8 FOCourseNode (org.olat.course.nodes.FOCourseNode)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 File (java.io.File)6 ArrayList (java.util.ArrayList)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 PublisherData (org.olat.core.commons.services.notifications.PublisherData)5