From 7a7a3d8fe493fe22d14bc7d9c688e3966114791c Mon Sep 17 00:00:00 2001 From: Goffi Date: Tue, 25 Aug 2026 19:07:06 +0200 Subject: [PATCH] plugin XEP-0308: check message edit for room messages: - Reference the stanza-id assigned by the MUC service when correcting. - Ignore the edit (with a warning) if the original message has no usable id. --- libervia/backend/plugins/plugin_xep_0308.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libervia/backend/plugins/plugin_xep_0308.py b/libervia/backend/plugins/plugin_xep_0308.py index 90acd98e..f42e1e55 100644 --- a/libervia/backend/plugins/plugin_xep_0308.py +++ b/libervia/backend/plugins/plugin_xep_0308.py @@ -293,6 +293,18 @@ class XEP_0308: store=not is_group_chat, ) + ref_id = edited_history.stanza_id if is_group_chat else edited_history.origin_id + if not ref_id: + orig_data = edited_history.serialise() + orig_data["from"] = jid.JID(orig_data["from"]) + orig_data["to"] = jid.JID(orig_data["to"]) + log.warning( + f"Can't correct message {message_id}: the original message has no usable " + f"id (stanza_id={edited_history.stanza_id}, " + f"origin_id={edited_history.origin_id}), ignoring the edit." + ) + return + serialised = edited_history.serialise() serialised["uid"] = str(uuid.uuid4()) serialised["from"] = client.jid @@ -301,7 +313,7 @@ class XEP_0308: message_elt = client.generate_message_xml(serialised)["xml"] replace_elt = message_elt.addElement((NS_MESSAGE_CORRECT, "replace")) - replace_elt["id"] = edited_history.origin_id + replace_elt["id"] = ref_id self._h.add_hint_elements(message_elt, [self._h.HINT_STORE]) client.send(message_elt)