Merge pull request #1864 from thelounge/yamanickill/isop

Change isOpInChannel to allow multiple different user roles
This commit is contained in:
Pavel Djundik 2018-02-21 19:32:11 +02:00 committed by GitHub
commit e957a52e43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -101,7 +101,7 @@ $(function() {
const channel = target.closest(".chan"); 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_divider();
output += templates.contextmenu_item({ output += templates.contextmenu_item({
class: "action-kick", class: "action-kick",

View file

@ -14,13 +14,13 @@ module.exports = {
lastMessageId, lastMessageId,
confirmExit, confirmExit,
forceFocus, forceFocus,
hasRoleInChannel,
move, move,
resetHeight, resetHeight,
setNick, setNick,
toggleNickEditor, toggleNickEditor,
toggleNotificationMarkers, toggleNotificationMarkers,
requestIdleCallback, requestIdleCallback,
isOpInChannel,
}; };
function findCurrentNetworkChan(name) { function findCurrentNetworkChan(name) {
@ -39,13 +39,17 @@ function resetHeight(element) {
element.style.height = element.style.minHeight; element.style.height = element.style.minHeight;
} }
// Given a channel element will determine if the lounge user is Op in that channel // Given a channel element will determine if the lounge user is one of the supplied roles.
function isOpInChannel(channel) { function hasRoleInChannel(channel, roles) {
if (!channel || !roles) {
return false;
}
const channelID = channel.data("id"); const channelID = channel.data("id");
const network = $("#sidebar .network").has(`.chan[data-id="${channelID}"]`); const network = $("#sidebar .network").has(`.chan[data-id="${channelID}"]`);
const ownNick = network.data("nick"); const ownNick = network.data("nick");
const isOP = channel.find(`.users .user-mode.op .user[data-name="${escape(ownNick)}"]`).length; const user = channel.find(`.users .user[data-name="${escape(ownNick)}"]`).first();
return isOP; return user.parent().is("." + roles.join(", ."));
} }
// Triggering click event opens the virtual keyboard on mobile // Triggering click event opens the virtual keyboard on mobile