From f91e597c570056a93eacf5c803bb05f6c24e24f1 Mon Sep 17 00:00:00 2001 From: Alexander PapaTutuWawa Date: Sun, 25 Apr 2021 16:43:47 +0200 Subject: [PATCH] mix_pam: Make the roster annotations work --- mod_mix_pam/mod_mix_pam.lua | 38 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/mod_mix_pam/mod_mix_pam.lua b/mod_mix_pam/mod_mix_pam.lua index a10d0e8..5d3f425 100644 --- a/mod_mix_pam/mod_mix_pam.lua +++ b/mod_mix_pam/mod_mix_pam.lua @@ -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 - 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)