From c09f06fccc516a2e7fa60a86973b5e14db5f9f68 Mon Sep 17 00:00:00 2001 From: Al McKinlay Date: Wed, 20 Dec 2017 09:45:12 +0000 Subject: [PATCH] Change isOpInChannel to allow multiple different user roles --- client/js/lounge.js | 2 +- client/js/utils.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/client/js/lounge.js b/client/js/lounge.js index 4264c767..439ba567 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -101,7 +101,7 @@ $(function() { const channel = target.closest(".chan"); - if (utils.isOpInChannel(channel) && channel.data("type") === "channel") { + if (utils.hasRoleInChannel(channel, ["op"]) && channel.data("type") === "channel") { output += templates.contextmenu_divider(); output += templates.contextmenu_item({ class: "action-kick", diff --git a/client/js/utils.js b/client/js/utils.js index 47e0568a..666e239c 100644 --- a/client/js/utils.js +++ b/client/js/utils.js @@ -14,13 +14,13 @@ module.exports = { lastMessageId, confirmExit, forceFocus, + hasRoleInChannel, move, resetHeight, setNick, toggleNickEditor, toggleNotificationMarkers, requestIdleCallback, - isOpInChannel, }; function findCurrentNetworkChan(name) { @@ -39,13 +39,17 @@ function resetHeight(element) { element.style.height = element.style.minHeight; } -// Given a channel element will determine if the lounge user is Op in that channel -function isOpInChannel(channel) { +// Given a channel element will determine if the lounge user is one of the supplied roles. +function hasRoleInChannel(channel, roles) { + if (!channel || !roles) { + return false; + } + const channelID = channel.data("id"); const network = $("#sidebar .network").has(`.chan[data-id="${channelID}"]`); const ownNick = network.data("nick"); - const isOP = channel.find(`.users .user-mode.op .user[data-name="${escape(ownNick)}"]`).length; - return isOP; + const user = channel.find(`.users .user[data-name="${escape(ownNick)}"]`).first(); + return user.parent().is("." + roles.join(", .")); } // Triggering click event opens the virtual keyboard on mobile