From 1509ca3533adba79c0e71511efda20b3b0ec1530 Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 27 Apr 2018 19:05:06 +0200 Subject: [PATCH] Can go up in a conversation --- .../components/conversations/chatWindows.js | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index 1492cae1..904fec26 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -700,7 +700,7 @@ ComunicWeb.components.conversations.chatWindows = { */ addMessage: function(conversationID, messageInfo){ - //First, check if the conversation informations can be found + //First, check if the conversation information can be found if(!this.__conversationsCache["conversation-"+conversationID]){ ComunicWeb.debug.logMessage("Conversation Chat Windows : Error ! Couldn't add a message to the conversation because the conversation was not found !"); return false; @@ -742,6 +742,43 @@ ComunicWeb.components.conversations.chatWindows = { return true; }, + /** + * Add old messages to a conversation window + * + * @param {number} conversationID The ID of the target conversation + * @param {array} messages The list of messages to add + */ + addOldMessages: function(conversationID, messages){ + + //First, check if the conversation information can be found + if(!this.__conversationsCache["conversation-"+conversationID]){ + ComunicWeb.debug.logMessage("Conversation Chat Windows : Error ! Couldn't add a message to the conversation because the conversation was not found !"); + return false; + } + + //Else extract conversation informations + var conv = this.__conversationsCache["conversation-"+conversationID]; + + //Process the list of messages in reverse order + messages.reverse(); + messages.forEach(function(message){ + + //Get message element + var uiMessageInfo = ComunicWeb.components.conversations.chatWindows._get_message_element(conv, message); + + //Add the messages at the begining of the conversation + conv.box.messagesArea.insertBefore(uiMessageInfo.rootElem, conv.messages[0].rootElem); + + //Add the message to the list + conv.messages.unshift(uiMessageInfo); + + //Check if some information about the post can be updated + ComunicWeb.components.conversations.chatWindows._makeMessageFollowAnotherMessage(conv, 1); + + }); + + }, + /** * Generate message HTML node based on given information * @@ -946,9 +983,10 @@ ComunicWeb.components.conversations.chatWindows = { } //Save the ID of the oldest message - ComunicWeb.components.conversations.service.setOldestMessageID(result[0].ID); + ComunicWeb.components.conversations.service.setOldestMessageID(conversationID, result[0].ID); - //Process the messages in reverse order + //Display the list of messages + ComunicWeb.components.conversations.chatWindows.addOldMessages(conversationID, result); } ); });