thelounge/client/js/utils.js

22 lines
638 B
JavaScript
Raw Normal View History

2017-05-18 22:08:54 +02:00
"use strict";
const $ = require("jquery");
const escape = require("css.escape");
2017-05-18 22:08:54 +02:00
module.exports = {
hasRoleInChannel,
2017-05-18 22:08:54 +02:00
};
// 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;
}
2018-07-19 12:46:30 +02:00
const channelID = channel.attr("data-id");
const network = $("#sidebar .network").has(`.chan[data-id="${channelID}"]`);
const target = nick || network.attr("data-nick");
2019-01-22 15:33:20 +01:00
const user = channel.find(`.names .user[data-name="${escape(target)}"]`).first();
return user.parent().is("." + roles.join(", ."));
}