mod_mix_pam: Cleanup of the roster portion
This commit is contained in:
parent
15c1179f4d
commit
c7b9dc2432
@ -283,6 +283,24 @@ module:hook("resource-unbind", function(event)
|
||||
module:log("debug", "Unbind of not recorded resource %s (%s)", resource, session_jid);
|
||||
end);
|
||||
|
||||
local function child_with_attrs(stanza, childtag, xmlns, attrs)
|
||||
-- Helper function: Like stanza:childtags, but returns only the first
|
||||
-- child whose attributes are in attrs (and match the values in attrs).
|
||||
-- Otherwise, nil is returned.
|
||||
for _, child in ipairs(stanza:childtags(childtag, xmlns)) do
|
||||
for attr_name, attr_value in pairs(attrs) do
|
||||
if child.attrs[attr_name] ~= nil and child.attrs[attr_name] == attr_value then
|
||||
return child;
|
||||
else
|
||||
-- We already now that this is not the child we're looking for
|
||||
break;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return nil;
|
||||
end
|
||||
|
||||
module:hook("roster-get", function(event)
|
||||
-- NOTE: Currently this requires a patch to make mod_roster emit
|
||||
-- the roster-get event
|
||||
@ -295,18 +313,14 @@ module:hook("roster-get", function(event)
|
||||
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
|
||||
for contact, item in pairs(rm_load_roster(jid.bare(stanza.attr.from))) do
|
||||
if item["mix_spid"] ~= nil then
|
||||
local roster_item = child_with_attrs(query, "item", nil, { jid = contact });
|
||||
if roster_item then
|
||||
roster_item:tag("channel", { xmlns = mix_roster_xmlns, ["participant-id"] = item["mix_spid"] });
|
||||
else
|
||||
module:log("warn", "Could not find %s during annotated roster query!");
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user