Welcome to mirror list, hosted at ThFree Co, Russian Federation.

reactions.py « modules « common « gajim - dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1f3dacf1acfd2a0b6b21e3f2f0de4081edf5b9b5 (plain)
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
85
86
87
88
89
# 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 Reactions (XEP-0444)

from __future__ import annotations

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 ReactionReceived
from gajim.common.modules.base import BaseModule


class Reactions(BaseModule):

    _nbxmpp_extends = 'Reactions'

    def __init__(self, client: types.Client) -> None:
        BaseModule.__init__(self, client)

        self.handlers = [
            StanzaHandler(name='message',
                          callback=self._process_reaction,
                          ns=Namespace.REACTIONS,
                          priority=47)
        ]

    def _process_reaction(self,
                          _client: types.xmppClient,
                          _stanza: Message,
                          properties: MessageProperties
                          ) -> None:

        if properties.reactions 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

        app.storage.archive.update_reactions(
            self._account,
            jid,
            properties.occupant_id,
            properties.timestamp,
            properties.reactions)

        app.ged.raise_event(
            ReactionReceived(account=self._account,
                             jid=jid,
                             reaction_id=properties.reactions.id))

    def add_reaction(self,
                     jid: JID,
                     message_id: str,
                     reactions: list[str]
                     ) -> None:

        # TODO
        pass

    def remove_reaction(self,
                        jid: JID,
                        message_id: str,
                        reactions: list[str]
                        ) -> None:

        # TODO
        pass