comparison mod_muc_moderation/mod_muc_moderation.lua @ 4814:5f12c75fd210

mod_muc_moderation: Handle non-retraction moderation The XEP is light on details and does not show any example of non-retraction uses.
author Kim Alvefur <zash@zash.se>
date Tue, 07 Dec 2021 20:36:13 +0100
parents 80f871bedcdf
children 1071a420ff6f
comparison
equal deleted inserted replaced
4813:0a257d1402c3 4814:5f12c75fd210
42 local apply_to = stanza.tags[1]; 42 local apply_to = stanza.tags[1];
43 local moderate_tag = apply_to:get_child("moderate", xmlns_moderate); 43 local moderate_tag = apply_to:get_child("moderate", xmlns_moderate);
44 if not moderate_tag then return end -- some other kind of fastening? 44 if not moderate_tag then return end -- some other kind of fastening?
45 45
46 local reason = moderate_tag:get_child_text("reason"); 46 local reason = moderate_tag:get_child_text("reason");
47 local retract = moderate_tag:get_child("retract", xmlns_retract);
47 48
48 local room_jid = stanza.attr.to; 49 local room_jid = stanza.attr.to;
49 local room_node = jid.split(room_jid); 50 local room_node = jid.split(room_jid);
50 local room = mod_muc.get_room_from_jid(room_jid); 51 local room = mod_muc.get_room_from_jid(room_jid);
51 52
90 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); 91 origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
91 end 92 end
92 return true; 93 return true;
93 end 94 end
94 95
95 -- Replacements
96 local tombstone = st.message({ from = original.attr.from, type = "groupchat", id = original.attr.id })
97 :tag("moderated", { xmlns = xmlns_moderate, by = actor_nick })
98 :tag("retracted", { xmlns = xmlns_retract, stamp = dt.datetime() }):up();
99 96
100 local announcement = st.message({ from = room_jid, type = "groupchat", id = id.medium(), }) 97 local announcement = st.message({ from = room_jid, type = "groupchat", id = id.medium(), })
101 :tag("apply-to", { xmlns = xmlns_fasten, id = stanza_id }) 98 :tag("apply-to", { xmlns = xmlns_fasten, id = stanza_id })
102 :tag("moderated", { xmlns = xmlns_moderate, by = actor_nick }) 99 :tag("moderated", { xmlns = xmlns_moderate, by = actor_nick })
103 :tag("retract", { xmlns = xmlns_retract }):up(); 100
101 if retract then
102 announcement:tag("retract", { xmlns = xmlns_retract }):up();
103 end
104 104
105 if reason then 105 if reason then
106 tombstone:text_tag("reason", reason);
107 announcement:text_tag("reason", reason); 106 announcement:text_tag("reason", reason);
108 end 107 end
109 108
110 if muc_log_archive.set then 109 if muc_log_archive.set and retract then
111 -- Tombstone 110 local tombstone = st.message({ from = original.attr.from, type = "groupchat", id = original.attr.id })
111 :tag("moderated", { xmlns = xmlns_moderate, by = actor_nick })
112 :tag("retracted", { xmlns = xmlns_retract, stamp = dt.datetime() }):up();
113
114 if reason then
115 tombstone:text_tag("reason", reason);
116 end
117
112 local was_replaced = muc_log_archive:set(room_node, stanza_id, tombstone); 118 local was_replaced = muc_log_archive:set(room_node, stanza_id, tombstone);
113 if not was_replaced then 119 if not was_replaced then
114 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); 120 origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
115 return true; 121 return true;
116 end 122 end