Search in sources :

Example 6 with ForumChangedEvent

use of org.olat.modules.fo.ForumChangedEvent in project openolat by klemens.

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 7 with ForumChangedEvent

use of org.olat.modules.fo.ForumChangedEvent in project openolat by klemens.

the class MessageListController method doHideThread.

/**
 * Sets the hidden status to the thread message.
 * @param ureq
 * @param msg
 * @param hidden
 */
private void doHideThread() {
    if (thread != null) {
        thread = forumManager.getMessageById(thread.getKey());
        Status status = Status.getStatus(thread.getStatusCode());
        status.setHidden(true);
        thread.setStatusCode(Status.getStatusCode(status));
        thread = forumManager.updateMessage(thread, false);
        // before sending async event
        DBFactory.getInstance().commit();
        hideThreadButton.setVisible(false);
        showThreadButton.setVisible(true && !guestOnly);
        mainVC.setDirty(true);
        ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.HIDE, thread.getKey(), null, getIdentity());
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forumOres);
        ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_THREAD_HIDE, getClass(), LoggingResourceable.wrap(thread));
    }
}
Also used : Status(org.olat.modules.fo.Status) ForumChangedEvent(org.olat.modules.fo.ForumChangedEvent)

Example 8 with ForumChangedEvent

use of org.olat.modules.fo.ForumChangedEvent in project openolat by klemens.

the class MessageListController method doToogleSticky.

private void doToogleSticky() {
    Status status = Status.getStatus(thread.getStatusCode());
    status.setSticky(!status.isSticky());
    thread.setStatusCode(Status.getStatusCode(status));
    thread = forumManager.updateMessage(thread, false);
    DBFactory.getInstance().commit();
    stickyButton.setVisible(!status.isSticky() && foCallback.mayEditMessageAsModerator());
    removeStickyButton.setVisible(status.isSticky() && foCallback.mayEditMessageAsModerator());
    mainVC.setDirty(true);
    ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.STICKY, thread.getKey(), null, getIdentity());
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forumOres);
    ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_MESSAGE_EDIT, getClass(), LoggingResourceable.wrap(thread));
}
Also used : Status(org.olat.modules.fo.Status) ForumChangedEvent(org.olat.modules.fo.ForumChangedEvent)

Example 9 with ForumChangedEvent

use of org.olat.modules.fo.ForumChangedEvent in project openolat by klemens.

the class ForumManager method splitThread.

/**
 * Splits the current thread starting from the current message.
 * It updates the messages of the selected subthread by setting the Parent and the Threadtop.
 * The method send a SPLIT event, and make a commit before sending it.
 *
 * @param msgid
 * @return the top message of the newly created thread.
 */
public Message splitThread(Message msg) {
    Message newTopMessage = null;
    if (msg.getThreadtop() == null) {
        newTopMessage = msg;
    } else {
        // it only make sense to split a thread if the current message is not a threadtop message.
        List<Message> threadList = getThread(msg.getThreadtop().getKey());
        List<Message> subthreadList = new ArrayList<>();
        getSubthread(msg, threadList, subthreadList);
        newTopMessage = getMessageById(msg.getKey());
        newTopMessage.setParent(null);
        newTopMessage.setThreadtop(null);
        newTopMessage = dbInstance.getCurrentEntityManager().merge(newTopMessage);
        for (Message message : subthreadList) {
            message.setThreadtop(newTopMessage);
            message = dbInstance.getCurrentEntityManager().merge(message);
        }
        // before sending async event
        dbInstance.commit();
        ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.SPLIT, newTopMessage.getKey(), null, null);
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, newTopMessage.getForum());
    }
    return newTopMessage;
}
Also used : ForumChangedEvent(org.olat.modules.fo.ForumChangedEvent) Message(org.olat.modules.fo.Message) ArrayList(java.util.ArrayList)

Example 10 with ForumChangedEvent

use of org.olat.modules.fo.ForumChangedEvent in project OpenOLAT by OpenOLAT.

the class MessageEditController method commitMessage.

