2017-06-14 09:46:10 +00:00
|
|
|
/**
|
|
|
|
* Opened conversations caching system
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
ComunicWeb.components.conversations.cachingOpened = {
|
|
|
|
|
|
|
|
__varName: "opened-conversations-ids",
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new conversation ID in the list
|
|
|
|
*
|
|
|
|
* @param {Integer} conversationID The ID of the conversation to add
|
|
|
|
* @return {Boolean} True for a success
|
|
|
|
*/
|
2017-06-14 12:13:52 +00:00
|
|
|
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;
|
|
|
|
},
|
2017-06-14 09:46:10 +00:00
|
|
|
|
2017-06-14 14:01:16 +00:00
|
|
|
/**
|
|
|
|
* Remove a conversation from the list
|
|
|
|
*
|
|
|
|
* @param {Integer} conversationID The ID of the conversation to remove
|
|
|
|
* @return {Boolean} True for a success
|
|
|
|
*/
|
|
|
|
remove: function(conversationID){
|
|
|
|
|
|
|
|
var conversations = this.getAll();
|
|
|
|
|
|
|
|
if(!conversations.includes(conversationID.toString())){
|
|
|
|
return false; //The conversation was not found
|
|
|
|
}
|
|
|
|
|
|
|
|
//Remove the entry
|
|
|
|
var entryNumber = conversations.indexOf(conversationID.toString());
|
|
|
|
conversations.splice(entryNumber, 1);
|
|
|
|
|
|
|
|
//Save the new values
|
|
|
|
var conversationsString = conversations.join(";");
|
|
|
|
sessionStorage.setItem(this.__varName, conversationsString);
|
|
|
|
},
|
|
|
|
|
2017-06-14 09:46:10 +00:00
|
|
|
/**
|
|
|
|
* Get all conversations ID in the list
|
|
|
|
*
|
2017-06-14 12:13:52 +00:00
|
|
|
* @return {array} An array with all opened conversations ID
|
2017-06-14 09:46:10 +00:00
|
|
|
*/
|
2017-06-14 12:13:52 +00:00
|
|
|
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(";");
|
|
|
|
},
|
2017-06-14 09:46:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Empty the storage
|
|
|
|
*
|
|
|
|
* @return {Boolean} True for a success
|
|
|
|
*/
|
|
|
|
emptyStorage: function(){
|
|
|
|
|
|
|
|
//Remove variables for session storage
|
|
|
|
sessionStorage.removeItem(this.__varName);
|
|
|
|
|
|
|
|
//Success
|
|
|
|
return true;
|
2017-06-14 12:13:52 +00:00
|
|
|
},
|
2017-06-14 09:46:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Register cache cleaner
|
|
|
|
ComunicWeb.common.cacheManager.registerCacheCleaner("ComunicWeb.components.conversations.cachingOpened.emptyStorage", true);
|