Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_xep_0359.py @ 4197:9cda0347e0ac
plugin XEP-0359: if no origin ID is found, use <message> ID instead:
This way, we always have the right ID to check for non groupchat message in
`History.origin_id`.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 13 Dec 2023 22:00:25 +0100 |
parents | 6784d07b99c8 |
children | 0d7bb4df2343 |
comparison
equal
deleted
inserted
replaced
4196:8b673bb307c1 | 4197:9cda0347e0ac |
---|---|
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 | 2 |
3 | 3 # Libervia plugin for Message Archive Management (XEP-0359) |
4 # SAT plugin for Message Archive Management (XEP-0359) | 4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org) |
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) | |
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) | 5 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) |
7 | 6 |
8 # This program is free software: you can redistribute it and/or modify | 7 # This program is free software: you can redistribute it and/or modify |
9 # it under the terms of the GNU Affero General Public License as published by | 8 # it under the terms of the GNU Affero General Public License as published by |
10 # the Free Software Foundation, either version 3 of the License, or | 9 # the Free Software Foundation, either version 3 of the License, or |
18 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | 19 |
21 from typing import Optional | 20 from typing import Optional |
22 import uuid | 21 import uuid |
22 | |
23 from twisted.words.protocols.jabber import xmlstream | |
24 from twisted.words.xish import domish | |
25 from wokkel import disco | |
23 from zope.interface import implementer | 26 from zope.interface import implementer |
24 from twisted.words.protocols.jabber import xmlstream | 27 |
25 from wokkel import disco | 28 from libervia.backend.core import exceptions |
26 from libervia.backend.core.constants import Const as C | 29 from libervia.backend.core.constants import Const as C |
27 from libervia.backend.core import exceptions | 30 from libervia.backend.core.core_types import SatXMPPEntity |
28 from libervia.backend.core.i18n import _ | 31 from libervia.backend.core.i18n import _ |
29 from libervia.backend.core.log import getLogger | 32 from libervia.backend.core.log import getLogger |
30 from twisted.words.xish import domish | 33 from libervia.backend.models.core import MessageData |
31 | 34 |
32 log = getLogger(__name__) | 35 log = getLogger(__name__) |
33 | 36 |
34 | 37 |
35 PLUGIN_INFO = { | 38 PLUGIN_INFO = { |
53 self.host = host | 56 self.host = host |
54 host.register_namespace("stanza_id", NS_SID) | 57 host.register_namespace("stanza_id", NS_SID) |
55 host.trigger.add("message_parse", self._message_parse_trigger) | 58 host.trigger.add("message_parse", self._message_parse_trigger) |
56 host.trigger.add("send_message_data", self._send_message_data_trigger) | 59 host.trigger.add("send_message_data", self._send_message_data_trigger) |
57 | 60 |
58 def _message_parse_trigger(self, client, message_elt, mess_data): | 61 def _message_parse_trigger( |
62 self, | |
63 client: SatXMPPEntity, | |
64 message_elt: domish.Element, | |
65 mess_data: MessageData | |
66 ) -> bool: | |
59 """Check if message has a stanza-id""" | 67 """Check if message has a stanza-id""" |
60 stanza_id = self.get_stanza_id(message_elt, client.jid.userhostJID()) | 68 stanza_id = self.get_stanza_id(message_elt, client.jid.userhostJID()) |
61 if stanza_id is not None: | 69 if stanza_id is not None: |
62 mess_data['extra']['stanza_id'] = stanza_id | 70 mess_data['extra']['stanza_id'] = stanza_id |
63 origin_id = self.get_origin_id(message_elt) | 71 try: |
64 if origin_id is not None: | 72 origin_id = self.get_origin_id(message_elt) or message_elt["id"] |
73 except KeyError: | |
74 pass | |
75 else: | |
65 mess_data['extra']['origin_id'] = origin_id | 76 mess_data['extra']['origin_id'] = origin_id |
66 return True | 77 return True |
67 | 78 |
68 def _send_message_data_trigger(self, client, mess_data): | 79 def _send_message_data_trigger(self, client, mess_data): |
69 origin_id = mess_data["extra"].setdefault("origin_id", mess_data.get("uid")) | 80 origin_id = mess_data["extra"].setdefault("origin_id", mess_data.get("uid")) |