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