use of org.olat.modules.fo.MessageLight in project OpenOLAT by OpenOLAT.
the class MessageListController method orderMessagesThreaded.
/**
* Orders the messages in the logical instead of chronological order.
* @param messages
* @param orderedList
* @param startMessage
*/
private void orderMessagesThreaded(List<MessageLight> messages, List<MessageLight> orderedList, MessageLight startMessage) {
if (messages == null || orderedList == null || startMessage == null)
return;
Map<Long, MessageNode> messagesMap = new HashMap<>();
if (startMessage != null) {
messagesMap.put(startMessage.getKey(), new MessageNode(startMessage));
}
for (MessageLight message : messages) {
if (message.getParentKey() != null) {
messagesMap.put(message.getKey(), new MessageNode(message));
}
}
List<MessageNode> roots = new ArrayList<>();
for (MessageLight message : messages) {
Long parentKey = message.getParentKey();
if (parentKey != null && messagesMap.containsKey(parentKey)) {
MessageNode parentMessage = messagesMap.get(parentKey);
MessageNode messageNode = messagesMap.get(message.getKey());
parentMessage.getChildren().add(messageNode);
} else {
MessageNode rootMessage = messagesMap.get(message.getKey());
roots.add(rootMessage);
}
}
for (MessageNode root : roots) {
orderMessagesThreaded(root, orderedList);
}
}
use of org.olat.modules.fo.MessageLight in project OpenOLAT by OpenOLAT.
the class ForumMessageListController method loadAllMessages.
public void loadAllMessages() {
List<MessageLight> allMessages = forumManager.getLightMessagesByForum(forum);
List<MessageLightView> views = new ArrayList<>(allMessages.size());
Map<Long, MessageLightView> keyToViews = new HashMap<>();
for (MessageLight message : allMessages) {
MessageLightView view = new MessageLightView(message, userPropertyHandlers, getLocale());
views.add(view);
keyToViews.put(view.getKey(), view);
}
// calculate depth
Map<Long, List<Long>> keyToParentline = new HashMap<>();
for (MessageLightView view : views) {
if (view.getParentKey() == null) {
view.setDepth(0);
} else {
List<Long> parentLine = new ArrayList<>(5);
view.setDepth(1);
for (MessageLightView parent = keyToViews.get(view.getParentKey()); parent != null; parent = keyToViews.get(parent.getParentKey())) {
view.setDepth(view.getDepth() + 1);
parentLine.add(parent.getKey());
}
keyToParentline.put(view.getKey(), parentLine);
}
}
// order
List<MessageNode> threads = convertToThreadTrees(views);
Collections.sort(threads, new MessageNodeComparator());
List<MessageLightView> orderedViews = new ArrayList<>(allMessages.size());
flatTree(threads, orderedViews);
dataModel.setObjects(orderedViews);
}
use of org.olat.modules.fo.MessageLight in project OpenOLAT by OpenOLAT.
the class ForumMediaHandler method getInformations.
@Override
public MediaInformations getInformations(Object mediaObject) {
String title = null;
if (mediaObject instanceof MessageLight) {
MessageLight messageLight = (MessageLight) mediaObject;
title = messageLight.getTitle();
}
return new Informations(title, null);
}
use of org.olat.modules.fo.MessageLight in project openolat by klemens.
the class MessageListController method orderMessagesThreaded.
/**
* Orders the messages in the logical instead of chronological order.
* @param messages
* @param orderedList
* @param startMessage
*/
private void orderMessagesThreaded(List<MessageLight> messages, List<MessageLight> orderedList, MessageLight startMessage) {
if (messages == null || orderedList == null || startMessage == null)
return;
Map<Long, MessageNode> messagesMap = new HashMap<>();
if (startMessage != null) {
messagesMap.put(startMessage.getKey(), new MessageNode(startMessage));
}
for (MessageLight message : messages) {
if (message.getParentKey() != null) {
messagesMap.put(message.getKey(), new MessageNode(message));
}
}
List<MessageNode> roots = new ArrayList<>();
for (MessageLight message : messages) {
Long parentKey = message.getParentKey();
if (parentKey != null && messagesMap.containsKey(parentKey)) {
MessageNode parentMessage = messagesMap.get(parentKey);
MessageNode messageNode = messagesMap.get(message.getKey());
parentMessage.getChildren().add(messageNode);
} else {
MessageNode rootMessage = messagesMap.get(message.getKey());
roots.add(rootMessage);
}
}
for (MessageNode root : roots) {
orderMessagesThreaded(root, orderedList);
}
}
use of org.olat.modules.fo.MessageLight in project openolat by klemens.
the class ForumMediaHandler method getInformations.
@Override
public MediaInformations getInformations(Object mediaObject) {
String title = null;
if (mediaObject instanceof MessageLight) {
MessageLight messageLight = (MessageLight) mediaObject;
title = messageLight.getTitle();
}
return new Informations(title, null);
}
Aggregations