# HG changeset patch # User Goffi # Date 1655468123 -7200 # Node ID cc653b2685f0514b574433a9d999e0083e2af77e # Parent 24c1c06c865b84996d4132b89acf8d8bd967652b 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. diff -r 24c1c06c865b -r cc653b2685f0 sat/memory/sqla.py --- 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], diff -r 24c1c06c865b -r cc653b2685f0 sat/plugins/plugin_xep_0359.py --- 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 diff -r 24c1c06c865b -r cc653b2685f0 sat/plugins/plugin_xep_0384.py --- 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))