Comparison

mod_muc_moderation/mod_muc_moderation.lua @ 5619:2e30af180da5

mod_muc_moderation: Stamp XEP-0421 occupant-id for the acting moderator Gives clients some hint about which moderator it was who did the deed. The @by attribute does have the nick of the actor, but they could change their nickname at some point, which is what occupant-id solves. Ref #1816
author Kim Alvefur <zash@zash.se>
date Thu, 20 Jul 2023 10:38:33 +0200
parent 5618:06fad22672e1
comparison
equal deleted inserted replaced
5618:06fad22672e1 5619:2e30af180da5
99 local moderated_occupant_id = original:get_child("occupant-id", xmlns_occupant_id); 99 local moderated_occupant_id = original:get_child("occupant-id", xmlns_occupant_id);
100 if room.get_occupant_id and moderated_occupant_id then 100 if room.get_occupant_id and moderated_occupant_id then
101 announcement:add_direct_child(moderated_occupant_id); 101 announcement:add_direct_child(moderated_occupant_id);
102 end 102 end
103 103
104 local actor_occupant = room:get_occupant_by_real_jid(actor) or room:new_occupant(jid.bare(actor), actor_nick);
105 if room.get_occupant_id then
106 -- This isn't a regular broadcast message going through the events occupant_id.lib hooks so we do this here
107 announcement:add_direct_child(st.stanza("occupant-id", { xmlns = xmlns_occupant_id; id = room:get_occupant_id(actor_occupant) }))
108 end
109
104 if muc_log_archive.set and retract then 110 if muc_log_archive.set and retract then
105 local tombstone = st.message({ from = original.attr.from, type = "groupchat", id = original.attr.id }) 111 local tombstone = st.message({ from = original.attr.from, type = "groupchat", id = original.attr.id })
106 :tag("moderated", { xmlns = xmlns_moderate, by = actor_nick }) 112 :tag("moderated", { xmlns = xmlns_moderate, by = actor_nick })
107 :tag("retracted", { xmlns = xmlns_retract, stamp = dt.datetime() }):up(); 113 :tag("retracted", { xmlns = xmlns_retract, stamp = dt.datetime() }):up();
108 114
109 if room.get_occupant_id and moderated_occupant_id then 115 if room.get_occupant_id then
110 -- Copy occupant id from moderated message 116 tombstone:add_direct_child(st.stanza("occupant-id", { xmlns = xmlns_occupant_id; id = room:get_occupant_id(actor_occupant) }))
111 tombstone:add_child(moderated_occupant_id); 117
118 if moderated_occupant_id then
119 -- Copy occupant id from moderated message
120 tombstone:add_child(moderated_occupant_id);
121 end
112 end 122 end
113 123
114 if reason then 124 if reason then
115 tombstone:text_tag("reason", reason); 125 tombstone:text_tag("reason", reason);
116 end 126 end