Can toggle admin status of a user

This commit is contained in:
Pierre HUBERT 2021-03-06 18:15:21 +01:00
parent a6fa3d7ac6
commit eb76a1491a
2 changed files with 39 additions and 0 deletions

View File

@ -536,6 +536,30 @@ const ConvChatWindow = {
});
// Set / unset admin
if(canRemoveUsers && member.user_id != userID()) {
let removeLink = createElem2({
type: "a",
appendTo: status,
innerHTML: (member.is_admin ? tr("Unset admin") : tr("Set admin"))
})
removeLink.addEventListener("click", async e => {
e.preventDefault();
try {
await ConversationsInterface.toggleAdminStatus(conv.id, member.user_id, !member.is_admin);
ConvChatWindow.reload(info);
} catch(e) {
console.error(e);
notify(tr("Failed to toggle admin status of %1%!", {"1": user.fullName}), "danger");
}
})
}
add_space(status)
// Remove user
if(canRemoveUsers && member.user_id != userID()) {
let removeLink = createElem2({

View File

@ -463,6 +463,21 @@ const ConversationsInterface = {
}, true);
},
/**
* Toggle admin status of a user
*
* @param {number} convID Conversation ID
* @param {number} userID User ID
* @param {boolean} setAdmin
*/
toggleAdminStatus: async function(convID, userID, setAdmin) {
await api("conversations/setAdmin", {
convID: convID,
userID: userID,
setAdmin: setAdmin
}, true);
},
/**
* Remove a user from a conversation
*