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