Implemented conversations numbers caching

This commit is contained in:
Pierre 2017-06-14 14:13:52 +02:00
parent 773a003bea
commit 9923b67d2e

View File

@ -14,12 +14,41 @@ ComunicWeb.components.conversations.cachingOpened = {
* @param {Integer} conversationID The ID of the conversation to add
* @return {Boolean} True for a success
*/
add: function(conversationID){
//Get currently openened conversations
var conversations = this.getAll();
//Add new conversation (if required)
if(!conversations.includes(conversationID.toString())){
conversations.push(conversationID);
//Convert into string
var conversationsString = conversations.join(";");
//Save the new values
sessionStorage.setItem(this.__varName, conversationsString);
}
//Success
return true;
},
/**
* Get all conversations ID in the list
*
* @return {Array} An array with all opened conversations ID
* @return {array} An array with all opened conversations ID
*/
getAll: function(){
//Query session storage
var results = sessionStorage.getItem(this.__varName);
if(results === null)
return []; //Return an empty array
//Else parse results
return results.split(";");
},
/**
* Empty the storage
@ -33,7 +62,7 @@ ComunicWeb.components.conversations.cachingOpened = {
//Success
return true;
}
},
}