diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index 16f7e815..9fdc4ba3 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -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({ diff --git a/assets/js/components/conversations/interface.js b/assets/js/components/conversations/interface.js index 358b3eee..29bc4586 100644 --- a/assets/js/components/conversations/interface.js +++ b/assets/js/components/conversations/interface.js @@ -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 *