Mercurial > prosody-modules
comparison mod_muc_moderation/mod_muc_moderation.lua @ 6128:bcad6baa4fc3
mod_muc_moderation: partial support for XEP-0425 v0.3.0 (no tombstones)
| author | nicoco <nicoco@nicoco.fr> |
|---|---|
| date | Fri, 17 Jan 2025 10:20:00 +0100 |
| parents | 4b677e445b8a |
| children | a58fb6a05412 |
comparison
equal
deleted
inserted
replaced
| 6127:d80e398a2acc | 6128:bcad6baa4fc3 |
|---|---|
| 25 end | 25 end |
| 26 | 26 |
| 27 -- Namespaces | 27 -- Namespaces |
| 28 local xmlns_fasten = "urn:xmpp:fasten:0"; | 28 local xmlns_fasten = "urn:xmpp:fasten:0"; |
| 29 local xmlns_moderate = "urn:xmpp:message-moderate:0"; | 29 local xmlns_moderate = "urn:xmpp:message-moderate:0"; |
| 30 local xmlns_moderate_1 = "urn:xmpp:message-moderate:1"; | |
| 30 local xmlns_occupant_id = "urn:xmpp:occupant-id:0"; | 31 local xmlns_occupant_id = "urn:xmpp:occupant-id:0"; |
| 31 local xmlns_retract = "urn:xmpp:message-retract:0"; | 32 local xmlns_retract = "urn:xmpp:message-retract:0"; |
| 33 local xmlns_retract_1 = "urn:xmpp:message-retract:1"; | |
| 32 | 34 |
| 33 -- Discovering support | 35 -- Discovering support |
| 34 module:hook("muc-disco#info", function (event) | 36 module:hook("muc-disco#info", function (event) |
| 35 event.reply:tag("feature", { var = xmlns_moderate }):up(); | 37 event.reply:tag("feature", { var = xmlns_moderate }):up(); |
| 38 event.reply:tag("feature", { var = xmlns_moderate_1 }):up(); | |
| 36 end); | 39 end); |
| 37 | 40 |
| 38 -- TODO error registry, requires Prosody 0.12+ | 41 -- TODO error registry, requires Prosody 0.12+ |
| 39 | 42 |
| 40 -- moderate : function (string, string, string, boolean, string) : boolean, enum, enum, string | 43 -- moderate : function (string, string, string, boolean, string) : boolean, enum, enum, string |
| 105 local moderated_occupant_id = original:get_child("occupant-id", xmlns_occupant_id); | 108 local moderated_occupant_id = original:get_child("occupant-id", xmlns_occupant_id); |
| 106 if room.get_occupant_id and moderated_occupant_id then | 109 if room.get_occupant_id and moderated_occupant_id then |
| 107 announcement:add_direct_child(moderated_occupant_id); | 110 announcement:add_direct_child(moderated_occupant_id); |
| 108 end | 111 end |
| 109 | 112 |
| 113 -- XEP 0425 v0.3.0 | |
| 114 | |
| 110 announcement:reset(); | 115 announcement:reset(); |
| 116 | |
| 117 if retract then | |
| 118 announcement:tag("retract", { xmlns = xmlns_retract_1 }) | |
| 119 :tag("moderated", { xmlns = xmlns_moderate_1 }) | |
| 120 :tag("occupant-id", { xmlns = xmlns_occupant_id; id = room:get_occupant_id(actor_occupant) }); | |
| 121 if reason then | |
| 122 announcement:up():up():text_tag("reason", reason); | |
| 123 end | |
| 124 end | |
| 125 | |
| 111 | 126 |
| 112 local tombstone = nil; | 127 local tombstone = nil; |
| 113 if muc_log_archive.set and retract then | 128 if muc_log_archive.set and retract then |
| 114 tombstone = st.message({ from = original.attr.from, type = "groupchat", id = original.attr.id }) | 129 tombstone = st.message({ from = original.attr.from, type = "groupchat", id = original.attr.id }) |
| 115 :tag("moderated", { xmlns = xmlns_moderate, by = actor_nick }) | 130 :tag("moderated", { xmlns = xmlns_moderate, by = actor_nick }) |
| 187 | 202 |
| 188 origin.send(st.reply(stanza)); | 203 origin.send(st.reply(stanza)); |
| 189 return true; | 204 return true; |
| 190 end); | 205 end); |
| 191 | 206 |
| 207 module:hook("iq-set/bare/" .. xmlns_moderate_1 .. ":moderate", function (event) | |
| 208 local stanza, origin = event.stanza, event.origin; | |
| 209 | |
| 210 local actor = stanza.attr.from; | |
| 211 local room_jid = stanza.attr.to; | |
| 212 | |
| 213 local moderate_tag = stanza:get_child("moderate", xmlns_moderate_1) | |
| 214 local retract_tag = moderate_tag:get_child("retract", xmlns_retract_1) | |
| 215 | |
| 216 if not retract_tag then return end -- other kind of moderation? | |
| 217 | |
| 218 local reason = moderate_tag:get_child_text("reason"); | |
| 219 local stanza_id = moderate_tag.attr.id | |
| 220 | |
| 221 local ok, error_type, error_condition, error_text = moderate( | |
| 222 actor, | |
| 223 room_jid, | |
| 224 stanza_id, | |
| 225 retract_tag, | |
| 226 reason | |
| 227 ); | |
| 228 if not ok then | |
| 229 origin.send(st.error_reply(stanza, error_type, error_condition, error_text)); | |
| 230 return true; | |
| 231 end | |
| 232 | |
| 233 origin.send(st.reply(stanza)); | |
| 234 return true; | |
| 235 end); | |
| 236 | |
| 192 module:hook("muc-message-is-historic", function (event) | 237 module:hook("muc-message-is-historic", function (event) |
| 193 -- Ensure moderation messages are stored | 238 -- Ensure moderation messages are stored |
| 194 if event.stanza.attr.from == event.room.jid then | 239 if event.stanza.attr.from == event.room.jid then |
| 195 return event.stanza:get_child("apply-to", xmlns_fasten); | 240 return event.stanza:get_child("apply-to", xmlns_fasten); |
| 196 end | 241 end |
