diff --git a/assets/js/components/conversations/cachingOpened.js b/assets/js/components/conversations/cachingOpened.js index 50685630..a34915b9 100644 --- a/assets/js/components/conversations/cachingOpened.js +++ b/assets/js/components/conversations/cachingOpened.js @@ -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; - } + }, }