Ready to display older messages

This commit is contained in:
Pierre 2018-04-26 17:55:38 +02:00
parent 7b71aeed08
commit 370512a6b6
2 changed files with 49 additions and 1 deletions

View File

@ -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
}
);
});
}
}

View File

@ -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
*