feat: Adds user hidden feature and handle breakout rooms.

This commit is contained in:
Дамян Минков 2022-02-11 14:16:25 -06:00
parent ea36be5e81
commit ba79af66fa
1 changed files with 42 additions and 13 deletions

View File

@ -1,36 +1,65 @@
--This module adds is_hidden tag when jwt contains `hidden`
--flag set to true, or removes it in case it was
--added maliciously from client sent presence.
--The module must be enabled under the muc component.
local is_user_hidden = module:require "util".is_user_hidden;
local tag_name = "is_hidden"
--The module must be enabled under the main virtual host.
local util = module:require 'util';
local is_user_hidden = util.is_user_hidden;
local process_host_module = util.process_host_module;
module:log("info", "Loading mod_muc_user_hidden!");
local TAG_NAME = 'is_hidden'
local USER_HIDDEN_FEATURE = 'http://jitsi.org/protocol/user_hidden';
-- main_muc
local main_muc_component_config = module:get_option_string('main_muc');
if main_muc_component_config == nil then
module:log('error', 'hidden_user not enabled missing main_muc config');
return ;
end
-- breakout_rooms_muc
local breakout_rooms_muc_component_config = module:get_option_string('breakout_rooms_muc');
function add_hidden_tag(event)
local stanza = event.stanza;
local session = event.origin;
if stanza == nil or stanza.name ~= "presence" then
if stanza == nil or stanza.name ~= 'presence' then
return
end
stanza:maptags(function(tag)
if tag and tag.name == tag_name then
module:log("info", "Removing %s tag from presence stanza!", tag_name);
if tag and tag.name == TAG_NAME then
module:log('info', 'Removing %s tag from presence stanza!', TAG_NAME);
return nil;
else
return tag;
end
end)
local session = event.origin;
if is_user_hidden(session) then
stanza:tag(tag_name):up()
stanza:tag(TAG_NAME):up()
end
end
module:hook("presence/bare", add_hidden_tag);
module:hook("presence/full", add_hidden_tag);
module:hook("presence/host", add_hidden_tag);
function process_muc_component(host)
module:log("info", "Hook to presence on %s", host);
module:log("info", "Loaded mod_muc_user_hidden!");
local muc_module = module:context(host);
muc_module:hook('presence/bare', add_hidden_tag);
muc_module:hook('presence/full', add_hidden_tag);
muc_module:hook('presence/host', add_hidden_tag);
-- announce it to the client
muc_module:hook('muc-disco#info', function(event)
event.reply:tag('feature', { var = USER_HIDDEN_FEATURE }):up();
end);
end
process_host_module(main_muc_component_config, process_muc_component);
if breakout_rooms_muc_component_config then
process_host_module(breakout_rooms_muc_component_config, process_muc_component);
end
module:log('info', 'Loaded mod_muc_user_hidden!');