mix_pam: Make the roster annotations work

This commit is contained in:
PapaTutuWawa 2021-04-25 16:43:47 +02:00
parent 562d0d7368
commit f91e597c57

View File

@ -287,30 +287,32 @@ end);
module:hook("roster-get", function(event) module:hook("roster-get", function(event)
-- NOTE: Currently this requires a patch to make mod_roster emit -- NOTE: Currently this requires a patch to make mod_roster emit
-- the roster-get event -- the roster-get event
local annotate = event.stanza local reply, stanza = event.reply, event.stanza;
:get_child("query", "jabber:iq:roster") local client_query = stanza:get_child("query", "jabber:iq:roster");
:get_child("annotate", mix_roster_xmlns); if not client_query then return; end
local annotate = client_query:get_child("annotate", mix_roster_xmlns);
if not annotate then return; end if not annotate then return; end
local stanza = event.stanza;
module:log("debug", "Annotated roster request received"); module:log("debug", "Annotated roster request received");
-- User requested the roster with an <annotate/> -- User requested the roster with an <annotate/>
local roster = rm_load_roster(jid.bare(stanza.attr.from)); local roster = rm_load_roster(jid.node(stanza.attr.from), jid.host(stanza.attr.from));
local query = event.reply:get_child("query", "jabber:iq:roster"); local query = reply:get_child("query", "jabber:iq:roster");
for contact, roster_item in pairs(roster) do query:maptags(function (item)
if roster_item["mix_spid"] ~= nil then -- Bail early, just in case
for _, item in ipairs(query:childtags("item")) do if item.name ~= "item" then return item; end
if item.attr.jid == contact then
item:tag("channel", { local spid = roster[item.attr.jid]["mix_spid"];
xmlns = mix_roster_xmlns, if spid ~= nil then
["participant-id"] = roster_item["mix_spid"], item:tag("channel", {
}); xmlns = mix_roster_xmlns,
break; ["participant-id"] = spid,
end });
end
end end
end
return item;
end);
end); end);
module:hook("message/bare", function(event) module:hook("message/bare", function(event)