Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0359.py @ 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 | be6d91572633 |
children | 8289ac1b34f4 |
comparison
equal
deleted
inserted
replaced
3796:24c1c06c865b | 3797:cc653b2685f0 |
---|---|
48 def __init__(self, host): | 48 def __init__(self, host): |
49 log.info(_("Unique and Stable Stanza IDs plugin initialization")) | 49 log.info(_("Unique and Stable Stanza IDs plugin initialization")) |
50 self.host = host | 50 self.host = host |
51 host.registerNamespace("stanza_id", NS_SID) | 51 host.registerNamespace("stanza_id", NS_SID) |
52 host.trigger.add("message_parse", self._message_parseTrigger) | 52 host.trigger.add("message_parse", self._message_parseTrigger) |
53 host.trigger.add("sendMessageData", self._sendMessageDataTrigger) | |
53 | 54 |
54 def _message_parseTrigger(self, client, message_elt, mess_data): | 55 def _message_parseTrigger(self, client, message_elt, mess_data): |
55 """Check if message has a stanza-id""" | 56 """Check if message has a stanza-id""" |
56 stanza_id = self.getStanzaId(message_elt, client.jid.userhostJID()) | 57 stanza_id = self.getStanzaId(message_elt, client.jid.userhostJID()) |
57 if stanza_id is not None: | 58 if stanza_id is not None: |
58 mess_data['extra']['stanza_id'] = stanza_id | 59 mess_data['extra']['stanza_id'] = stanza_id |
60 origin_id = self.getOriginId(message_elt) | |
61 if origin_id is not None: | |
62 mess_data['extra']['origin_id'] = origin_id | |
59 return True | 63 return True |
64 | |
65 def _sendMessageDataTrigger(self, client, mess_data): | |
66 origin_id = mess_data["extra"].get("origin_id") | |
67 if not origin_id: | |
68 origin_id = str(uuid.uuid4()) | |
69 mess_data["extra"]["origin_id"] = origin_id | |
70 message_elt = mess_data["xml"] | |
71 self.addOriginId(message_elt, origin_id) | |
60 | 72 |
61 def getStanzaId(self, element, by): | 73 def getStanzaId(self, element, by): |
62 """Return stanza-id if found in element | 74 """Return stanza-id if found in element |
63 | 75 |
64 @param element(domish.Element): element to parse | 76 @param element(domish.Element): element to parse |