Files
jitsi-meet/resources/prosody-plugins/mod_muc_displayname.lua
ltorje-8x8 0e69336f94 JIT-14750 Do not show names to visitors (#16231)
* JIT-14750 Do not show names to visitors

* apply review

* change name and email too

* fix: Fix filtering initial presence to vnodes.

* Also strip stats-id and identity.user.name.

* Move filtering logic to a util, filter all identity in main room

---------

Co-authored-by: Boris Grozev <boris@jitsi.org>
2025-07-14 16:00:25 -05:00

76 lines
2.9 KiB
Lua

--- This module removes identity information from presence stanzas when the
--- hideDisplayNameForAll or hideDisplayNameForGuests options are enabled
--- for a room.
--- To be enabled under the main muc component
local filters = require 'util.filters';
local st = require 'util.stanza';
local util = module:require 'util';
local filter_identity_from_presence = util.filter_identity_from_presence;
local get_room_by_name_and_subdomain = util.get_room_by_name_and_subdomain;
local is_admin = util.is_admin;
local ends_with = util.ends_with;
local internal_room_jid_match_rewrite = util.internal_room_jid_match_rewrite;
-- we need to get the shared resource for joining moderators, as participants are marked as moderators
-- after joining which is after the filter for stanza/out, but we need to know will this participant be a moderator
local joining_moderator_participants = module:shared('moderators/joining_moderator_participants');
--- Filter presence sent to non-moderator members of a room when the hideDisplayNameForGuests option is set.
function filter_stanza_out(stanza, session)
if stanza.name ~= 'presence' or stanza.attr.type == 'error'
or stanza.attr.type == 'unavailable' or ends_with(stanza.attr.from, '/focus') then
return stanza;
end
local room = get_room_by_name_and_subdomain(session.jitsi_web_query_room, session.jitsi_web_query_prefix);
if not room or room._data.hideDisplayNameForGuests ~= true then
return stanza;
end
local occupant = room:get_occupant_by_real_jid(stanza.attr.to);
if occupant then
if stanza.attr.from == internal_room_jid_match_rewrite(occupant.nick) then
-- we ignore self-presences, in this case and role will not be correct
return stanza;
end
if occupant.role ~= 'moderator' and not joining_moderator_participants[occupant.bare_jid] then
return filter_identity_from_presence(stanza);
end
end
return stanza;
end
--- Filter presence received from anyone in a room when the hideDisplayNameForAll option is set.
function filter_stanza_in(stanza, session)
if stanza.name ~= 'presence' or stanza.attr.type == 'error' or stanza.attr.type == 'unavailable' then
return stanza;
end
local room = get_room_by_name_and_subdomain(session.jitsi_web_query_room, session.jitsi_web_query_prefix);
-- if hideDisplayNameForAll we want to drop any display name from the presence stanza
if room and room._data.hideDisplayNameForAll == true then
return filter_identity_from_presence(stanza);
end
return stanza;
end
function filter_session(session)
filters.add_filter(session, 'stanzas/out', filter_stanza_out, -100);
filters.add_filter(session, 'stanzas/in', filter_stanza_in, -100);
end
function module.load()
filters.add_filter_hook(filter_session);
end
function module.unload()
filters.remove_filter_hook(filter_session);
end