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");
}
}
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));
}
}
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));
}
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;
}
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> ", "<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));
}
}
Aggregations