mirror of
https://github.com/thelounge/thelounge
synced 2024-11-22 20:13:07 +00:00
21 lines
638 B
JavaScript
21 lines
638 B
JavaScript
"use strict";
|
|
|
|
const $ = require("jquery");
|
|
const escape = require("css.escape");
|
|
|
|
module.exports = {
|
|
hasRoleInChannel,
|
|
};
|
|
|
|
// Given a channel element will determine if the lounge user or a given nick is one of the supplied roles.
|
|
function hasRoleInChannel(channel, roles, nick) {
|
|
if (!channel || !roles) {
|
|
return false;
|
|
}
|
|
|
|
const channelID = channel.attr("data-id");
|
|
const network = $("#sidebar .network").has(`.chan[data-id="${channelID}"]`);
|
|
const target = nick || network.attr("data-nick");
|
|
const user = channel.find(`.names .user[data-name="${escape(target)}"]`).first();
|
|
return user.parent().is("." + roles.join(", ."));
|
|
}
|