Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0424.py @ 4381:3c97717fd662
plugin XEP-0428: Add missing "for" attribute:
The "for" attribute was missing from <fallback> element.
rel 461
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 04 Jul 2025 12:30:20 +0200 |
parents | 79d463e3fdeb |
children |
rev | line source |
---|---|
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Copyright (C) 2009-2022 Jérôme Poisson (goffi@goffi.org) |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # This program is free software: you can redistribute it and/or modify |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # it under the terms of the GNU Affero General Public License as published by |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # the Free Software Foundation, either version 3 of the License, or |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # (at your option) any later version. |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # This program is distributed in the hope that it will be useful, |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # GNU Affero General Public License for more details. |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # You should have received a copy of the GNU Affero General Public License |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 import time |
4381
3c97717fd662
plugin XEP-0428: Add missing "for" attribute:
Goffi <goffi@goffi.org>
parents:
4379
diff
changeset
|
19 from typing import Any, Dict, cast |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
21 from sqlalchemy.orm.attributes import flag_modified |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
22 from twisted.internet import defer |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
23 from twisted.words.protocols.jabber import jid, xmlstream |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.words.xish import domish |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from wokkel import disco |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from zope.interface import implementer |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
28 from libervia.backend.core import exceptions |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
29 from libervia.backend.core.constants import Const as C |
4379
79d463e3fdeb
core (types): Renamed `libervia.backend.core.core_types.MessageData` to `MessageDataLegacy`:
Goffi <goffi@goffi.org>
parents:
4199
diff
changeset
|
30 from libervia.backend.core.core_types import MessageDataLegacy, SatXMPPEntity |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
31 from libervia.backend.core.i18n import D_, _ |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
32 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
33 from libervia.backend.memory.sqla_mapping import History |
4381
3c97717fd662
plugin XEP-0428: Add missing "for" attribute:
Goffi <goffi@goffi.org>
parents:
4379
diff
changeset
|
34 from libervia.backend.plugins.plugin_xep_0428 import XEP_0428 |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
35 from libervia.backend.tools.common import data_format |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 log = getLogger(__name__) |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 PLUGIN_INFO = { |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 C.PI_NAME: "Message Retraction", |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 C.PI_IMPORT_NAME: "XEP-0424", |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 C.PI_TYPE: "XEP", |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 C.PI_MODES: C.PLUG_MODE_BOTH, |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
45 C.PI_PROTOCOLS: ["XEP-0424"], |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
46 C.PI_DEPENDENCIES: ["XEP-0334", "XEP-0428"], |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
47 C.PI_RECOMMENDATIONS: ["XEP-0045"], |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 C.PI_MAIN: "XEP_0424", |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 C.PI_HANDLER: "yes", |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 C.PI_DESCRIPTION: _("""Implementation Message Retraction"""), |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 } |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
53 NS_MESSAGE_RETRACT = "urn:xmpp:message-retract:1" |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 CATEGORY = "Privacy" |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 NAME = "retract_history" |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 LABEL = D_("Keep History of Retracted Messages") |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 PARAMS = """ |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 <params> |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 <individual> |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 <category name="{category_name}"> |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 <param name="{name}" label="{label}" type="bool" value="false" /> |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 </category> |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 </individual> |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 </params> |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 """.format( |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 category_name=CATEGORY, name=NAME, label=_(LABEL) |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 ) |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
71 class XEP_0424: |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 def __init__(self, host): |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
73 log.info(f"plugin {PLUGIN_INFO[C.PI_NAME]!r} initialization") |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 self.host = host |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3887
diff
changeset
|
75 host.memory.update_params(PARAMS) |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 self._h = host.plugins["XEP-0334"] |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
77 self._m = host.plugins.get("XEP-0045") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3887
diff
changeset
|
78 host.register_namespace("message-retract", NS_MESSAGE_RETRACT) |
4051
c23cad65ae99
core: renamed `messageReceived` trigger to `message_received`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
79 host.trigger.add("message_received", self._message_received_trigger, 100) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3887
diff
changeset
|
80 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3887
diff
changeset
|
81 "message_retract", |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 ".plugin", |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 in_sign="ss", |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 out_sign="", |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 method=self._retract, |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 async_=True, |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 ) |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3887
diff
changeset
|
89 def get_handler(self, __): |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 return XEP_0424_handler() |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 def _retract(self, message_id: str, profile: str) -> None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3887
diff
changeset
|
93 client = self.host.get_client(profile) |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
94 return defer.ensureDeferred(self.retract(client, message_id)) |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
96 def send_retract( |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
97 self, client: SatXMPPEntity, peer_jid: jid.JID, retract_id: str, history: History |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 ) -> None: |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 """Send a message retraction using origin-id |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 [retract] should be prefered: internal ID should be used as it is independant of |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 XEPs changes. However, in some case messages may not be stored in database |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 (notably for some components), and then this method can be used |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
104 |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
105 @param retract_id: ID (origin or stanza according to XEP-0359) of message to |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
106 retract |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
107 @param history: history instance of the message to retract |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 """ |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 message_elt = domish.Element((None, "message")) |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 message_elt["from"] = client.jid.full() |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
111 message_elt["to"] = peer_jid.full() |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
112 message_elt["type"] = history.type |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
113 retract_elt = message_elt.addElement((NS_MESSAGE_RETRACT, "retract")) |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
114 retract_elt["id"] = retract_id |
4381
3c97717fd662
plugin XEP-0428: Add missing "for" attribute:
Goffi <goffi@goffi.org>
parents:
4379
diff
changeset
|
115 fallback = cast(XEP_0428, self.host.plugins["XEP-0428"]) |
3c97717fd662
plugin XEP-0428: Add missing "for" attribute:
Goffi <goffi@goffi.org>
parents:
4379
diff
changeset
|
116 fallback.add_fallback_elt( |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 message_elt, |
4381
3c97717fd662
plugin XEP-0428: Add missing "for" attribute:
Goffi <goffi@goffi.org>
parents:
4379
diff
changeset
|
118 NS_MESSAGE_RETRACT, |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 "[A message retraction has been requested, but your client doesn't support " |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
120 "it]", |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3887
diff
changeset
|
122 self._h.add_hint_elements(message_elt, [self._h.HINT_STORE]) |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 client.send(message_elt) |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
125 async def retract_by_history(self, client: SatXMPPEntity, history: History) -> None: |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 """Send a message retraction using History instance |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 This method is to use instead of [retract] when the history instance is already |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 retrieved. Note that the instance must have messages and subjets loaded |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 @param history: history instance of the message to retract |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 """ |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
132 if history.type == C.MESS_TYPE_GROUPCHAT: |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
133 is_group_chat = True |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
134 peer_jid = jid.JID(history.source) |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
135 retract_id = history.stanza_id |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 else: |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
137 is_group_chat = False |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
138 peer_jid = jid.JID(history.dest) |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
139 if self._m is not None and self._m.is_joined_room(client, peer_jid): |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
140 # it's actually a private MUC message, we need the full JID. |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
141 peer_jid = history.dest_jid |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
142 retract_id = history.origin_id |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
143 |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
144 if not retract_id: |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
145 raise exceptions.FeatureNotFound( |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
146 "Message to retract doesn't have the necessary ID, the sending client is " |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
147 "probably not supporting message retraction." |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
148 ) |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
149 |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
150 self.send_retract(client, peer_jid, retract_id, history) |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
151 if not is_group_chat: |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
152 # retraction will happen when <retract> message will be received in the |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
153 # chat. |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
154 await self.retract_db_history(client, history) |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 async def retract( |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 self, |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 client: SatXMPPEntity, |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 message_id: str, |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 ) -> None: |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 """Send a message retraction request |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 @param message_id: ID of the message |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 This ID is the Libervia internal ID of the message. It will be retrieve from |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 database to find the ID used by XMPP (i.e. XEP-0359's "origin ID"). If the |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 message is not found in database, an exception will be raised |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 """ |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 if not message_id: |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 raise ValueError("message_id can't be empty") |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 history = await self.host.memory.storage.get( |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
171 client, |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
172 History, |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
173 History.uid, |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
174 message_id, |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
175 joined_loads=[History.messages, History.subjects, History.thread], |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 ) |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 if history is None: |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 raise exceptions.NotFound( |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 f"message to retract not found in database ({message_id})" |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3887
diff
changeset
|
181 await self.retract_by_history(client, history) |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3887
diff
changeset
|
183 async def retract_db_history(self, client, history: History) -> None: |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 """Mark an history instance in database as retracted |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 @param history: history instance |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 "messages" and "subjects" must be loaded too |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 """ |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
189 # FIXME: should we keep history? This is useful to check why a message has been |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 # retracted, but if may be bad if the user think it's really deleted |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
191 flag_modified(history, "extra") |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
192 keep_history = await self.host.memory.param_get_a_async( |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 NAME, CATEGORY, profile_key=client.profile |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 ) |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
195 old_version: Dict[str, Any] = {"timestamp": time.time()} |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 if keep_history: |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
197 old_version.update( |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
198 { |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
199 "messages": [m.serialise() for m in history.messages], |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
200 "subjects": [s.serialise() for s in history.subjects], |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
201 } |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
202 ) |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 history.extra.setdefault("old_versions", []).append(old_version) |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
205 |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
206 history.messages.clear() |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
207 history.subjects.clear() |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
208 history.extra["retracted"] = True |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
209 # we remove editions history to keep no trace of old messages |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
210 if "editions" in history.extra: |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
211 del history.extra["editions"] |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
212 if "attachments" in history.extra: |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
213 del history.extra["attachments"] |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
214 await self.host.memory.storage.add(history) |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
215 |
4379
79d463e3fdeb
core (types): Renamed `libervia.backend.core.core_types.MessageData` to `MessageDataLegacy`:
Goffi <goffi@goffi.org>
parents:
4199
diff
changeset
|
216 retract_data = MessageDataLegacy(history.serialise()) |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
217 self.host.bridge.message_update( |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
218 history.uid, |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
219 C.MESS_UPDATE_RETRACT, |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
220 data_format.serialise(retract_data), |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
221 client.profile, |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 ) |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3887
diff
changeset
|
224 async def _message_received_trigger( |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 self, |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 client: SatXMPPEntity, |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 message_elt: domish.Element, |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
228 post_treat: defer.Deferred, |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 ) -> bool: |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
230 retract_elt = next(message_elt.elements(NS_MESSAGE_RETRACT, "retract"), None) |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
231 if not retract_elt: |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 return True |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
233 try: |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
234 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT: |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
235 col_id = History.stanza_id |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
236 else: |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
237 col_id = History.origin_id |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
238 history = await self.host.memory.storage.get( |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
239 client, |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
240 History, |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
241 col_id, |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
242 retract_elt["id"], |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
243 joined_loads=[History.messages, History.subjects, History.thread], |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
244 ) |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
245 except KeyError: |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
246 log.warning(f"invalid retract element, missing id: {retract_elt.toXml()}") |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
247 return False |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
248 from_jid = jid.JID(message_elt["from"]) |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
249 |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
250 if history is not None and ( |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
251 (history.type == C.MESS_TYPE_GROUPCHAT and history.source_jid != from_jid) |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
252 or ( |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
253 history.type != C.MESS_TYPE_GROUPCHAT |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
254 and history.source_jid.userhostJID() != from_jid.userhostJID() |
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
255 ) |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
256 ): |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
257 log.warning( |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
258 f"Received message retraction from {from_jid.full()}, but the message to " |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
259 f"retract is from {history.source_jid.full()}. This maybe a hack " |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
260 f"attempt.\n{message_elt.toXml()}" |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
261 ) |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
262 return False |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
263 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3887
diff
changeset
|
264 if not await self.host.trigger.async_point( |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
265 "XEP-0424_retract_received", client, message_elt, retract_elt, history |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 ): |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 return False |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
268 |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
269 if history is None: |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 # we check history after the trigger because we may be in a component which |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 # doesn't store messages in database. |
4199
7eda7cb8a15c
plugin XEP-0424: fix ID used and recipients
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
272 log.warning(f"No message found with given id: {message_elt.toXml()}") |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 return False |
4166
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
274 log.info(f"[{client.profile}] retracting message {history.uid!r}") |
a1f7040b5a15
plugin XEP-0424: message retraction update:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
275 await self.retract_db_history(client, history) |
3801
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 return False |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 @implementer(disco.IDisco) |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 class XEP_0424_handler(xmlstream.XMPPHandler): |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 def getDiscoInfo(self, __, target, nodeIdentifier=""): |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 return [disco.DiscoFeature(NS_MESSAGE_RETRACT)] |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
6952a002abc7
plugin XEP-424: Message Retractation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 return [] |