private void commitMessage(UserRequest ureq) {
    // if msg exist -> persist uploads directly to final dest
    if (message.getKey() != null) {
        message = fm.loadMessage(message.getKey());
    }
    // set values from form to message
    message.setTitle(titleEl.getValue());
    String body = bodyEl.getValue();
    body = body.replace("<p>&nbsp;", "<p>");
    message.setBody(body.trim());
    if (usePseudonymEl != null && (usePseudonymEl.isAtLeastSelected(1) || guestOnly)) {
        String password = passwordEl.getValue();
        String pseudonym = pseudonymEl.getValue();
        if (StringHelper.containsNonWhitespace(password)) {
            List<Pseudonym> protectedPseudonyms = fm.getPseudonyms(pseudonym);
            if (protectedPseudonyms.isEmpty()) {
                fm.createProtectedPseudonym(pseudonym, password);
                ureq.getUserSession().putEntry("FOPseudo-" + pseudonym, password);
            } else {
                // we double check the password
                boolean authenticated = false;
                for (Pseudonym protectedPseudonym : protectedPseudonyms) {
                    if (fm.authenticatePseudonym(protectedPseudonym, password)) {
                        ureq.getUserSession().putEntry("FOPseudo-" + protectedPseudonym.getPseudonym(), password);
                        authenticated = true;
                        break;
                    }
                }
                if (!authenticated) {
                    validateFormLogic(ureq);
                    return;
                }
            }
        }
        message.setPseudonym(pseudonym);
        if (guestOnly) {
            ureq.getUserSession().putEntry("FOPseudo" + forum.getKey(), message.getPseudonym());
        }
    } else if (message.getCreator() != null && message.getCreator().equals(getIdentity())) {
        message.setPseudonym(null);
    }
    if (editMode == EditMode.newThread) {
        if (foCallback.mayOpenNewThread()) {
            // save a new thread
            fm.addTopMessage(message);
            fm.markNewMessageAsRead(getIdentity(), forum, message);
            persistTempUploadedFiles(message);
            // if notification is enabled -> notify the publisher about news
            notifiySubscription();
            addLoggingResourceable(LoggingResourceable.wrap(message));
            // commit before sending events
            DBFactory.getInstance().commit();
            ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.NEW_MESSAGE, message.getKey(), message.getKey(), getIdentity());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
            ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_MESSAGE_CREATE, getClass());
        } else {
            showWarning("may.not.save.msg.as.author");
        }
    } else if (editMode == EditMode.edit) {
        boolean children = fm.countMessageChildren(message.getKey()) > 0;
        if (foCallback.mayEditMessageAsModerator() || (userIsMsgCreator && !children)) {
            message.setModifier(getIdentity());
            message = fm.updateMessage(message, true);
            persistTempUploadedFiles(message);
            notifiySubscription();
            // commit before sending events
            DBFactory.getInstance().commit();
            Long threadTopKey = message.getThreadtop() == null ? null : message.getThreadtop().getKey();
            ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.CHANGED_MESSAGE, threadTopKey, message.getKey(), getIdentity());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
            ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_MESSAGE_EDIT, getClass(), LoggingResourceable.wrap(message));
        } else {
            showWarning("may.not.save.msg.as.author");
        }
    } else if (editMode == EditMode.reply) {
        fm.replyToMessage(message, parentMessage);
        fm.markNewMessageAsRead(getIdentity(), forum, message);
        persistTempUploadedFiles(message);
        notifiySubscription();
        Long threadTopKey = message.getThreadtop() == null ? null : message.getThreadtop().getKey();
        // commit before sending events
        DBFactory.getInstance().commit();
        ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.NEW_MESSAGE, threadTopKey, message.getKey(), getIdentity());
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
        ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_REPLY_MESSAGE_CREATE, getClass(), LoggingResourceable.wrap(message));
    }
}
Also used : ForumChangedEvent(org.olat.modules.fo.ForumChangedEvent) Pseudonym(org.olat.modules.fo.Pseudonym)

Aggregations

ForumChangedEvent (org.olat.modules.fo.ForumChangedEvent)18 Status (org.olat.modules.fo.Status)10 Message (org.olat.modules.fo.Message)4 ArrayList (java.util.ArrayList)2 Pseudonym (org.olat.modules.fo.Pseudonym)2 DeleteMessageEvent (org.olat.modules.fo.ui.events.DeleteMessageEvent)2 DeleteThreadEvent (org.olat.modules.fo.ui.events.DeleteThreadEvent)2 ErrorEditMessage (org.olat.modules.fo.ui.events.ErrorEditMessage)2