From 98906334a7845de8142d423c36a104c5046dd587 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 7 Mar 2021 14:08:01 +0100 Subject: [PATCH] Can update conversation color --- .../components/conversations/chatWindows.js | 29 +++++++++++-------- .../js/components/conversations/interface.js | 17 +++-------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index c6694096..0e635770 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -606,15 +606,11 @@ const ConvChatWindow = { showConversationSettings: function(conversation){ //First, check conversation settings button and pane don't exists yet - if(conversation.box.settingsButton){ - if(conversation.box.settingsButton.remove){ - conversation.box.settingsButton.remove(); - } + if(conversation.box.settingsButton && conversation.box.settingsButton.remove){ + conversation.box.settingsButton.remove(); } - if(conversation.box.settingsPane){ - if(conversation.box.settingsPane.remove){ - conversation.box.settingsPane.remove(); - } + if(conversation.box.settingsPane && conversation.box.settingsPane.remove){ + conversation.box.settingsPane.remove(); } //Create and display conversation settings button wheel @@ -658,6 +654,12 @@ const ConvChatWindow = { //Update conversation name if(conversation.infos.name) settingsForm.conversationNameInput.value = conversation.infos.name; + + // Apply conversation color + if (conversation.infos.color) { + settingsForm.conversationColorInput.value = "#" + conversation.infos.color; + settingsForm.conversationColorInput.dispatchEvent(new CustomEvent("change")) + } //Update conversation members ComunicWeb.components.userSelect.pushEntries(settingsForm.usersElement, conversation.infos.members.map(m => m.user_id)); @@ -669,8 +671,8 @@ const ConvChatWindow = { //Check if user is a conversation moderator or not if(!conversation.infos.members.find(m => m.user_id == userID()).is_admin) { - //We disable name field - settingsForm.conversationNameInput.disabled = "true"; + settingsForm.conversationNameInput.disabled = true; + settingsForm.conversationColorInput.parentNode.parentNode.style.display = "none"; settingsForm.allowEveryoneToAddMembers.parentNode.parentNode.remove(); } @@ -731,10 +733,13 @@ const ConvChatWindow = { } //Add other fields if the user is a conversation moderator - if(conversation.infos.ID_owner == userID()){ + if(conversation.infos.members.find(m => m.user_id == userID()).is_admin){ //Specify conversation name - var nameValue = conversation.settingsForm.conversationNameInput.value + let nameValue = conversation.settingsForm.conversationNameInput.value newValues.name = (nameValue === "" ? false : nameValue); + + let colorValue = conversation.settingsForm.conversationColorInput.value + newValues.color = (colorValue == "" ? null : colorValue) newValues.canEveryoneAddMembers = conversation.settingsForm.allowEveryoneToAddMembers.checked; diff --git a/assets/js/components/conversations/interface.js b/assets/js/components/conversations/interface.js index d288b2fc..7b080288 100644 --- a/assets/js/components/conversations/interface.js +++ b/assets/js/components/conversations/interface.js @@ -110,9 +110,8 @@ const ConversationsInterface = { * @info {Integer} conversationID The ID of the conversation to update * @info {Boolean} following Specify if the user is following the conversation or not * @info {String} name Specify a new name for the conversation - * @info {array} members Specify the new list of members for the conversation + * @info {String} color Specify a new color for the conversation * @param {function} callback The function callback - * @return {Boolean} True for a success */ updateSettings: function(infos, callback){ //Prepare the API request @@ -125,10 +124,6 @@ const ConversationsInterface = { if(infos.name !== undefined) params.name = infos.name; - //Add conversation members (if specified) - if(infos.members) - params.members = infos.members; - //Add conversation following status (if specified) if(infos.following !== undefined) params.following = infos.following; @@ -136,22 +131,18 @@ const ConversationsInterface = { if(infos.canEveryoneAddMembers !== undefined) params.canEveryoneAddMembers = infos.canEveryoneAddMembers; + if(infos.color !== undefined) + params.color = infos.color == null ? "" : infos.color.replace("#", "").toUpperCase(); + //Perform API request ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, function(result){ //Empty the cache (considered as deprecated) ComunicWeb.components.conversations.interface.emptyCache(true); - //Check for error - if(result.error) - ComunicWeb.debug.logMessage("Error! An error occured while trying to update conversation settings !"); - //Perform next action callback(result); }); - - //Success - return true; }, /**