mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 01:48:50 +00:00
Can get and set oldest message ID known of a conversation
This commit is contained in:
parent
6170a4eb03
commit
09fbdb2933
@ -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
|
||||
|
@ -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)
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user