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)