changeset 3797:cc653b2685f0

core (memory/sqla), plugin XEP-0359: always add `origin-id`, and store: `origin-id` is now always added to messages, and it is stored to database in the new column instead of `extra` when present.
author Goffi <goffi@goffi.org>
date Fri, 17 Jun 2022 14:15:23 +0200
parents 24c1c06c865b
children b5013bada4b6
files sat/memory/sqla.py sat/plugins/plugin_xep_0359.py sat/plugins/plugin_xep_0384.py
diffstat 3 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/sat/memory/sqla.py	Fri Jun 17 14:15:23 2022 +0200
+++ b/sat/memory/sqla.py	Fri Jun 17 14:15:23 2022 +0200
@@ -564,6 +564,8 @@
                     or limit != 1):
                     raise ValueError("Unexpected values for last_stanza_id filter")
                 stmt = stmt.where(History.stanza_id.is_not(None))
+            if 'origin_id' in filters:
+                stmt = stmt.where(History.origin_id == filters["origin_id"])
 
         if limit is not None:
             stmt = stmt.limit(limit)
@@ -596,6 +598,7 @@
                 async with session.begin():
                     session.add(History(
                         uid=data["uid"],
+                        origin_id=data["extra"].get("origin_id"),
                         stanza_id=data["extra"].get("stanza_id"),
                         update_uid=data["extra"].get("update_uid"),
                         profile_id=self.profiles[profile],
--- a/sat/plugins/plugin_xep_0359.py	Fri Jun 17 14:15:23 2022 +0200
+++ b/sat/plugins/plugin_xep_0359.py	Fri Jun 17 14:15:23 2022 +0200
@@ -50,14 +50,26 @@
         self.host = host
         host.registerNamespace("stanza_id", NS_SID)
         host.trigger.add("message_parse", self._message_parseTrigger)
+        host.trigger.add("sendMessageData", self._sendMessageDataTrigger)
 
     def _message_parseTrigger(self, client, message_elt, mess_data):
         """Check if message has a stanza-id"""
         stanza_id = self.getStanzaId(message_elt, client.jid.userhostJID())
         if stanza_id is not None:
             mess_data['extra']['stanza_id'] = stanza_id
+        origin_id = self.getOriginId(message_elt)
+        if origin_id is not None:
+            mess_data['extra']['origin_id'] = origin_id
         return True
 
+    def _sendMessageDataTrigger(self, client, mess_data):
+        origin_id = mess_data["extra"].get("origin_id")
+        if not origin_id:
+            origin_id = str(uuid.uuid4())
+            mess_data["extra"]["origin_id"] = origin_id
+        message_elt = mess_data["xml"]
+        self.addOriginId(message_elt, origin_id)
+
     def getStanzaId(self, element, by):
         """Return stanza-id if found in element
 
--- a/sat/plugins/plugin_xep_0384.py	Fri Jun 17 14:15:23 2022 +0200
+++ b/sat/plugins/plugin_xep_0384.py	Fri Jun 17 14:15:23 2022 +0200
@@ -1417,9 +1417,6 @@
                     MUC_CACHE_TTL, self._expireMUCCache, client)
             else:
                 timer.reset(MUC_CACHE_TTL)
-            # we use origin-id when possible, to identifiy the message in a stable way
-            if self._sid is not None:
-                self._sid.addOriginId(message_elt, mess_data['uid'])
 
         encryption_data = yield defer.ensureDeferred(self.encryptMessage(
             client, to_jids, body, feedback_jid=feedback_jid))