mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 20:19:21 +00:00
Ready to display older messages
This commit is contained in:
parent
7b71aeed08
commit
370512a6b6
@ -887,7 +887,34 @@ ComunicWeb.components.conversations.chatWindows = {
|
||||
scrollDetectionLocked = true;
|
||||
|
||||
//Fetch older messages
|
||||
console.log("Fetch old messages");
|
||||
ComunicWeb.components.conversations.interface.getOlderMessages(
|
||||
conversationID,
|
||||
ComunicWeb.components.conversations.service.getOldestMessageID(conversationID),
|
||||
10,
|
||||
function(result){
|
||||
|
||||
//Unlock scroll detection
|
||||
scrollDetectionLocked = false;
|
||||
|
||||
//Check for errors
|
||||
if(result.error){
|
||||
notify("An error occured while trying to fetch older messages for the conversation !");
|
||||
return;
|
||||
}
|
||||
|
||||
//Check for results
|
||||
if(result.length == 0){
|
||||
//Lock scroll detection in order to avoid useless traffic
|
||||
scrollDetectionLocked = true;
|
||||
return;
|
||||
}
|
||||
|
||||
//Save the ID of the oldest message
|
||||
ComunicWeb.components.conversations.service.setOldestMessageID(result[0].ID);
|
||||
|
||||
//Process the messages in reverse order
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -322,6 +322,27 @@ ComunicWeb.components.conversations.interface = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get older message of a conversation
|
||||
*
|
||||
* @param {number} conversationID The ID of the conversation
|
||||
* @param {number} oldestMessageID The ID of the oldest message known
|
||||
* @param {number} limit The limit
|
||||
* @param {function} callback
|
||||
*/
|
||||
getOlderMessages: function(conversationID, oldestMessageID, limit, callback){
|
||||
|
||||
//Perform a request on the API
|
||||
var apiURI = "conversations/get_older_messages";
|
||||
var params = {
|
||||
conversationID: conversationID,
|
||||
oldest_message_id: oldestMessageID,
|
||||
limit: limit
|
||||
};
|
||||
|
||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Empty conversations cache
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user