Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 10687:8c2c5b4fde32
MUC: Support for broadcasting unavailable presence for affiliated offline users
Activated when muc#roomconfig_presencebroadcast includes the "none" role.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 12 Mar 2020 16:01:31 +0000 |
parent | 10686:ac3ec4f2b124 |
child | 10688:83668e16b9a3 |
comparison
equal
deleted
inserted
replaced
10686:ac3ec4f2b124 | 10687:8c2c5b4fde32 |
---|---|
331 if not (occupant and can_see_real_jids(whois, occupant)) then | 331 if not (occupant and can_see_real_jids(whois, occupant)) then |
332 is_anonymous = true; | 332 is_anonymous = true; |
333 end | 333 end |
334 end | 334 end |
335 end | 335 end |
336 local broadcast_bare_jids = {}; -- Track which bare JIDs we have sent presence for | |
336 for occupant_jid, occupant in self:each_occupant() do | 337 for occupant_jid, occupant in self:each_occupant() do |
338 broadcast_bare_jids[occupant.bare_jid] = true; | |
337 if filter == nil or filter(occupant_jid, occupant) then | 339 if filter == nil or filter(occupant_jid, occupant) then |
338 local x = st.stanza("x", {xmlns='http://jabber.org/protocol/muc#user'}); | 340 local x = st.stanza("x", {xmlns='http://jabber.org/protocol/muc#user'}); |
339 self:build_item_list(occupant, x, is_anonymous and to_bare ~= occupant.bare_jid); -- can always see your own jids | 341 self:build_item_list(occupant, x, is_anonymous and to_bare ~= occupant.bare_jid); -- can always see your own jids |
340 local pres = st.clone(occupant:get_presence()); | 342 local pres = st.clone(occupant:get_presence()); |
341 pres.attr.to = to; | 343 pres.attr.to = to; |
342 pres:add_child(x); | 344 pres:add_child(x); |
343 if to_bare == occupant.bare_jid or broadcast_roles[occupant.role or "none"] then | 345 if to_bare == occupant.bare_jid or broadcast_roles[occupant.role or "none"] then |
346 self:route_stanza(pres); | |
347 end | |
348 end | |
349 end | |
350 if broadcast_roles.none then | |
351 -- Broadcast stanzas for affiliated users not currently in the MUC | |
352 for affiliated_jid, affiliation, affiliation_data in self:each_affiliation() do | |
353 local nick = affiliation_data and affiliation_data.reserved_nickname; | |
354 if (nick or not is_anonymous) and not broadcast_bare_jids[affiliated_jid] | |
355 and (filter == nil or filter(affiliated_jid, nil)) then | |
356 local from = nick and (self.jid.."/"..nick) or self.jid; | |
357 local pres = st.presence({ to = to, from = from, type = "unavailable" }) | |
358 :tag("x", { xmlns = 'http://jabber.org/protocol/muc#user' }) | |
359 :tag("item", { | |
360 affiliation = affiliation; | |
361 role = "none"; | |
362 nick = nick; | |
363 jid = not is_anonymous and affiliated_jid or nil }):up() | |
364 :up(); | |
344 self:route_stanza(pres); | 365 self:route_stanza(pres); |
345 end | 366 end |
346 end | 367 end |
347 end | 368 end |
348 end | 369 end |
668 | 689 |
669 if orig_occupant == nil or muc_x then | 690 if orig_occupant == nil or muc_x then |
670 -- Send occupant list to newly joined or desynced user | 691 -- Send occupant list to newly joined or desynced user |
671 self:send_occupant_list(real_jid, function(nick, occupant) -- luacheck: ignore 212 | 692 self:send_occupant_list(real_jid, function(nick, occupant) -- luacheck: ignore 212 |
672 -- Don't include self | 693 -- Don't include self |
673 return occupant:get_presence(real_jid) == nil; | 694 return (not occupant) or occupant:get_presence(real_jid) == nil; |
674 end) | 695 end) |
675 end | 696 end |
676 local dest_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); | 697 local dest_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
677 local self_x = st.clone(dest_x); | 698 local self_x = st.clone(dest_x); |
678 if orig_occupant == nil and self:get_whois() == "anyone" then | 699 if orig_occupant == nil and self:get_whois() == "anyone" then |
1376 (old_role == "moderator" and occupant.role ~= "moderator") or | 1397 (old_role == "moderator" and occupant.role ~= "moderator") or |
1377 (old_role ~= "moderator" and occupant.role == "moderator") then -- Has gained or lost moderator status | 1398 (old_role ~= "moderator" and occupant.role == "moderator") then -- Has gained or lost moderator status |
1378 -- Send everyone else's presences (as jid visibility has changed) | 1399 -- Send everyone else's presences (as jid visibility has changed) |
1379 for real_jid in occupant:each_session() do | 1400 for real_jid in occupant:each_session() do |
1380 self:send_occupant_list(real_jid, function(occupant_jid, occupant) --luacheck: ignore 212 433 | 1401 self:send_occupant_list(real_jid, function(occupant_jid, occupant) --luacheck: ignore 212 433 |
1381 return occupant.bare_jid ~= jid; | 1402 return (not occupant) or occupant.bare_jid ~= jid; |
1382 end); | 1403 end); |
1383 end | 1404 end |
1384 end | 1405 end |
1385 end | 1406 end |
1386 else | 1407 else |