comparison plugins/muc/hats.lib.lua @ 11120:b2331f3dfeea

Merge 0.11->trunk
author Matthew Wild <mwild1@gmail.com>
date Wed, 30 Sep 2020 09:50:33 +0100
parents 9ecad2304297
children 43b43e7156b8
comparison
equal deleted inserted replaced
11119:68df52bf08d5 11120:b2331f3dfeea
1 local st = require "util.stanza";
2 local muc_util = module:require "muc/util";
3
4 local xmlns_hats = "xmpp:prosody.im/protocol/hats:1";
5
6 -- Strip any hats claimed by the client (to prevent spoofing)
7 muc_util.add_filtered_namespace(xmlns_hats);
8
9 module:hook("muc-build-occupant-presence", function (event)
10 local aff_data = event.room:get_affiliation_data(event.occupant.bare_jid);
11 local hats = aff_data and aff_data.hats;
12 if not hats then return; end
13 local hats_el;
14 for hat_id, hat_data in pairs(hats) do
15 if hat_data.active then
16 if not hats_el then
17 hats_el = st.stanza("hats", { xmlns = xmlns_hats });
18 end
19 hats_el:tag("hat", { uri = hat_id, title = hat_data.title }):up();
20 end
21 end
22 if not hats_el then return; end
23 event.stanza:add_direct_child(hats_el);
24 end);