Added cache system

This commit is contained in:
Pierre
2017-06-14 11:46:10 +02:00
parent aa74943b01
commit f750165c3e
13 changed files with 295 additions and 26 deletions

View File

@ -0,0 +1,41 @@
/**
* 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
*/
/**
* Get all conversations ID in the list
*
* @return {Array} An array with all opened conversations ID
*/
/**
* Empty the storage
*
* @return {Boolean} True for a success
*/
emptyStorage: function(){
//Remove variables for session storage
sessionStorage.removeItem(this.__varName);
//Success
return true;
}
}
//Register cache cleaner
ComunicWeb.common.cacheManager.registerCacheCleaner("ComunicWeb.components.conversations.cachingOpened.emptyStorage", true);

View File

@ -182,7 +182,9 @@ ComunicWeb.components.conversations.list = {
infos.listBox.rootElem.remove();
//Open the conversation (under construction)
console.log("Open conversation ID: " + response.conversationID);
ComunicWeb.components.conversations.manager.openConversation({
conversationID: response.conversationID
});
})
},
@ -255,8 +257,10 @@ ComunicWeb.components.conversations.list = {
//Remove conversations list
listBox.rootElem.remove();
//Show conversation
console.log("Open conversation ID: " + conversationInfos.ID);
//Open conversation
ComunicWeb.components.conversations.manager.openConversation({
conversationID: conversationInfos.ID
});
}
//Add conversations last activity

View File

@ -79,4 +79,34 @@ ComunicWeb.components.conversations.manager = {
ComunicWeb.components.conversations.list.display(this);
}
},
/**
* Open a conversation accordingly to specified informations
*
* @param {Object} infos Informations about the conversation to open
* @info {Integer} conversationID The ID of the conversation to open
* @return {Boolean} True or false depending of the success of the operation
*/
openConversation: function(infos){
//We check if a conversation ID was specified or not
if(infos.conversationID){
ComunicWeb.debug.logMessage("Open a conversation based on its ID");
var conversationID = infos.conversationID;
}
else {
//It is an error
ComunicWeb.debug.logMessage("Don't know which conversation to open !");
return false;
}
//Log action
ComunicWeb.debug.logMessage("Opening conversation " + conversationID);
//Save conversation ID in session storage
//Success
return true;
}
}

View File

@ -62,8 +62,9 @@ ComunicWeb.components.friends.bar = {
this.refresh(listFriendsElem);
//Remove previously existing interval
if(this.refreshInterval)
if(this.refreshInterval){
clearInterval(this.refreshInterval);
}
//Make the friend bar automaticaly refreshed
this.refreshInterval = setInterval(function(){

View File

@ -89,4 +89,21 @@ ComunicWeb.components.friends.list = {
//Success
return true;
},
};
/**
* Empty friends cache list
*
* @return {Boolean} True for a success
*/
emptyCache: function(){
//Empty cache
this.__list = {};
//Success
return true;
}
};
//Register cache cleaner
ComunicWeb.common.cacheManager.registerCacheCleaner("ComunicWeb.components.friends.list.emptyCache");