Mercurial > prosody-hg
comparison plugins/muc/hats.lib.lua @ 11200:bf8f2da84007
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 05 Nov 2020 22:31:25 +0100 |
| parents | 9ecad2304297 |
| children | 43b43e7156b8 |
comparison
equal
deleted
inserted
replaced
| 11199:6c7c50a4de32 | 11200:bf8f2da84007 |
|---|---|
| 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); |
