Remove user from conversation

This commit is contained in:
Pierre HUBERT 2021-03-06 18:05:53 +01:00
parent cbfad9ad87
commit a6fa3d7ac6
2 changed files with 43 additions and 3 deletions

View File

@ -432,7 +432,7 @@ const ConvChatWindow = {
const conv = info.infos; const conv = info.infos;
let isAdmin = conv.members.find(m => m.user_id).is_admin; let isAdmin = conv.members.find(m => m.user_id).is_admin;
let canAddUser = conv.group_id == null && (conv.can_everyone_add_members || isAdmin); let canAddUser = conv.group_id == null && (conv.can_everyone_add_members || isAdmin);
let canMakeUsersAdmin = isAdmin && canAddUser; let canRemoveUsers = isAdmin && canAddUser;
// =================== Add a member =================== // =================== Add a member ===================
if (canAddUser) { if (canAddUser) {
@ -528,13 +528,39 @@ const ConvChatWindow = {
}); });
//Add member status //Add member status
createElem2({ let status = createElem2({
type: "span", type: "span",
appendTo: memberInfosList, appendTo: memberInfosList,
class: "contacts-list-msg", 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");
}
})
}
} }
//Enable slimscrooll //Enable slimscrooll

View File

@ -463,6 +463,20 @@ const ConversationsInterface = {
}, true); }, 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 * Empty conversations cache
* *