From a6fa3d7ac66582249f542711d8f5d60636882847 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 6 Mar 2021 18:05:53 +0100 Subject: [PATCH] Remove user from conversation --- .../components/conversations/chatWindows.js | 32 +++++++++++++++++-- .../js/components/conversations/interface.js | 14 ++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index ae43dcc7..16f7e815 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -432,7 +432,7 @@ const ConvChatWindow = { const conv = info.infos; let isAdmin = conv.members.find(m => m.user_id).is_admin; let canAddUser = conv.group_id == null && (conv.can_everyone_add_members || isAdmin); - let canMakeUsersAdmin = isAdmin && canAddUser; + let canRemoveUsers = isAdmin && canAddUser; // =================== Add a member =================== if (canAddUser) { @@ -528,12 +528,38 @@ const ConvChatWindow = { }); //Add member status - createElem2({ + let status = createElem2({ type: "span", appendTo: memberInfosList, class: "contacts-list-msg", - innerHTML: member.is_admin ? tr("Admin") : tr("Member") + innerHTML: (member.is_admin ? tr("Admin") : tr("Member")) + " " }); + + + // Remove user + if(canRemoveUsers && member.user_id != userID()) { + let removeLink = createElem2({ + type: "a", + appendTo: status, + innerHTML: "Remove" + }) + + removeLink.addEventListener("click", async e => { + e.preventDefault(); + + if(!await showConfirmDialog(tr("Do you really want to remove %1% from the conversation ?", {"1": user.fullName}))) + return; + + try { + await ConversationsInterface.removeUser(conv.id, member.user_id); + + ConvChatWindow.reload(info); + } catch(e) { + console.error(e); + notify(tr("Failed to remove %1% from the conversation!", {"1": user.fullName}), "danger"); + } + }) + } } diff --git a/assets/js/components/conversations/interface.js b/assets/js/components/conversations/interface.js index c5965b8b..358b3eee 100644 --- a/assets/js/components/conversations/interface.js +++ b/assets/js/components/conversations/interface.js @@ -463,6 +463,20 @@ const ConversationsInterface = { }, true); }, + /** + * Remove a user from a conversation + * + * @param {number} convID Conversation ID + * @param {number} userID Target user + */ + removeUser: async function(convID, userID) { + await api("conversations/removeMember", { + convID: convID, + userID: userID + }, true); + }, + + /** * Empty conversations cache *