Search in sources :

Example 6 with MessageLight

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);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MessageLight(org.olat.modules.fo.MessageLight)

Example 7 with MessageLight

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MessageLight(org.olat.modules.fo.MessageLight)

Example 8 with MessageLight

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

Example 9 with MessageLight

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);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MessageLight(org.olat.modules.fo.MessageLight)

Example 10 with MessageLight

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

Aggregations

MessageLight (org.olat.modules.fo.MessageLight)10 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 File (java.io.File)2 List (java.util.List)2 Mark (org.olat.core.commons.services.mark.Mark)2 MarkResourceStat (org.olat.core.commons.services.mark.MarkResourceStat)2 Message (org.olat.modules.fo.Message)2 Media (org.olat.modules.portfolio.Media)2 MediaInformations (org.olat.modules.portfolio.MediaInformations)2