Search in sources :

Example 91 with Message

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");
    }
}
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 92 with Message

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();
}
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)

Example 93 with Message

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);
        }
    }
}
Also used : Message(org.olat.modules.fo.Message)

Example 94 with Message

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);
            }
        }
    }
}
Also used : Message(org.olat.modules.fo.Message)

Example 95 with Message

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

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