Mercurial > prosody-modules
comparison mod_muc_moderation/mod_muc_moderation.lua @ 5944:4b677e445b8a
mod_muc_moderation: adding a new hook that can be used to cancel the moderation, or modify resulting stanzas.
| author | John Livingston <git@john-livingston.fr> |
|---|---|
| date | Mon, 29 Jul 2024 13:08:43 +0200 |
| parents | 5076b78c95ef |
| children | bcad6baa4fc3 |
comparison
equal
deleted
inserted
replaced
| 5943:5076b78c95ef | 5944:4b677e445b8a |
|---|---|
| 107 announcement:add_direct_child(moderated_occupant_id); | 107 announcement:add_direct_child(moderated_occupant_id); |
| 108 end | 108 end |
| 109 | 109 |
| 110 announcement:reset(); | 110 announcement:reset(); |
| 111 | 111 |
| 112 local tombstone = nil; | |
| 112 if muc_log_archive.set and retract then | 113 if muc_log_archive.set and retract then |
| 113 local tombstone = st.message({ from = original.attr.from, type = "groupchat", id = original.attr.id }) | 114 tombstone = st.message({ from = original.attr.from, type = "groupchat", id = original.attr.id }) |
| 114 :tag("moderated", { xmlns = xmlns_moderate, by = actor_nick }) | 115 :tag("moderated", { xmlns = xmlns_moderate, by = actor_nick }) |
| 115 :tag("retracted", { xmlns = xmlns_retract, stamp = dt.datetime() }):up(); | 116 :tag("retracted", { xmlns = xmlns_retract, stamp = dt.datetime() }):up(); |
| 116 | 117 |
| 117 if reason then | 118 if reason then |
| 118 tombstone:text_tag("reason", reason); | 119 tombstone:text_tag("reason", reason); |
| 127 -- Copy occupant id from moderated message | 128 -- Copy occupant id from moderated message |
| 128 tombstone:add_direct_child(moderated_occupant_id); | 129 tombstone:add_direct_child(moderated_occupant_id); |
| 129 end | 130 end |
| 130 end | 131 end |
| 131 tombstone:reset(); | 132 tombstone:reset(); |
| 133 end | |
| 132 | 134 |
| 135 -- fire an event, that can be used to cancel the moderation, or modify stanzas. | |
| 136 local event = { | |
| 137 room = room; | |
| 138 announcement = announcement; | |
| 139 tombstone = tombstone; | |
| 140 stanza_id = stanza_id; | |
| 141 retract = retract; | |
| 142 reason = reason; | |
| 143 actor = actor; | |
| 144 actor_nick = actor_nick; | |
| 145 }; | |
| 146 if module:fire_event("muc-moderate-message", event) then | |
| 147 -- TODO: allow to change the error message? | |
| 148 return false, "wait", "internal-server-error"; | |
| 149 end | |
| 150 | |
| 151 if tombstone then | |
| 133 local was_replaced = muc_log_archive:set(room_node, stanza_id, tombstone); | 152 local was_replaced = muc_log_archive:set(room_node, stanza_id, tombstone); |
| 134 if not was_replaced then | 153 if not was_replaced then |
| 135 return false, "wait", "internal-server-error"; | 154 return false, "wait", "internal-server-error"; |
| 136 end | 155 end |
| 137 end | 156 end |
