From 343416ed0c8cc772d17b5060a9dfa1243cfc1543 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 18 Jun 2017 09:15:50 +0200 Subject: [PATCH] Moved openConversation --- .../components/conversations/chatWindows.js | 71 +++++++++++++++++- assets/js/components/conversations/manager.js | 72 +------------------ 2 files changed, 72 insertions(+), 71 deletions(-) diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index 27485e23..8bc4b67c 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -5,6 +5,75 @@ */ ComunicWeb.components.conversations.chatWindows = { + + /** + * Open a new conversation window + * + * @param {Integer} windowID The ID of the window to open + * @return {Boolean} True for a success + */ + openConversation: function(conversationID){ + + //Log action + ComunicWeb.debug.logMessage("Opening conversation " + conversationID); + + //Save conversation ID in session storage + ComunicWeb.components.conversations.cachingOpened.add(conversationID); + + //Create a conversation window + var conversationWindow = this.create({ + target: byId(ComunicWeb.components.conversations.manager.__conversationsContenerID), + conversationID: conversationID + }); + + //Change conversation window name (loading state) + this.changeName("Loading", conversationWindow); + + //Peform a request to informations about the conversation + ComunicWeb.components.conversations.interface.getInfosOne(conversationID, function(informations){ + + //In case of error + if(informations.error){ + //Display error notification + ComunicWeb.common.notificationSystem.showNotification("Couldn't get informations about the conversation !", "danger"); + return false; + } + + //Get informations about the members of the conversation + getMultipleUsersInfos(informations.members, function(membersInfos){ + + //Quit in case of error + if(informations.error){ + //Display error notification + ComunicWeb.common.notificationSystem.showNotification("Couldn't get informations about the conversation members !", "danger"); + return false; + } + + //Create conversation informations root object + var conversationInfos = { + box: conversationWindow, + membersInfos: membersInfos, + infos: informations + }; + + //Change the name of the conversation + ComunicWeb.components.conversations.utils.getName(informations, function(conversationName){ + ComunicWeb.components.conversations.chatWindows.changeName(conversationName, conversationWindow); + }); + + //Update conversation members informations + ComunicWeb.components.conversations.chatWindows.updateMembersList(conversationInfos); + + //Display conversation settings pane + ComunicWeb.components.conversations.chatWindows.showConversationSettings(conversationInfos); + + }); + }); + + //Success + return true; + }, + /** * Create a new chat window * @@ -17,7 +86,7 @@ ComunicWeb.components.conversations.chatWindows = { //Log action ComunicWeb.debug.logMessage("Create a new chat window"); - + //First, create the generic conversation window var infosBox = ComunicWeb.components.conversations.windows.create(infos.target.children[0]); diff --git a/assets/js/components/conversations/manager.js b/assets/js/components/conversations/manager.js index a6f78a57..42170dcd 100644 --- a/assets/js/components/conversations/manager.js +++ b/assets/js/components/conversations/manager.js @@ -70,7 +70,7 @@ ComunicWeb.components.conversations.manager = { //Process opened conversations for(i in openedConversations){ if(i < openedConversations.length) - this.openConversation(openedConversations[i]); + ComunicWeb.components.conversations.chatWindows.openConversation(openedConversations[i]); } }, @@ -121,77 +121,9 @@ ComunicWeb.components.conversations.manager = { } //Open the conversation - this.openConversation(conversationID); + ComunicWeb.components.conversations.chatWindows.openConversation(conversationID); //Success return true; }, - - /** - * Open a conversation - * - * @param {Integer} conversationID The ID of the conversation to open - * @return {Boolean} True or false depending of the success of the operation - */ - openConversation: function(conversationID){ - - //Log action - ComunicWeb.debug.logMessage("Opening conversation " + conversationID); - - //Save conversation ID in session storage - ComunicWeb.components.conversations.cachingOpened.add(conversationID); - - //Create a conversation window - var conversationWindow = ComunicWeb.components.conversations.chatWindows.create({ - target: byId(this.__conversationsContenerID), - conversationID: conversationID - }); - - //Change conversation window name (loading state) - ComunicWeb.components.conversations.chatWindows.changeName("Loading", conversationWindow); - - //Peform a request to informations about the conversation - ComunicWeb.components.conversations.interface.getInfosOne(conversationID, function(informations){ - - //In case of error - if(informations.error){ - //Display error notification - ComunicWeb.common.notificationSystem.showNotification("Couldn't get informations about the conversation !", "danger"); - return false; - } - - //Get informations about the members of the conversation - ComunicWeb.user.userInfos.getMultipleUsersInfos(informations.members, function(membersInfos){ - - //Quit in case of error - if(informations.error){ - //Display error notification - ComunicWeb.common.notificationSystem.showNotification("Couldn't get informations about the conversation members !", "danger"); - return false; - } - - //Create conversation informations root object - var conversationInfos = { - box: conversationWindow, - membersInfos: membersInfos, - infos: informations - }; - - //Change the name of the conversation - ComunicWeb.components.conversations.utils.getName(informations, function(conversationName){ - ComunicWeb.components.conversations.chatWindows.changeName(conversationName, conversationWindow); - }); - - //Update conversation members informations - ComunicWeb.components.conversations.chatWindows.updateMembersList(conversationInfos); - - //Display conversation settings pane - ComunicWeb.components.conversations.chatWindows.showConversationSettings(conversationInfos); - - }); - }); - - //Success - return true; - } } \ No newline at end of file