1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# This file is part of Gajim.
#
# Gajim is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; version 3 only.
#
# Gajim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
# Message Retraction (XEP-0424)
from __future__ import annotations
import nbxmpp
from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import JID
from nbxmpp.protocol import Message
from nbxmpp.structs import MessageProperties
from nbxmpp.structs import StanzaHandler
from gajim.common import app
from gajim.common import types
from gajim.common.events import MessageRetractionReceived
from gajim.common.modules.base import BaseModule
class MessageRetraction(BaseModule):
_nbxmpp_extends = 'MessageRetraction'
def __init__(self, client: types.Client) -> None:
BaseModule.__init__(self, client)
self.handlers = [
StanzaHandler(name='message',
callback=self._process_message_retraction,
ns=Namespace.MESSAGE_RETRACT,
priority=47)
]
def _process_message_retraction(self,
_client: types.xmppClient,
_stanza: Message,
properties: MessageProperties
) -> None:
if properties.message_retraction is None:
return
if properties.type.is_error:
return
# TODO: make sure to use correct jid here
jid = properties.jid
assert jid is not None
success = app.storage.archive.try_message_retraction(
self._account,
jid,
properties.message_retraction.origin_id,
properties.occupant_id)
if not success:
self._log.warning(
'Received invalid message retraction request from %s', jid)
return
app.ged.raise_event(MessageRetractionReceived(
account=self._account,
jid=jid,
origin_id=properties.message_retraction.origin_id))
raise nbxmpp.NodeProcessed
def retract_message(self,
jid: JID,
message_id: str
) -> None:
pass
|