From 09fbdb2933f64a08aeca4df2204261b04ee38011 Mon Sep 17 00:00:00 2001 From: Pierre Date: Thu, 26 Apr 2018 06:50:23 +0200 Subject: [PATCH] Can get and set oldest message ID known of a conversation --- .../components/conversations/chatWindows.js | 47 ++++++++++++++++++- assets/js/components/conversations/service.js | 35 ++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index 77bb793b..30489053 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -831,7 +831,7 @@ ComunicWeb.components.conversations.chatWindows = { element: textMessage, }); - //Enable slimscrool + //Enable slimscroll $(convInfos.box.messagesArea).slimscroll({ height: "250px", }); @@ -842,9 +842,54 @@ ComunicWeb.components.conversations.chatWindows = { scrollTo: scrollBottom }); + //Initialize top scroll detection if required + this.initTopScrollDetection(conversationID); + //Success return true; }, + + /** + * Init top scroll detection (if required) + * + * @param {number} conversationID The ID of the target conversation + */ + initTopScrollDetection: function(conversationID){ + + //Extract conversation informations + var convInfo = this.__conversationsCache["conversation-"+conversationID]; + + //Check if nothing has to be done + if(convInfo.box.initializedScrollDetection) + return; + + //Mark scroll detection as initialized + convInfo.box.initializedScrollDetection = true; + + var scrollDetectionLocked = false; + var scrollTopCount = 0; + $(convInfo.box.messagesArea).slimScroll().bind("slimscrolling", function(e, pos){ + + if(scrollDetectionLocked) + return; + + if(pos != 0){ + scrollTopCount = 0; + } + + scrollTopCount++; + + //Check top count + if(scrollTopCount < 3) + return; + + //Lock the detection + scrollDetectionLocked = true; + + //Fetch older messages + console.log("Fetch old messages"); + }); + } } //Register conversations cache cleaning function diff --git a/assets/js/components/conversations/service.js b/assets/js/components/conversations/service.js index 327355b8..eb6a3f7f 100644 --- a/assets/js/components/conversations/service.js +++ b/assets/js/components/conversations/service.js @@ -226,6 +226,41 @@ ComunicWeb.components.conversations.service = { return true; }, + /** + * Get the oldest messages of a conversation + * + * @param {number} conversationID The ID of the target conversation + * @return {numbert} The ID of the oldest message / -1 in case of failure + */ + getOldestMessageID: function(conversationID){ + + //Try to fetch information + if(this.__serviceCache){ + if(this.__serviceCache['conversation-'+conversationID]){ + return this.__serviceCache['conversation-'+conversationID].first_message_id; + } + } + + //The conversation was not found + return -1; + }, + + /** + * Set the oldest messages of a conversation + * + * @param {number} conversationID The ID of the target conversation + * @param {numbert} firstMessageID New value for the first known message id + */ + setOldestMessageID: function(conversationID, firstMessageID){ + + //Try to fetch information + if(this.__serviceCache){ + if(this.__serviceCache['conversation-'+conversationID]){ + this.__serviceCache['conversation-'+conversationID].first_message_id = firstMessageID; + } + } + }, + /** * Empty service cache (unregister all conversations) *