From 64bb781dfec9b44618da58991aab292b1e360be1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 12 Mar 2020 16:01:31 +0000 Subject: MUC: Support for broadcasting unavailable presence for affiliated offline users Activated when muc#roomconfig_presencebroadcast includes the "none" role. --- plugins/muc/muc.lib.lua | 25 +- plugins/muc/presence_broadcast.lib.lua | 2 +- spec/scansion/muc_show_offline.scs | 544 +++++++++++++++++++++++++++++++++ 3 files changed, 568 insertions(+), 3 deletions(-) create mode 100644 spec/scansion/muc_show_offline.scs diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 42f41831..5f45498a 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -333,7 +333,9 @@ function room_mt:send_occupant_list(to, filter) end end end + local broadcast_bare_jids = {}; -- Track which bare JIDs we have sent presence for for occupant_jid, occupant in self:each_occupant() do + broadcast_bare_jids[occupant.bare_jid] = true; if filter == nil or filter(occupant_jid, occupant) then local x = st.stanza("x", {xmlns='http://jabber.org/protocol/muc#user'}); self:build_item_list(occupant, x, is_anonymous and to_bare ~= occupant.bare_jid); -- can always see your own jids @@ -345,6 +347,25 @@ function room_mt:send_occupant_list(to, filter) end end end + if broadcast_roles.none then + -- Broadcast stanzas for affiliated users not currently in the MUC + for affiliated_jid, affiliation, affiliation_data in self:each_affiliation() do + local nick = affiliation_data and affiliation_data.reserved_nickname; + if (nick or not is_anonymous) and not broadcast_bare_jids[affiliated_jid] + and (filter == nil or filter(affiliated_jid, nil)) then + local from = nick and (self.jid.."/"..nick) or self.jid; + local pres = st.presence({ to = to, from = from, type = "unavailable" }) + :tag("x", { xmlns = 'http://jabber.org/protocol/muc#user' }) + :tag("item", { + affiliation = affiliation; + role = "none"; + nick = nick; + jid = not is_anonymous and affiliated_jid or nil }):up() + :up(); + self:route_stanza(pres); + end + end + end end function room_mt:get_disco_info(stanza) @@ -670,7 +691,7 @@ function room_mt:handle_normal_presence(origin, stanza) -- Send occupant list to newly joined or desynced user self:send_occupant_list(real_jid, function(nick, occupant) -- luacheck: ignore 212 -- Don't include self - return occupant:get_presence(real_jid) == nil; + return (not occupant) or occupant:get_presence(real_jid) == nil; end) end local dest_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); @@ -1378,7 +1399,7 @@ function room_mt:set_affiliation(actor, jid, affiliation, reason, data) -- Send everyone else's presences (as jid visibility has changed) for real_jid in occupant:each_session() do self:send_occupant_list(real_jid, function(occupant_jid, occupant) --luacheck: ignore 212 433 - return occupant.bare_jid ~= jid; + return (not occupant) or occupant.bare_jid ~= jid; end); end end diff --git a/plugins/muc/presence_broadcast.lib.lua b/plugins/muc/presence_broadcast.lib.lua index 72e0d76b..82a89fee 100644 --- a/plugins/muc/presence_broadcast.lib.lua +++ b/plugins/muc/presence_broadcast.lib.lua @@ -9,7 +9,7 @@ local st = require "util.stanza"; -local valid_roles = { "visitor", "participant", "moderator" }; +local valid_roles = { "none", "visitor", "participant", "moderator" }; local default_broadcast = { visitor = true; participant = true; diff --git a/spec/scansion/muc_show_offline.scs b/spec/scansion/muc_show_offline.scs new file mode 100644 index 00000000..755a4774 --- /dev/null +++ b/spec/scansion/muc_show_offline.scs @@ -0,0 +1,544 @@ +# MUC: Room registration and presence broadcast of unavailable members + +[Client] Romeo + jid: user@localhost + password: password + +[Client] Juliet + jid: user2@localhost + password: password + +[Client] Rosaline + jid: user3@localhost + password: password + +----- + +Romeo connects + +Romeo sends: + + + + +Romeo receives: + + + + + + + + +Romeo receives: + + +# Submit config form +Romeo sends: + + + + + http://jabber.org/protocol/muc#roomconfig + + + none + participant + moderator + + + + + +Romeo receives: + + + +Romeo sends: + + + + + + +Romeo receives: + + + + + + +Romeo receives: + + +# Juliet connects, and joins the room +Juliet connects + +Juliet sends: + + + + +Juliet receives: + + +Juliet receives: + + +Juliet receives: + + +Romeo receives: + + +# Juliet retrieves the registration form + +Juliet sends: + + + + +Juliet receives: + + + + + http://jabber.org/protocol/muc#register + + + + + + + + +Juliet sends: + + + + + http://jabber.org/protocol/muc#register + + + Juliet + + + + + +Juliet receives: + + + + + + + +Juliet receives: + + +# Juliet discovers her reserved nick + +Juliet sends: + + + + +Juliet receives: + + + + + + +# Juliet leaves the room: + +Juliet sends: + + +Juliet receives: + + + + + + + +Romeo receives: + + + + + + +# Rosaline connect and tries to join the room as Juliet + +Rosaline connects + +Rosaline sends: + + + + +Rosaline receives: + + + + + + + +# In a heated moment, Juliet unregisters from the room + +Juliet sends: + + + + + + +Juliet receives: + + +# Romeo is notified of Juliet's sad decision + +Romeo receives: + + + + + + +# Rosaline attempts once more to sneak into the room, disguised as Juliet + +Rosaline sends: + + + + +Rosaline receives: + + + + + + +Rosaline receives: + + + + + + + +Romeo receives: + + + + + + +# On discovering the ruse, Romeo restores Juliet's nick and status within the room + +Romeo sends: + + + + + + +# Rosaline is evicted from the room + +Romeo receives: + + + + + This nickname is reserved + + + + +# An out-of-room affiliation change is received for Juliet + +Romeo receives: + + + + + + +Romeo receives: + + +Rosaline receives: + + + + + This nickname is reserved + + + + + +# Rosaline, frustrated, attempts to get back into the room... + +Rosaline sends: + + + + +# ...but once again, is denied + +Rosaline receives: + + + + + + + +# Juliet, however, quietly joins the room with success + +Juliet sends: + + + + +Juliet receives: + + +Juliet receives: + + +Juliet receives: + + +Romeo receives: + + +# Romeo checks whether he has reserved his own nick yet + +Romeo sends: + + + + +# But no nick is returned, as he hasn't registered yet! + +Romeo receives: + + + + +# Romeo updates his own registration + +Romeo sends: + + + + +Romeo receives: + + + + + http://jabber.org/protocol/muc#register + + + + + + + + +Romeo sends: + + + + + http://jabber.org/protocol/muc#register + + + Romeo + + + + + +Romeo receives: + + + + + + + +Romeo receives: + + +Juliet receives: + + + + + + +# Romeo discovers his reserved nick + +Romeo sends: + + + + +Romeo receives: + + + + + + +# To check the status of the room is as expected, Romeo requests the member list + +Romeo sends: + + + + + + +Romeo receives: + + + + + + +Juliet sends: + + +Juliet receives: + + +Romeo receives: + + +# Rosaline joins as herself + +Rosaline sends: + + + + +Rosaline receives: + + +Rosaline receives: + + + + + + +Rosaline receives: + + +Rosaline receives: + + +Romeo receives: + + + + + + +# Rosaline tries to register her own nickname, but unaffiliated +# registration is disabled by default + +Rosaline sends: + + + + +Rosaline receives: + + + + + + +Rosaline sends: + + + + + http://jabber.org/protocol/muc#register + + + Romeo + + + + + +Rosaline receives: + + + + + + +# Romeo reserves her nickname for her + +Romeo sends: + + + + + + +Romeo receives: + + + + + + + + +Romeo receives: + + +Rosaline receives: + + + + + + + + + +# Romeo sets their their own nickname via admin query (see #1273) +Romeo sends: + + + + + + +Romeo receives: + + + + + + + + + +Romeo receives: + + -- cgit v1.2.3