annotate libervia/backend/plugins/plugin_xep_0045.py @ 4309:b56b1eae7994

component email gateway: add multicasting: XEP-0033 multicasting is now supported both for incoming and outgoing messages. XEP-0033 metadata are converted to suitable Email headers and vice versa. Email address and JID are both supported, and delivery is done by the gateway when suitable on incoming messages. rel 450
author Goffi <goffi@goffi.org>
date Thu, 26 Sep 2024 16:12:01 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
4 # SAT plugin for managing xep-0045
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3254
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
10 # (at your option) any later version.
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
15 # GNU Affero General Public License for more details.
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
20 import time
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
21 from typing import Optional
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
22 import uuid
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
23
4245
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
24 import shortuuid
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
25 from twisted.internet import defer
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
26 from twisted.python import failure
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
27 from twisted.words.protocols.jabber import jid
3080
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
28 from twisted.words.protocols.jabber import error as xmpp_error
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
29 from wokkel import disco, iwokkel, muc
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
30 from wokkel import rsm
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
31 from wokkel import mam
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
32 from zope.interface import implementer
505
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
33
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
34 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
35 from libervia.backend.core.core_types import SatXMPPEntity
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
36 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
37 from libervia.backend.core.i18n import D_, _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
38 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
39 from libervia.backend.memory import memory
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
40 from libervia.backend.tools import xml_tools, utils
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
41
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42
3080
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
43 log = getLogger(__name__)
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
44
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
45
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
47 C.PI_NAME: "XEP-0045 Plugin",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
48 C.PI_IMPORT_NAME: "XEP-0045",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
49 C.PI_TYPE: "XEP",
4183
6784d07b99c8 plugin XEP-053, component AP gateway: use the new `trigger.add_with_check` method
Goffi <goffi@goffi.org>
parents: 4155
diff changeset
50 C.PI_MODES: C.PLUG_MODE_BOTH,
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
51 C.PI_PROTOCOLS: ["XEP-0045"],
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
52 C.PI_DEPENDENCIES: ["XEP-0359"],
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
53 C.PI_RECOMMENDATIONS: [C.TEXT_CMDS, "XEP-0313"],
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
54 C.PI_MAIN: "XEP_0045",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
55 C.PI_HANDLER: "yes",
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
56 C.PI_DESCRIPTION: _("""Implementation of Multi-User Chat"""),
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 }
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
59 NS_MUC = "http://jabber.org/protocol/muc"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
60 AFFILIATIONS = ("owner", "admin", "member", "none", "outcast")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
61 ROOM_USER_JOINED = "ROOM_USER_JOINED"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
62 ROOM_USER_LEFT = "ROOM_USER_LEFT"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
63 OCCUPANT_KEYS = ("nick", "entity", "affiliation", "role")
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 ROOM_STATE_OCCUPANTS = "occupants"
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 ROOM_STATE_SELF_PRESENCE = "self-presence"
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 ROOM_STATE_LIVE = "live"
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 ROOM_STATES = (ROOM_STATE_OCCUPANTS, ROOM_STATE_SELF_PRESENCE, ROOM_STATE_LIVE)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
68 HISTORY_LEGACY = "legacy"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
69 HISTORY_MAM = "mam"
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
71
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
72 CONFIG_SECTION = "plugin muc"
1407
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
73
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
74 default_conf = {"default_muc": "sat@chat.jabberfr.org"}
1407
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
75
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
76
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
77 class AlreadyJoined(exceptions.ConflictError):
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
78
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
79 def __init__(self, room):
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
80 super(AlreadyJoined, self).__init__()
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
81 self.room = room
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
82
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
83
4245
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
84 class XEP_0045:
2046
b99bd02ea643 plugin XEP-0045, XEP-0054, XEP-0096: deprecated bridge method are not used anymore
Goffi <goffi@goffi.org>
parents: 2028
diff changeset
85 # TODO: handle invitations
2461
34cb8b713370 plugin XEP-0045: added mucNickGet to retrieve our nickname in a MUC room
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
86 # FIXME: this plugin need a good cleaning, join method is messy
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 950
diff changeset
89 log.info(_("Plugin XEP_0045 initialization"))
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 self.host = host
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
91 self._sessions = memory.Sessions()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
92 # return same arguments as muc_room_joined + a boolean set to True is the room was
3060
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
93 # already joined (first argument)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
94 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
95 "muc_join",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
96 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
97 in_sign="ssa{ss}s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
98 out_sign="(bsa{sa{ss}}ssass)",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
99 method=self._join,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
100 async_=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
101 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
102 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
103 "muc_nick", ".plugin", in_sign="sss", out_sign="", method=self._nick
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
104 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
105 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
106 "muc_nick_get",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
107 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
108 in_sign="ss",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
109 out_sign="s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
110 method=self._get_room_nick,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
111 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
112 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
113 "muc_leave",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
114 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
115 in_sign="ss",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
116 out_sign="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
117 method=self._leave,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
118 async_=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
119 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
120 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
121 "muc_occupants_get",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
122 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
123 in_sign="ss",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
124 out_sign="a{sa{ss}}",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
125 method=self._get_room_occupants,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
126 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
127 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
128 "muc_subject", ".plugin", in_sign="sss", out_sign="", method=self._subject
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
129 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
130 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
131 "muc_get_rooms_joined",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
132 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
133 in_sign="s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
134 out_sign="a(sa{sa{ss}}ssas)",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
135 method=self._get_rooms_joined,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
136 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
137 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
138 "muc_get_unique_room_name",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
139 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
140 in_sign="ss",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
141 out_sign="s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
142 method=self._get_unique_name,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
143 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
144 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
145 "muc_configure_room",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
146 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
147 in_sign="ss",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
148 out_sign="s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
149 method=self._configure_room,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
150 async_=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
151 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
152 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
153 "muc_get_default_service",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
154 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
155 in_sign="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
156 out_sign="s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
157 method=self.get_default_muc,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
158 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
159 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
160 "muc_get_service",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
161 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
162 in_sign="ss",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
163 out_sign="s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
164 method=self._get_muc_service,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
165 async_=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
166 )
3060
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
167 # called when a room will be joined but must be locked until join is received
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
168 # (room is prepared, history is getting retrieved)
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
169 # args: room_jid, profile
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
170 host.bridge.add_signal("muc_room_prepare_join", ".plugin", signature="ss")
3060
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
171 # args: room_jid, occupants, user_nick, subject, profile
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
172 host.bridge.add_signal("muc_room_joined", ".plugin", signature="sa{sa{ss}}ssass")
3060
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
173 # args: room_jid, profile
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
174 host.bridge.add_signal("muc_room_left", ".plugin", signature="ss")
3060
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
175 # args: room_jid, old_nick, new_nick, profile
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
176 host.bridge.add_signal("muc_room_user_changed_nick", ".plugin", signature="ssss")
3060
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
177 # args: room_jid, subject, profile
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
178 host.bridge.add_signal("muc_room_new_subject", ".plugin", signature="sss")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
179 self.__submit_conf_id = host.register_callback(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
180 self._submit_configuration, with_data=True
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
181 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
182 self._room_join_id = host.register_callback(self._ui_room_join_cb, with_data=True)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
183 host.import_menu(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
184 (D_("MUC"), D_("configure")),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
185 self._configure_room_menu,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
186 security_limit=0,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
187 help_string=D_("Configure Multi-User Chat room"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
188 type_=C.MENU_ROOM,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
189 )
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
190 try:
1992
d5befe7253aa plugin XEP-0045: fixed typo in text commands
Goffi <goffi@goffi.org>
parents: 1990
diff changeset
191 self.text_cmds = self.host.plugins[C.TEXT_CMDS]
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
192 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
193 log.info(_("Text commands not available"))
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
194 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
195 self.text_cmds.register_text_commands(self)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
196 self.text_cmds.add_who_is_cb(self._whois, 100)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
197
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
198 self._mam = self.host.plugins.get("XEP-0313")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
199 self._si = self.host.plugins["XEP-0359"]
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
200
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
201 host.trigger.add("presence_available", self.presence_trigger)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
202 host.trigger.add("presence_received", self.presence_received_trigger)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
203 host.trigger.add(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
204 "message_received", self.message_received_trigger, priority=1000000
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
205 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
206 host.trigger.add("message_parse", self._message_parse_trigger)
1239
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
207
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
208 async def profile_connected(self, client):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
209 client.muc_service = await self.get_muc_service(client)
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
210
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
211 def _message_parse_trigger(self, client, message_elt, data):
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
212 """Add stanza-id from the room if present"""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
213 if message_elt.getAttribute("type") != C.MESS_TYPE_GROUPCHAT:
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
214 return True
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
215
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
216 # stanza_id will not be filled by parse_message because the emitter
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
217 # is the room and not our server, so we have to parse it here
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
218 room_jid = data["from"].userhostJID()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
219 stanza_id = self._si.get_stanza_id(message_elt, room_jid)
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
220 if stanza_id:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
221 data["extra"]["stanza_id"] = stanza_id
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
222
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
223 def message_received_trigger(self, client, message_elt, post_treat):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
224 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT:
4155
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
225 if message_elt.subject:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
226 return False
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
227 from_jid = jid.JID(message_elt["from"])
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
228 room_jid = from_jid.userhostJID()
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
229 if room_jid in client._muc_client.joined_rooms:
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
230 room = client._muc_client.joined_rooms[room_jid]
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
231 if room.state != ROOM_STATE_LIVE:
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
232 if getattr(room, "_history_type", HISTORY_LEGACY) == HISTORY_LEGACY:
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
233 # With MAM history, order is different, and we can get live
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
234 # messages before history is complete, so this is not a warning
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
235 # but an expected case.
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
236 # On the other hand, with legacy history, it's not normal.
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
237 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
238 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
239 "Received non delayed message in a room before its "
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
240 "initialisation: state={state}, msg={msg}"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
241 ).format(state=room.state, msg=message_elt.toXml())
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
242 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
243 room._cache.append(message_elt)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
244 return False
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
245 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
246 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
247 "Received groupchat message for a room which has not been "
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
248 "joined, ignoring it: {}".format(message_elt.toXml())
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
249 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
250 return False
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
251 return True
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
252
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
253 def get_room(self, client: SatXMPPEntity, room_jid: jid.JID) -> muc.Room:
2844
fa1cc09df195 plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents: 2827
diff changeset
254 """Retrieve Room instance from its jid
fa1cc09df195 plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents: 2827
diff changeset
255
3911
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3573
diff changeset
256 @param room_jid: jid of the room
2844
fa1cc09df195 plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents: 2827
diff changeset
257 @raise exceptions.NotFound: the room has not been joined
fa1cc09df195 plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents: 2827
diff changeset
258 """
fa1cc09df195 plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents: 2827
diff changeset
259 try:
fa1cc09df195 plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents: 2827
diff changeset
260 return client._muc_client.joined_rooms[room_jid]
fa1cc09df195 plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents: 2827
diff changeset
261 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
262 raise exceptions.NotFound(_("This room has not been joined"))
2844
fa1cc09df195 plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents: 2827
diff changeset
263
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
264 def check_room_joined(self, client, room_jid):
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
265 """Check that given room has been joined in current session
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
266
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
267 @param room_jid (JID): room JID
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
268 """
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
269 if room_jid not in client._muc_client.joined_rooms:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
270 raise exceptions.NotFound(_("This room has not been joined"))
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
271
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
272 def is_joined_room(self, client: SatXMPPEntity, room_jid: jid.JID) -> bool:
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
273 """Tell if a jid is a known and joined room
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
274
3911
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3573
diff changeset
275 @room_jid: jid of the room
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
276 """
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
277 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
278 self.check_room_joined(client, room_jid)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
279 except exceptions.NotFound:
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
280 return False
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
281 else:
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
282 return True
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
283
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
284 def is_room(self, client, entity_jid):
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
285 """Tell if a jid is a joined MUC
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
286
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
287 similar to is_joined_room but returns a boolean
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
288 @param entity_jid(jid.JID): full or bare jid of the entity check
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
289 @return (bool): True if the bare jid of the entity is a room jid
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
290 """
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
291 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
292 self.check_room_joined(client, entity_jid.userhostJID())
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
293 except exceptions.NotFound:
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
294 return False
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
295 else:
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
296 return True
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
297
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
298 def get_bare_or_full(self, client, peer_jid):
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
299 """use full jid if peer_jid is an occupant of a room, bare jid else
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
300
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
301 @param peer_jid(jid.JID): entity to test
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
302 @return (jid.JID): bare or full jid
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
303 """
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
304 if peer_jid.resource:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
305 if not self.is_room(client, peer_jid):
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
306 return peer_jid.userhostJID()
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
307 return peer_jid
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
308
4155
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
309 def get_room_user_jid(self, client: SatXMPPEntity, room_jid: jid.JID) -> jid.JID:
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
310 """Get the nick used in the room
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
311
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
312 @param room_jid: jid of the room to use
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
313 @return: JID used in room
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
314
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
315 @raise exceptions.NotFound: this room has not been joined
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
316 @raise exceptions.InternalError: invalid room_jid
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
317 """
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
318 # FIXME: doesn't check if room is anonymous or not
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
319 # TODO: check if room is (semi)anonymous
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
320 if room_jid.resource:
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
321 raise exceptions.InternalError(f"{room_jid} should not have a ressource.")
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
322 room = self.get_room(client, room_jid)
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
323 return jid.JID(tuple=(room_jid.user, room_jid.host, room.nick))
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
324
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
325 def _get_room_joined_args(self, room, profile):
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
326 return [
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
327 room.roomJID.userhost(),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
328 XEP_0045._get_occupants(room),
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
329 room.nick,
4196
8b673bb307c1 plugin XEP-0045: avoir crash if `subject` is not set when `_get_room_joined_args` is called.
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
330 # FIXME: getattr below is a Q&D fix as `subject` may not be set in early call
8b673bb307c1 plugin XEP-0045: avoir crash if `subject` is not set when `_get_room_joined_args` is called.
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
331 # of _get_rooms_joined (during `join` call). The whole workflow of this
8b673bb307c1 plugin XEP-0045: avoir crash if `subject` is not set when `_get_room_joined_args` is called.
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
332 # plugin should be refactored.
8b673bb307c1 plugin XEP-0045: avoir crash if `subject` is not set when `_get_room_joined_args` is called.
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
333 getattr(room, "subject", ""),
3101
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3086
diff changeset
334 [s.name for s in room.statuses],
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
335 profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
336 ]
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
337
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
338 def _ui_room_join_cb(self, data, profile):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
339 room_jid = jid.JID(data["index"])
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
340 client = self.host.get_client(profile)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
341 defer.ensureDeferred(self.join(client, room_jid))
1990
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
342 return {}
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
343
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
344 def _password_ui_cb(self, data, client, room_jid, nick):
1986
fbd313cfd40b plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents: 1984
diff changeset
345 """Called when the user has given room password (or cancelled)"""
fbd313cfd40b plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents: 1984
diff changeset
346 if C.bool(data.get(C.XMLUI_DATA_CANCELLED, "false")):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
347 log.info("room join for {} is cancelled".format(room_jid.userhost()))
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
348 raise failure.Failure(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
349 exceptions.CancelError(D_("Room joining cancelled by user"))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
350 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
351 password = data[xml_tools.form_escape("password")]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
352 return client._muc_client.join(room_jid, nick, password).addCallbacks(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
353 self._join_cb,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
354 self._join_eb,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
355 (client, room_jid, nick),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
356 errbackArgs=(client, room_jid, nick, password),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
357 )
1986
fbd313cfd40b plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents: 1984
diff changeset
358
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
359 def _show_list_ui(self, items, client, service):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
360 xmlui = xml_tools.XMLUI(title=D_("Rooms in {}".format(service.full())))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
361 adv_list = xmlui.change_container(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
362 "advanced_list",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
363 columns=1,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
364 selectable="single",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
365 callback_id=self._room_join_id,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
366 )
1990
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
367 items = sorted(items, key=lambda i: i.name.lower())
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
368 for item in items:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
369 adv_list.set_row_index(item.entity.full())
1990
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
370 xmlui.addText(item.name)
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
371 adv_list.end()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
372 self.host.action_new({"xmlui": xmlui.toXml()}, profile=client.profile)
1990
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
373
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
374 def _join_cb(self, room, client, room_jid, nick):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
375 """Called when the user is in the requested room"""
452
fd455b3ca6d4 plugin XEP-0045: room unlocking fix
Goffi <goffi@goffi.org>
parents: 451
diff changeset
376 if room.locked:
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
377 # FIXME: the current behaviour is to create an instant room
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
378 # and send the signal only when the room is unlocked
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
379 # a proper configuration management should be done
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
380 log.debug(_("room locked !"))
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
381 d = client._muc_client.configure(room.roomJID, {})
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
382 d.addErrback(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
383 self.host.log_errback,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
384 msg=_("Error while configuring the room: {failure_}"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
385 )
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
386 return room.fully_joined
319
5bb1cfc105d0 plugin xep-0045: misc improvments
Goffi <goffi@goffi.org>
parents: 291
diff changeset
387
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
388 def _join_eb(self, failure_, client, room_jid, nick, password):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
389 """Called when something is going wrong when joining the room"""
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
390 try:
3086
13be04a70e2f plugin XEP-0045: show join error even if it's not a StanzaError, log it with warning instead of error
Goffi <goffi@goffi.org>
parents: 3080
diff changeset
391 condition = failure_.value.condition
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
392 except AttributeError:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
393 msg_suffix = f": {failure_}"
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
394 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
395 if condition == "conflict":
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
396 # we have a nickname conflict, we try again with "_" suffixed to current nickname
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
397 nick += "_"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
398 return client._muc_client.join(room_jid, nick, password).addCallbacks(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
399 self._join_cb,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
400 self._join_eb,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
401 (client, room_jid, nick),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
402 errbackArgs=(client, room_jid, nick, password),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
403 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
404 elif condition == "not-allowed":
1986
fbd313cfd40b plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents: 1984
diff changeset
405 # room is restricted, we need a password
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
406 password_ui = xml_tools.XMLUI(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
407 "form",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
408 title=D_("Room {} is restricted").format(room_jid.userhost()),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
409 submit_id="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
410 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
411 password_ui.addText(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
412 D_("This room is restricted, please enter the password")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
413 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
414 password_ui.addPassword("password")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
415 d = xml_tools.defer_xmlui(self.host, password_ui, profile=client.profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
416 d.addCallback(self._password_ui_cb, client, room_jid, nick)
1986
fbd313cfd40b plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents: 1984
diff changeset
417 return d
fbd313cfd40b plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents: 1984
diff changeset
418
3086
13be04a70e2f plugin XEP-0045: show join error even if it's not a StanzaError, log it with warning instead of error
Goffi <goffi@goffi.org>
parents: 3080
diff changeset
419 msg_suffix = ' with condition "{}"'.format(failure_.value.condition)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
420
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
421 mess = D_(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
422 "Error while joining the room {room}{suffix}".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
423 room=room_jid.userhost(), suffix=msg_suffix
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
424 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
425 )
3086
13be04a70e2f plugin XEP-0045: show join error even if it's not a StanzaError, log it with warning instead of error
Goffi <goffi@goffi.org>
parents: 3080
diff changeset
426 log.warning(mess)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
427 xmlui = xml_tools.note(mess, D_("Group chat error"), level=C.XMLUI_DATA_LVL_ERROR)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
428 self.host.action_new({"xmlui": xmlui.toXml()}, profile=client.profile)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
429
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
430 @staticmethod
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
431 def _get_occupants(room):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
432 """Get occupants of a room in a form suitable for bridge"""
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
433 return {
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
434 u.nick: {k: str(getattr(u, k) or "") for k in OCCUPANT_KEYS}
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
435 for u in list(room.roster.values())
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
436 }
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
437
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
438 def _get_room_occupants(self, room_jid_s, profile_key):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
439 client = self.host.get_client(profile_key)
2844
fa1cc09df195 plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents: 2827
diff changeset
440 room_jid = jid.JID(room_jid_s)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
441 return self.get_room_occupants(client, room_jid)
2844
fa1cc09df195 plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents: 2827
diff changeset
442
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
443 def get_room_occupants(self, client, room_jid):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
444 room = self.get_room(client, room_jid)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
445 return self._get_occupants(room)
2844
fa1cc09df195 plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents: 2827
diff changeset
446
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
447 def _get_rooms_joined(self, profile_key=C.PROF_KEY_NONE):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
448 client = self.host.get_client(profile_key)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
449 return self.get_rooms_joined(client)
1392
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
450
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
451 def get_rooms_joined(self, client):
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
452 """Return rooms where user is"""
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
453 result = []
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
454 for room in list(client._muc_client.joined_rooms.values()):
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
455 if room.state == ROOM_STATE_LIVE:
3101
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3086
diff changeset
456 result.append(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
457 (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
458 room.roomJID.userhost(),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
459 self._get_occupants(room),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
460 room.nick,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
461 room.subject,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
462 [s.name for s in room.statuses],
3101
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3086
diff changeset
463 )
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3086
diff changeset
464 )
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
465 return result
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
466
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
467 def _get_room_nick(self, room_jid_s, profile_key=C.PROF_KEY_NONE):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
468 client = self.host.get_client(profile_key)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
469 return self.get_room_nick(client, jid.JID(room_jid_s))
2461
34cb8b713370 plugin XEP-0045: added mucNickGet to retrieve our nickname in a MUC room
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
470
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
471 def get_room_nick(self, client, room_jid):
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
472 """return nick used in room by user
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
473
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
474 @param room_jid (jid.JID): JID of the room
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
475 @profile_key: profile
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
476 @return: nick or empty string in case of error
2461
34cb8b713370 plugin XEP-0045: added mucNickGet to retrieve our nickname in a MUC room
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
477 @raise exceptions.Notfound: use has not joined the room
715
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
478 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
479 self.check_room_joined(client, room_jid)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
480 return client._muc_client.joined_rooms[room_jid].nick
715
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
481
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
482 def _configure_room(self, room_jid_s, profile_key=C.PROF_KEY_NONE):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
483 client = self.host.get_client(profile_key)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
484 d = self.configure_room(client, jid.JID(room_jid_s))
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
485 d.addCallback(lambda xmlui: xmlui.toXml())
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
486 return d
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
487
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
488 def _configure_room_menu(self, menu_data, profile):
1094
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
489 """Return room configuration form
1135
3158f9e08760 plugin OTR: a warning is logged when Account is instancied with a bare jid.
Goffi <goffi@goffi.org>
parents: 1101
diff changeset
490
1094
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
491 @param menu_data: %(menu_data)s
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
492 @param profile: %(doc_profile)s
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
493 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
494 client = self.host.get_client(profile)
1094
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
495 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
496 room_jid = jid.JID(menu_data["room_jid"])
1094
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
497 except KeyError:
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
498 log.error(_("room_jid key is not present !"))
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
499 return defer.fail(exceptions.DataError)
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
500
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
501 def xmlui_received(xmlui):
2584
f8e4d855001e plugin XEP-0045: display a note when no configuration is available on the room
Goffi <goffi@goffi.org>
parents: 2583
diff changeset
502 if not xmlui:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
503 msg = D_("No configuration available for this room")
2584
f8e4d855001e plugin XEP-0045: display a note when no configuration is available on the room
Goffi <goffi@goffi.org>
parents: 2583
diff changeset
504 return {"xmlui": xml_tools.note(msg).toXml()}
1094
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
505 return {"xmlui": xmlui.toXml()}
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
506
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
507 return self.configure_room(client, room_jid).addCallback(xmlui_received)
1094
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
508
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
509 def configure_room(self, client, room_jid):
1094
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
510 """return the room configuration form
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
511
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
512 @param room: jid of the room to configure
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
513 @return: configuration form as XMLUI
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
514 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
515 self.check_room_joined(client, room_jid)
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
516
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
517 def config_2_xmlui(result):
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
518 if not result:
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
519 return ""
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
520 session_id, session_data = self._sessions.new_session(profile=client.profile)
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
521 session_data["room_jid"] = room_jid
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
522 xmlui = xml_tools.data_form_2_xmlui(result, submit_id=self.__submit_conf_id)
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
523 xmlui.session_id = session_id
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
524 return xmlui
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
525
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
526 d = client._muc_client.getConfiguration(room_jid)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
527 d.addCallback(config_2_xmlui)
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
528 return d
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
529
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
530 def _submit_configuration(self, raw_data, profile):
2583
8378806a70fe plugin XEP-0045: fixed room configuration cancellation
Goffi <goffi@goffi.org>
parents: 2581
diff changeset
531 cancelled = C.bool(raw_data.get("cancelled", C.BOOL_FALSE))
8378806a70fe plugin XEP-0045: fixed room configuration cancellation
Goffi <goffi@goffi.org>
parents: 2581
diff changeset
532 if cancelled:
8378806a70fe plugin XEP-0045: fixed room configuration cancellation
Goffi <goffi@goffi.org>
parents: 2581
diff changeset
533 return defer.succeed({})
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
534 client = self.host.get_client(profile)
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
535 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
536 session_data = self._sessions.profile_get(raw_data["session_id"], profile)
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
537 except KeyError:
1068
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
538 log.warning(D_("Session ID doesn't exist, session has probably expired."))
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
539 _dialog = xml_tools.XMLUI("popup", title=D_("Room configuration failed"))
1068
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
540 _dialog.addText(D_("Session ID doesn't exist, session has probably expired."))
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
541 return defer.succeed({"xmlui": _dialog.toXml()})
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
542
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
543 data = xml_tools.xmlui_result_2_data_form_result(raw_data)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
544 d = client._muc_client.configure(session_data["room_jid"], data)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
545 _dialog = xml_tools.XMLUI("popup", title=D_("Room configuration succeed"))
1068
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
546 _dialog.addText(D_("The new settings have been saved."))
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
547 d.addCallback(lambda ignore: {"xmlui": _dialog.toXml()})
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
548 del self._sessions[raw_data["session_id"]]
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
549 return d
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
550
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
551 def is_nick_in_room(self, client, room_jid, nick):
522
3446ce33247d plugin XEP-0045: added isNickInRoom method
Goffi <goffi@goffi.org>
parents: 519
diff changeset
552 """Tell if a nick is currently present in a room"""
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
553 self.check_room_joined(client, room_jid)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
554 return client._muc_client.joined_rooms[room_jid].inRoster(muc.User(nick))
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
555
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
556 def _get_muc_service(self, jid_=None, profile=C.PROF_KEY_NONE):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
557 client = self.host.get_client(profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
558 d = defer.ensureDeferred(self.get_muc_service(client, jid_ or None))
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
559 d.addCallback(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
560 lambda service_jid: service_jid.full() if service_jid is not None else ""
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
561 )
2468
8f14c1865e9e plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents: 2461
diff changeset
562 return d
8f14c1865e9e plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents: 2461
diff changeset
563
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
564 async def get_muc_service(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
565 self, client: SatXMPPEntity, jid_: Optional[jid.JID] = None
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
566 ) -> Optional[jid.JID]:
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
567 """Return first found MUC service of an entity
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
568
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
569 @param jid_: entity which may have a MUC service, or None for our own server
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
570 @return: found service jid or None
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
571 """
2468
8f14c1865e9e plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents: 2461
diff changeset
572 if jid_ is None:
8f14c1865e9e plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents: 2461
diff changeset
573 try:
8f14c1865e9e plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents: 2461
diff changeset
574 muc_service = client.muc_service
8f14c1865e9e plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents: 2461
diff changeset
575 except AttributeError:
8f14c1865e9e plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents: 2461
diff changeset
576 pass
8f14c1865e9e plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents: 2461
diff changeset
577 else:
8f14c1865e9e plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents: 2461
diff changeset
578 # we have a cached value, we return it
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
579 return muc_service
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
580 services = await self.host.find_service_entities(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
581 client, "conference", "text", jid_
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
582 )
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
583 for service in services:
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
584 if ".irc." not in service.userhost():
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
585 # FIXME:
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
586 # This ugly hack is here to avoid an issue with openfire: the IRC gateway
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
587 # use "conference/text" identity (instead of "conference/irc")
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
588 muc_service = service
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
589 break
2613
9680cd958529 plugin XEP-0045: fixed crash when muc service is not found
Goffi <goffi@goffi.org>
parents: 2584
diff changeset
590 else:
9680cd958529 plugin XEP-0045: fixed crash when muc service is not found
Goffi <goffi@goffi.org>
parents: 2584
diff changeset
591 muc_service = None
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
592 return muc_service
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
593
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
594 def _get_unique_name(self, muc_service="", profile_key=C.PROF_KEY_NONE):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
595 client = self.host.get_client(profile_key)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
596 return self.get_unique_name(client, muc_service or None).full()
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
597
4245
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
598 def get_unique_name(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
599 self, client: SatXMPPEntity, muc_service: jid.JID | None = None, prefix: str = ""
4245
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
600 ) -> jid.JID:
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
601 """Return unique name for a room, avoiding collision
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
602
4245
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
603 @param client: Client instance.
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
604 @param muc_service: leave empty string to use the default service
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
605 @param prefix: prefix to use in room name.
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
606 @return: unique room bare JID
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
607 """
4245
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
608 room_name = f"{prefix}{shortuuid.uuid()}"
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
609 if muc_service is None:
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
610 try:
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
611 muc_service = client.muc_service
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
612 except AttributeError:
4245
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
613 raise exceptions.NotReady(
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
614 "Main server MUC service has not been checked yet"
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
615 )
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
616 if muc_service is None:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 950
diff changeset
617 log.warning(_("No MUC service found on main server"))
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
618 raise exceptions.FeatureNotFound
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
619
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
620 muc_service = muc_service.userhost()
4245
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
621 return jid.JID(f"{room_name}@{muc_service}")
319
5bb1cfc105d0 plugin xep-0045: misc improvments
Goffi <goffi@goffi.org>
parents: 291
diff changeset
622
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
623 def get_default_muc(self):
1407
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
624 """Return the default MUC.
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
625
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
626 @return: unicode
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
627 """
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
628 return self.host.memory.config_get(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
629 CONFIG_SECTION, "default_muc", default_conf["default_muc"]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
630 )
1407
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
631
4117
d861ad696797 plugin XEP-0045: fix name conflict in errback
Goffi <goffi@goffi.org>
parents: 4083
diff changeset
632 def _bridge_join_eb(self, failure_, client):
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
633 failure_.trap(AlreadyJoined)
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
634 room = failure_.value.room
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
635 return [True] + self._get_room_joined_args(room, client.profile)
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
636
2028
70bd7b242a9e plugin XEP-0045: fixed options parameter handling in bridge callback
Goffi <goffi@goffi.org>
parents: 2021
diff changeset
637 def _join(self, room_jid_s, nick, options, profile_key=C.PROF_KEY_NONE):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
638 """join method used by bridge
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
639
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
640 @return (tuple): already_joined boolean + room joined arguments (see [_get_room_joined_args])
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
641 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
642 client = self.host.get_client(profile_key)
1356
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
643 if room_jid_s:
1989
757c512fe06c plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents: 1986
diff changeset
644 muc_service = client.muc_service
1356
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
645 try:
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
646 room_jid = jid.JID(room_jid_s)
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
647 except (RuntimeError, jid.InvalidFormat, AttributeError):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
648 return defer.fail(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
649 jid.InvalidFormat(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
650 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
651 "Invalid room identifier: {room_id}'. Please give a room short or full identifier like 'room' or 'room@{muc_service}'."
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
652 ).format(room_id=room_jid_s, muc_service=str(muc_service))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
653 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
654 )
1384
73f8582c7c99 plugins XEP-0045, XEP-0249: allow to join / invite without specifying the JID's host part (use client's values)
souliane <souliane@mailoo.org>
parents: 1381
diff changeset
655 if not room_jid.user:
73f8582c7c99 plugins XEP-0045, XEP-0249: allow to join / invite without specifying the JID's host part (use client's values)
souliane <souliane@mailoo.org>
parents: 1381
diff changeset
656 room_jid.user, room_jid.host = room_jid.host, muc_service
1356
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
657 else:
4083
2ea567afc0cf plugin XEP-0045: fix calls to `join`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
658 room_jid = self.get_unique_name(client)
743
5a131930348d plugin XEP-0045: remove redondant errback from _join
souliane <souliane@mailoo.org>
parents: 742
diff changeset
659 # TODO: error management + signal in bridge
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
660 d = defer.ensureDeferred(self.join(client, room_jid, nick, options or None))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
661
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
662 d.addCallback(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
663 lambda room: [False] + self._get_room_joined_args(room, client.profile)
4083
2ea567afc0cf plugin XEP-0045: fix calls to `join`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
664 )
4117
d861ad696797 plugin XEP-0045: fix name conflict in errback
Goffi <goffi@goffi.org>
parents: 4083
diff changeset
665 d.addErrback(self._bridge_join_eb, client)
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
666 return d
505
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
667
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
668 async def join(
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
669 self,
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
670 client: SatXMPPEntity,
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
671 room_jid: jid.JID,
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
672 nick: Optional[str] = None,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
673 options: Optional[dict] = None,
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
674 ) -> Optional[muc.Room]:
1989
757c512fe06c plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents: 1986
diff changeset
675 if not nick:
757c512fe06c plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents: 1986
diff changeset
676 nick = client.jid.user
757c512fe06c plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents: 1986
diff changeset
677 if options is None:
757c512fe06c plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents: 1986
diff changeset
678 options = {}
1977
bdc6a5b07922 plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
679 if room_jid in client._muc_client.joined_rooms:
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
680 room = client._muc_client.joined_rooms[room_jid]
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
681 log.info(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
682 _("{profile} is already in room {room_jid}").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
683 profile=client.profile, room_jid=room_jid.userhost()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
684 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
685 )
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
686 raise AlreadyJoined(room)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
687 log.info(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
688 _("[{profile}] is joining room {room} with nick {nick}").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
689 profile=client.profile, room=room_jid.userhost(), nick=nick
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
690 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
691 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
692 self.host.bridge.muc_room_prepare_join(room_jid.userhost(), client.profile)
1977
bdc6a5b07922 plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
693
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
694 password = options.get("password")
1977
bdc6a5b07922 plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
695
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
696 try:
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
697 room = await client._muc_client.join(room_jid, nick, password)
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
698 except Exception as e:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
699 room = await utils.as_deferred(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
700 self._join_eb(failure.Failure(e), client, room_jid, nick, password)
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
701 )
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
702 else:
4245
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
703 room.on_joined_callbacks = []
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
704 room.on_left_callbacks = []
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
705 await defer.ensureDeferred(self._join_cb(room, client, room_jid, nick))
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
706 return room
1977
bdc6a5b07922 plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
707
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
708 def pop_rooms(self, client):
3008
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
709 """Remove rooms and return data needed to re-join them
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
710
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
711 This methods is to be called before a hot reconnection
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
712 @return (list[(jid.JID, unicode)]): arguments needed to re-join the rooms
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
713 This list can be used directly (unpacked) with self.join
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
714 """
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
715 args_list = []
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
716 for room in list(client._muc_client.joined_rooms.values()):
3008
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
717 client._muc_client._removeRoom(room.roomJID)
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
718 args_list.append((client, room.roomJID, room.nick))
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
719 return args_list
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
720
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
721 def _nick(self, room_jid_s, nick, profile_key=C.PROF_KEY_NONE):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
722 client = self.host.get_client(profile_key)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
723 return self.nick(client, jid.JID(room_jid_s), nick)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
724
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
725 def nick(self, client, room_jid, nick):
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
726 """Change nickname in a room"""
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
727 self.check_room_joined(client, room_jid)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
728 return client._muc_client.nick(room_jid, nick)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
729
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
730 def _leave(self, room_jid, profile_key):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
731 client = self.host.get_client(profile_key)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
732 return self.leave(client, jid.JID(room_jid))
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
733
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
734 def leave(self, client, room_jid):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
735 self.check_room_joined(client, room_jid)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
736 return client._muc_client.leave(room_jid)
505
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
737
2021
6c51e8f17c92 plugin XEP-0045: added bridge method to change subject
Goffi <goffi@goffi.org>
parents: 1992
diff changeset
738 def _subject(self, room_jid_s, new_subject, profile_key):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
739 client = self.host.get_client(profile_key)
2021
6c51e8f17c92 plugin XEP-0045: added bridge method to change subject
Goffi <goffi@goffi.org>
parents: 1992
diff changeset
740 return self.subject(client, jid.JID(room_jid_s), new_subject)
6c51e8f17c92 plugin XEP-0045: added bridge method to change subject
Goffi <goffi@goffi.org>
parents: 1992
diff changeset
741
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
742 def subject(self, client, room_jid, subject):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
743 self.check_room_joined(client, room_jid)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
744 return client._muc_client.subject(room_jid, subject)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
745
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
746 def get_handler(self, client):
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
747 # create a MUC client and associate it with profile' session
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
748 muc_client = client._muc_client = LiberviaMUCClient(self)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
749 return muc_client
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
750
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
751 def kick(self, client, nick, room_jid, options=None):
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents: 2613
diff changeset
752 """Kick a participant from the room
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents: 2613
diff changeset
753
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
754 @param nick (str): nick of the user to kick
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
755 @param room_jid_s (JID): jid of the room
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
756 @param options (dict): attribute with extra info (reason, password) as in #XEP-0045
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
757 """
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
758 if options is None:
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
759 options = {}
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
760 self.check_room_joined(client, room_jid)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
761 return client._muc_client.kick(room_jid, nick, reason=options.get("reason", None))
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
762
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
763 def ban(self, client, entity_jid, room_jid, options=None):
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
764 """Ban an entity from the room
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
765
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
766 @param entity_jid (JID): bare jid of the entity to be banned
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
767 @param room_jid (JID): jid of the room
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
768 @param options: attribute with extra info (reason, password) as in #XEP-0045
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
769 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
770 self.check_room_joined(client, room_jid)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
771 if options is None:
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
772 options = {}
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
773 assert not entity_jid.resource
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
774 assert not room_jid.resource
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
775 return client._muc_client.ban(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
776 room_jid, entity_jid, reason=options.get("reason", None)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
777 )
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
778
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
779 def affiliate(self, client, entity_jid, room_jid, options):
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
780 """Change the affiliation of an entity
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
781
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
782 @param entity_jid (JID): bare jid of the entity
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
783 @param room_jid_s (JID): jid of the room
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
784 @param options: attribute with extra info (reason, nick) as in #XEP-0045
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
785 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
786 self.check_room_joined(client, room_jid)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
787 assert not entity_jid.resource
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
788 assert not room_jid.resource
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
789 assert "affiliation" in options
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
790 # TODO: handles reason and nick
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
791 return client._muc_client.modifyAffiliationList(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
792 room_jid, [entity_jid], options["affiliation"]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
793 )
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
794
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
795 # Text commands #
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
796
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
797 def cmd_nick(self, client, mess_data):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
798 """change nickname
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
799
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
800 @command (group): new_nick
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
801 - new_nick: new nick to use
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
802 """
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
803 nick = mess_data["unparsed"].strip()
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
804 if nick:
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
805 room = mess_data["to"]
1977
bdc6a5b07922 plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
806 self.nick(client, room, nick)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
807
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
808 return False
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
809
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
810 def cmd_join(self, client, mess_data):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
811 """join a new room
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
812
1381
0d12d4e32664 plugin XEP-0045: /join text command can be used in all contexts, not only group
Goffi <goffi@goffi.org>
parents: 1371
diff changeset
813 @command (all): JID
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
814 - JID: room to join (on the same service if full jid is not specified)
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
815 """
3544
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
816 room_raw = mess_data["unparsed"].strip()
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
817 if room_raw:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
818 if self.is_joined_room(client, mess_data["to"]):
3544
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
819 # we use the same service as the one from the room where the command has
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
820 # been entered if full jid is not entered
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
821 muc_service = mess_data["to"].host
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
822 nick = self.get_room_nick(client, mess_data["to"]) or client.jid.user
3544
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
823 else:
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
824 # the command has been entered in a one2one conversation, so we use
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
825 # our server MUC service as default service
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
826 muc_service = client.muc_service or ""
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
827 nick = client.jid.user
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
828 room_jid = self.text_cmds.get_room_jid(room_raw, muc_service)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
829 defer.ensureDeferred(self.join(client, room_jid, nick, {}))
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
830
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
831 return False
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
832
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
833 def cmd_leave(self, client, mess_data):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
834 """quit a room
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
835
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
836 @command (group): [ROOM_JID]
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
837 - ROOM_JID: jid of the room to live (current room if not specified)
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
838 """
3544
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
839 room_raw = mess_data["unparsed"].strip()
ae5f63e5ed2c plugin XEP-0045: fix `/join` text command
Goffi <goffi@goffi.org>
parents: 3543
diff changeset
840 if room_raw:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
841 room = self.text_cmds.get_room_jid(room_raw, mess_data["to"].host)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
842 else:
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
843 room = mess_data["to"]
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
844
1977
bdc6a5b07922 plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
845 self.leave(client, room)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
846
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
847 return False
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
848
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
849 def cmd_part(self, client, mess_data):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
850 """just a synonym of /leave
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
851
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
852 @command (group): [ROOM_JID]
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
853 - ROOM_JID: jid of the room to live (current room if not specified)
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
854 """
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
855 return self.cmd_leave(client, mess_data)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
856
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
857 def cmd_kick(self, client, mess_data):
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
858 """kick a room member
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
859
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
860 @command (group): ROOM_NICK
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
861 - ROOM_NICK: the nick of the person to kick
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
862 """
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
863 options = mess_data["unparsed"].strip().split()
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
864 try:
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
865 nick = options[0]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
866 assert self.is_nick_in_room(client, mess_data["to"], nick)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
867 except (IndexError, AssertionError):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
868 feedback = _("You must provide a member's nick to kick.")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
869 self.text_cmds.feed_back(client, feedback, mess_data)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
870 return False
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
871
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
872 reason = " ".join(options[1:]) if len(options) > 1 else None
3543
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
873
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
874 d = self.kick(client, nick, mess_data["to"], {"reason": reason})
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
875
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
876 def cb(__):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
877 feedback_msg = _("You have kicked {}").format(nick)
3543
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
878 if reason is not None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
879 feedback_msg += _(" for the following reason: {reason}").format(
3543
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
880 reason=reason
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
881 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
882 self.text_cmds.feed_back(client, feedback_msg, mess_data)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
883 return True
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
884
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
885 d.addCallback(cb)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
886 return d
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
887
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
888 def cmd_ban(self, client, mess_data):
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
889 """ban an entity from the room
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
890
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
891 @command (group): (JID) [reason]
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
892 - JID: the JID of the entity to ban
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
893 - reason: the reason why this entity is being banned
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
894 """
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
895 options = mess_data["unparsed"].strip().split()
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
896 try:
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
897 jid_s = options[0]
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
898 entity_jid = jid.JID(jid_s).userhostJID()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
899 assert entity_jid.user
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
900 assert entity_jid.host
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
901 except (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
902 RuntimeError,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
903 jid.InvalidFormat,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
904 AttributeError,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
905 IndexError,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
906 AssertionError,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
907 ):
3543
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
908 feedback = _(
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
909 "You must provide a valid JID to ban, like in '/ban contact@example.net'"
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
910 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
911 self.text_cmds.feed_back(client, feedback, mess_data)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
912 return False
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
913
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
914 reason = " ".join(options[1:]) if len(options) > 1 else None
3543
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
915
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
916 d = self.ban(client, entity_jid, mess_data["to"], {"reason": reason})
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
917
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
918 def cb(__):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
919 feedback_msg = _("You have banned {}").format(entity_jid)
3543
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
920 if reason is not None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
921 feedback_msg += _(" for the following reason: {reason}").format(
3543
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
922 reason=reason
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
923 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
924 self.text_cmds.feed_back(client, feedback_msg, mess_data)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
925 return True
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
926
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
927 d.addCallback(cb)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
928 return d
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
929
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
930 def cmd_affiliate(self, client, mess_data):
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
931 """affiliate an entity to the room
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
932
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
933 @command (group): (JID) [owner|admin|member|none|outcast]
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
934 - JID: the JID of the entity to affiliate
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
935 - owner: grant owner privileges
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
936 - admin: grant admin privileges
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
937 - member: grant member privileges
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
938 - none: reset entity privileges
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
939 - outcast: ban entity
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
940 """
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
941 options = mess_data["unparsed"].strip().split()
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
942 try:
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
943 jid_s = options[0]
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
944 entity_jid = jid.JID(jid_s).userhostJID()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
945 assert entity_jid.user
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
946 assert entity_jid.host
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
947 except (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
948 RuntimeError,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
949 jid.InvalidFormat,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
950 AttributeError,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
951 IndexError,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
952 AssertionError,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
953 ):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
954 feedback = _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
955 "You must provide a valid JID to affiliate, like in '/affiliate contact@example.net member'"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
956 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
957 self.text_cmds.feed_back(client, feedback, mess_data)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
958 return False
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
959
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
960 affiliation = options[1] if len(options) > 1 else "none"
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
961 if affiliation not in AFFILIATIONS:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
962 feedback = _("You must provide a valid affiliation: %s") % " ".join(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
963 AFFILIATIONS
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
964 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
965 self.text_cmds.feed_back(client, feedback, mess_data)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
966 return False
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
967
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
968 d = self.affiliate(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
969 client, entity_jid, mess_data["to"], {"affiliation": affiliation}
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
970 )
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
971
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
972 def cb(__):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
973 feedback_msg = _("New affiliation for {entity}: {affiliation}").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
974 entity=entity_jid, affiliation=affiliation
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
975 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
976 self.text_cmds.feed_back(client, feedback_msg, mess_data)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
977 return True
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
978
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
979 d.addCallback(cb)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
980 return d
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
981
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
982 def cmd_title(self, client, mess_data):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
983 """change room's subject
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
984
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
985 @command (group): title
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
986 - title: new room subject
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
987 """
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
988 subject = mess_data["unparsed"].strip()
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
989
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
990 if subject:
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
991 room = mess_data["to"]
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
992 self.subject(client, room, subject)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
993
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
994 return False
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
995
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
996 def cmd_topic(self, client, mess_data):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
997 """just a synonym of /title
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
998
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
999 @command (group): title
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
1000 - title: new room subject
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
1001 """
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1002 return self.cmd_title(client, mess_data)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
1003
1990
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1004 def cmd_list(self, client, mess_data):
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1005 """list available rooms in a muc server
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1006
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1007 @command (all): [MUC_SERVICE]
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1008 - MUC_SERVICE: service to request
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1009 empty value will request room's service for a room,
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1010 or user's server default MUC service in a one2one chat
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1011 """
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1012 unparsed = mess_data["unparsed"].strip()
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1013 try:
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1014 service = jid.JID(unparsed)
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1015 except RuntimeError:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1016 if mess_data["type"] == C.MESS_TYPE_GROUPCHAT:
1990
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1017 room_jid = mess_data["to"]
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1018 service = jid.JID(room_jid.host)
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1019 elif client.muc_service is not None:
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1020 service = client.muc_service
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1021 else:
3543
f19718296c20 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1022 msg = D_("No known default MUC service {unparsed}").format(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1023 unparsed=unparsed
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1024 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1025 self.text_cmds.feed_back(client, msg, mess_data)
1990
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1026 return False
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1027 except jid.InvalidFormat:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1028 msg = D_("{} is not a valid JID!".format(unparsed))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1029 self.text_cmds.feed_back(client, msg, mess_data)
1990
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1030 return False
2148
a543eda2c923 core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
1031 d = self.host.getDiscoItems(client, service)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1032 d.addCallback(self._show_list_ui, client, service)
1990
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1033
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1034 return False
dfbe0bb056dc plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents: 1989
diff changeset
1035
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1036 def _whois(self, client, whois_msg, mess_data, target_jid):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1037 """Add MUC user information to whois"""
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1038 if mess_data["type"] != "groupchat":
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1039 return
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
1040 if target_jid.userhostJID() not in client._muc_client.joined_rooms:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 950
diff changeset
1041 log.warning(_("This room has not been joined"))
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1042 return
1392
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
1043 if not target_jid.resource:
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
1044 return
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1045 user = client._muc_client.joined_rooms[target_jid.userhostJID()].getUser(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1046 target_jid.resource
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1047 )
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1048 whois_msg.append(_("Nickname: %s") % user.nick)
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1049 if user.entity:
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1050 whois_msg.append(_("Entity: %s") % user.entity)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1051 if user.affiliation != "none":
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1052 whois_msg.append(_("Affiliation: %s") % user.affiliation)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1053 if user.role != "none":
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1054 whois_msg.append(_("Role: %s") % user.role)
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1055 if user.status:
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1056 whois_msg.append(_("Status: %s") % user.status)
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1057 if user.show:
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1058 whois_msg.append(_("Show: %s") % user.show)
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1059
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1060 def presence_trigger(self, presence_elt, client):
3008
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
1061 # FIXME: should we add a privacy parameters in settings to activate before
c8c68a3b0a79 plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
1062 # broadcasting the presence to all MUC rooms ?
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
1063 muc_client = client._muc_client
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1064 for room_jid, room in muc_client.joined_rooms.items():
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1065 elt = xml_tools.element_copy(presence_elt)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1066 elt["to"] = room_jid.userhost() + "/" + room.nick
1239
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
1067 client.presence.send(elt)
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
1068 return True
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
1069
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1070 def presence_received_trigger(self, client, entity, show, priority, statuses):
2822
5284be4c601b plugin XEP-0045: cache presences if they are received before the room is fully joined:
Goffi <goffi@goffi.org>
parents: 2815
diff changeset
1071 entity_bare = entity.userhostJID()
5284be4c601b plugin XEP-0045: cache presences if they are received before the room is fully joined:
Goffi <goffi@goffi.org>
parents: 2815
diff changeset
1072 muc_client = client._muc_client
5284be4c601b plugin XEP-0045: cache presences if they are received before the room is fully joined:
Goffi <goffi@goffi.org>
parents: 2815
diff changeset
1073 if entity_bare in muc_client.joined_rooms:
2991
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1074 # presence is already handled in (un)availableReceived
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1075 return False
2822
5284be4c601b plugin XEP-0045: cache presences if they are received before the room is fully joined:
Goffi <goffi@goffi.org>
parents: 2815
diff changeset
1076 return True
5284be4c601b plugin XEP-0045: cache presences if they are received before the room is fully joined:
Goffi <goffi@goffi.org>
parents: 2815
diff changeset
1077
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1078
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1079 @implementer(iwokkel.IDisco)
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1080 class LiberviaMUCClient(muc.MUCClient):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1081
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1082 def __init__(self, plugin_parent):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1083 self.plugin_parent = plugin_parent
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1084 muc.MUCClient.__init__(self)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1085 self._changing_nicks = set() # used to keep trace of who is changing nick,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1086 # and to discard userJoinedRoom signal in this case
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1087 print("init SatMUCClient OK")
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
1088
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
1089 @property
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
1090 def joined_rooms(self):
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
1091 return self._rooms
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
1092
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1093 @property
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1094 def host(self):
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1095 return self.plugin_parent.host
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1096
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1097 @property
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1098 def client(self):
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1099 return self.parent
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1100
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1101 @property
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1102 def _mam(self):
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1103 return self.plugin_parent._mam
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1104
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1105 @property
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1106 def _si(self):
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1107 return self.plugin_parent._si
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1108
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1109 def change_room_state(self, room, new_state):
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1110 """Check that room is in expected state, and change it
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1111
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1112 @param new_state: one of ROOM_STATE_*
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1113 """
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1114 new_state_idx = ROOM_STATES.index(new_state)
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1115 if new_state_idx == -1:
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1116 raise exceptions.InternalError("unknown room state")
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1117 if new_state_idx < 1:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1118 raise exceptions.InternalError(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1119 "unexpected new room state ({room}): {state}".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1120 room=room.userhost(), state=new_state
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1121 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1122 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1123 expected_state = ROOM_STATES[new_state_idx - 1]
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1124 if room.state != expected_state:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1125 log.error(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1126 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1127 "room {room} is not in expected state: room is in state {current_state} "
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1128 "while we were expecting {expected_state}"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1129 ).format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1130 room=room.roomJID.userhost(),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1131 current_state=room.state,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1132 expected_state=expected_state,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1133 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1134 )
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1135 room.state = new_state
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1136
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1137 def _addRoom(self, room):
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1138 super(LiberviaMUCClient, self)._addRoom(room)
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
1139 room._roster_ok = False # True when occupants list has been fully received
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1140 room.state = ROOM_STATE_OCCUPANTS
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
1141 # FIXME: check if history_d is not redundant with fully_joined
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2058
diff changeset
1142 room.fully_joined = defer.Deferred() # called when everything is OK
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1143 # cache data until room is ready
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1144 # list of elements which will be re-injected in stream
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1145 room._cache = []
2822
5284be4c601b plugin XEP-0045: cache presences if they are received before the room is fully joined:
Goffi <goffi@goffi.org>
parents: 2815
diff changeset
1146 # we only need to keep last presence status for each jid, so a dict is suitable
5284be4c601b plugin XEP-0045: cache presences if they are received before the room is fully joined:
Goffi <goffi@goffi.org>
parents: 2815
diff changeset
1147 room._cache_presence = {}
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1148
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1149 async def _join_legacy(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1150 self, client: SatXMPPEntity, room_jid: jid.JID, nick: str, password: Optional[str]
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1151 ) -> muc.Room:
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1152 """Join room an retrieve history with legacy method"""
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1153 mess_data_list = await self.host.memory.history_get(
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1154 room_jid,
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1155 client.jid.userhostJID(),
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1156 limit=1,
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1157 between=True,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1158 profile=client.profile,
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1159 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1160 if mess_data_list:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1161 timestamp = mess_data_list[0][1]
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1162 # we use seconds since last message to get backlog without duplicates
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1163 # and we remove 1 second to avoid getting the last message again
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1164 seconds = int(time.time() - timestamp) - 1
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1165 else:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1166 seconds = None
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1167
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1168 room = await super(LiberviaMUCClient, self).join(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1169 room_jid, nick, muc.HistoryOptions(seconds=seconds), password
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1170 )
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1171 # used to send bridge signal once backlog are written in history
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1172 room._history_type = HISTORY_LEGACY
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1173 room._history_d = defer.Deferred()
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1174 room._history_d.callback(None)
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1175 return room
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1176
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1177 async def _get_mam_history(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1178 self, client: SatXMPPEntity, room: muc.Room, room_jid: jid.JID
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1179 ) -> None:
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1180 """Retrieve history for rooms handling MAM"""
3060
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
1181 history_d = room._history_d = defer.Deferred()
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
1182 # we trigger now the deferred so all callback are processed as soon as possible
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
1183 # and in order
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
1184 history_d.callback(None)
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1185
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1186 last_mess = await self.host.memory.history_get(
2826
177f11163ed0 plugin XEP-0045: fixed message type filtering when getting last stanza_id to retrieve history with MAM
Goffi <goffi@goffi.org>
parents: 2822
diff changeset
1187 room_jid,
177f11163ed0 plugin XEP-0045: fixed message type filtering when getting last stanza_id to retrieve history with MAM
Goffi <goffi@goffi.org>
parents: 2822
diff changeset
1188 None,
177f11163ed0 plugin XEP-0045: fixed message type filtering when getting last stanza_id to retrieve history with MAM
Goffi <goffi@goffi.org>
parents: 2822
diff changeset
1189 limit=1,
177f11163ed0 plugin XEP-0045: fixed message type filtering when getting last stanza_id to retrieve history with MAM
Goffi <goffi@goffi.org>
parents: 2822
diff changeset
1190 between=False,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1191 filters={"types": C.MESS_TYPE_GROUPCHAT, "last_stanza_id": True},
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1192 profile=client.profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1193 )
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1194 if last_mess:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1195 stanza_id = last_mess[0][-1]["stanza_id"]
3060
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
1196 rsm_req = rsm.RSMRequest(max_=20, after=stanza_id)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1197 no_loop = False
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1198 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1199 log.info(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1200 "We have no MAM archive for room {room_jid}.".format(room_jid=room_jid)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1201 )
2718
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1202 # we don't want the whole archive if we have no archive yet
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1203 # as it can be huge
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1204 rsm_req = rsm.RSMRequest(max_=50, before="")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1205 no_loop = True
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1206
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1207 mam_req = mam.MAMRequest(rsm_=rsm_req)
2718
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1208 complete = False
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1209 count = 0
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1210 while not complete:
3080
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
1211 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1212 mam_data = await self._mam.get_archives(client, mam_req, service=room_jid)
3080
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
1213 except xmpp_error.StanzaError as e:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1214 if last_mess and e.condition == "item-not-found":
4155
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
1215 log.warning(
3080
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
1216 f"requested item (with id {stanza_id!r}) can't be found in "
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
1217 f"history of {room_jid}, history has probably been purged on "
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1218 f"server."
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1219 )
3080
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
1220 # we get last items like for a new room
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1221 rsm_req = rsm.RSMRequest(max_=50, before="")
3080
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
1222 mam_req = mam.MAMRequest(rsm_=rsm_req)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1223 no_loop = True
3080
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
1224 continue
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
1225 else:
16925f494820 plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents: 3060
diff changeset
1226 raise e
2718
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1227 elt_list, rsm_response, mam_response = mam_data
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1228 complete = True if no_loop else mam_response["complete"]
2718
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1229 # we update MAM request for next iteration
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1230 mam_req.rsm.after = rsm_response.last
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1231
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1232 if not elt_list:
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1233 break
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1234 else:
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1235 count += len(elt_list)
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1236
2718
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1237 for mess_elt in elt_list:
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1238 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1239 fwd_message_elt = self._mam.get_message_from_result(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1240 client, mess_elt, mam_req, service=room_jid
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1241 )
2718
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1242 except exceptions.DataError:
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1243 continue
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1244 if fwd_message_elt.getAttribute("to"):
2718
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1245 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1246 'Forwarded message element has a "to" attribute while it is '
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1247 "forbidden by specifications"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1248 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1249 fwd_message_elt["to"] = client.jid.full()
4155
453e53dfc50e plugin XEP-0045: user normal workflow for history + `get_room_user_jid` method:
Goffi <goffi@goffi.org>
parents: 4117
diff changeset
1250 client.messageProt.onMessage(fwd_message_elt)
2718
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1251 client._muc_client._onGroupChat(fwd_message_elt)
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1252
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2715
diff changeset
1253 if not count:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1254 log.info(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1255 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1256 "No message received while offline in {room_jid}".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1257 room_jid=room_jid
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1258 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1259 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1260 )
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1261 else:
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1262 log.info(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1263 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1264 "We have received {num_mess} message(s) in {room_jid} while "
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1265 "offline."
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1266 ).format(num_mess=count, room_jid=room_jid)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1267 )
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1268
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1269 # for legacy history, the following steps are done in receivedSubject but for MAM
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1270 # the order is different (we have to join then get MAM archive, so subject
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1271 # is received before archive), so we change state and add the callbacks here.
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1272 self.change_room_state(room, ROOM_STATE_LIVE)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1273 history_d.addCallbacks(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1274 self._history_cb, self._history_eb, [room], errbackArgs=[room]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1275 )
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1276
3060
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
1277 # we wait for all callbacks to be processed
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1278 await history_d
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1279
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1280 async def _join_mam(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1281 self, client: SatXMPPEntity, room_jid: jid.JID, nick: str, password: Optional[str]
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1282 ) -> muc.Room:
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1283 """Join room and retrieve history using MAM"""
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1284 room = await super(LiberviaMUCClient, self).join(
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1285 # we don't want any history from room as we'll get it with MAM
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1286 room_jid,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1287 nick,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1288 muc.HistoryOptions(maxStanzas=0),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1289 password=password,
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1290 )
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1291 room._history_type = HISTORY_MAM
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1292 # MAM history retrieval can be very long, and doesn't need to be sync, so we don't
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1293 # wait for it
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1294 defer.ensureDeferred(self._get_mam_history(client, room, room_jid))
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1295 room.fully_joined.callback(room)
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1296
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1297 return room
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1298
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1299 async def join(self, room_jid, nick, password=None):
2827
9a3b99acad91 plugin XEP-0045: fixed item-not-found exception when creating a room:
Goffi <goffi@goffi.org>
parents: 2826
diff changeset
1300 room_service = jid.JID(room_jid.host)
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1301 has_mam = await self.host.hasFeature(self.client, mam.NS_MAM, room_service)
2728
1b11da85492c plugin XEP-0045: fixed bad MAM detection on join
Goffi <goffi@goffi.org>
parents: 2724
diff changeset
1302 if not self._mam or not has_mam:
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1303 return await self._join_legacy(self.client, room_jid, nick, password)
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1304 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1305 return await self._join_mam(self.client, room_jid, nick, password)
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1306
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1307 ## presence/roster ##
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1308
1891
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1309 def availableReceived(self, presence):
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1310 """
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1311 Available presence was received.
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1312 """
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1313 # XXX: we override MUCClient.availableReceived to fix bugs
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1314 # (affiliation and role are not set)
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1315
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1316 room, user = self._getRoomUser(presence)
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1317
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1318 if room is None:
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1319 return
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1320
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1321 if user is None:
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1322 nick = presence.sender.resource
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1323 if not nick:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1324 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1325 _("missing nick in presence: {xml}").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1326 xml=presence.toElement().toXml()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1327 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1328 )
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1329 return
1891
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1330 user = muc.User(nick, presence.entity)
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1331
3101
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3086
diff changeset
1332 # we want to keep statuses with room
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3086
diff changeset
1333 # XXX: presence if broadcasted, and we won't have status code
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3086
diff changeset
1334 # like 110 (REALJID_PUBLIC) after first <presence/> received
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3086
diff changeset
1335 # so we keep only the initial <presence> (with SELF_PRESENCE),
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3086
diff changeset
1336 # thus we check if attribute already exists
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1337 if (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1338 not hasattr(room, "statuses")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1339 and muc.STATUS_CODE.SELF_PRESENCE in presence.mucStatuses
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1340 ):
3101
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3086
diff changeset
1341 room.statuses = presence.mucStatuses
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3086
diff changeset
1342
1891
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1343 # Update user data
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1344 user.role = presence.role
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1345 user.affiliation = presence.affiliation
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1346 user.status = presence.status
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1347 user.show = presence.show
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1348
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1349 if room.inRoster(user):
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1350 self.userUpdatedStatus(room, user, presence.show, presence.status)
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1351 else:
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1352 room.addUser(user)
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
1353 self.userJoinedRoom(room, user)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1354
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1355 def unavailableReceived(self, presence):
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
1356 # XXX: we override this method to manage nickname change
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1357 """
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1358 Unavailable presence was received.
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1359
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1360 If this was received from a MUC room occupant JID, that occupant has
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1361 left the room.
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1362 """
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1363 room, user = self._getRoomUser(presence)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1364
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1365 if room is None or user is None:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1366 return
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1367
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1368 room.removeUser(user)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1369
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1370 if muc.STATUS_CODE.NEW_NICK in presence.mucStatuses:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1371 self._changing_nicks.add(presence.nick)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1372 self.user_changed_nick(room, user, presence.nick)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1373 else:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1374 self._changing_nicks.discard(presence.nick)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1375 self.userLeftRoom(room, user)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1376
74
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
1377 def userJoinedRoom(self, room, user):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1378 if user.nick == room.nick:
2994
94708a7d3ecf core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents: 2991
diff changeset
1379 # we have received our own nick,
94708a7d3ecf core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents: 2991
diff changeset
1380 # this mean that the full room roster was received
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1381 self.change_room_state(room, ROOM_STATE_SELF_PRESENCE)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1382 log.debug(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1383 "room {room} joined with nick {nick}".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1384 room=room.occupantJID.userhost(), nick=user.nick
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1385 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1386 )
2994
94708a7d3ecf core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents: 2991
diff changeset
1387 # we set type so we don't have to use a deferred
94708a7d3ecf core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents: 2991
diff changeset
1388 # with disco to check entity type
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1389 self.host.memory.update_entity_data(
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
1390 self.client, room.roomJID, C.ENTITY_TYPE, C.ENTITY_TYPE_MUC
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
1391 )
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1392 elif room.state not in (ROOM_STATE_OCCUPANTS, ROOM_STATE_LIVE):
2994
94708a7d3ecf core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents: 2991
diff changeset
1393 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1394 "Received user presence data in a room before its initialisation "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1395 "(current state: {state}),"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1396 "this is not standard! Ignoring it: {room} ({nick})".format(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1397 state=room.state, room=room.roomJID.userhost(), nick=user.nick
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1398 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1399 )
1984
de4fac507dc4 xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents: 1977
diff changeset
1400 return
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1401 else:
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1402 if not room.fully_joined.called:
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1403 return
4245
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
1404 for cb in room.on_joined_callbacks:
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
1405 defer.ensureDeferred(cb(room, user))
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1406 try:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1407 self._changing_nicks.remove(user.nick)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1408 except KeyError:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1409 # this is a new user
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1410 log.debug(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1411 _("user {nick} has joined room {room_id}").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1412 nick=user.nick, room_id=room.occupantJID.userhost()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1413 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1414 )
2994
94708a7d3ecf core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents: 2991
diff changeset
1415 if not self.host.trigger.point(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1416 "MUC user joined", room, user, self.client.profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1417 ):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1418 return
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1419
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1420 extra = {
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1421 "info_type": ROOM_USER_JOINED,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1422 "user_affiliation": user.affiliation,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1423 "user_role": user.role,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1424 "user_nick": user.nick,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1425 }
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1426 if user.entity is not None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1427 extra["user_entity"] = user.entity.full()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1428 mess_data = { # dict is similar to the one used in client.onMessage
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1429 "from": room.roomJID,
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1430 "to": self.client.jid,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1431 "uid": str(uuid.uuid4()),
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1432 "message": {"": D_("=> {} has joined the room").format(user.nick)},
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1433 "subject": {},
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1434 "type": C.MESS_TYPE_INFO,
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1435 "extra": extra,
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1436 "timestamp": time.time(),
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1437 }
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1438 # FIXME: we disable presence in history as it's taking a lot of space
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1439 # while not indispensable. In the future an option may allow
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1440 # to re-enable it
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1441 # self.client.message_add_to_history(mess_data)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1442 self.client.message_send_to_bridge(mess_data)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1443
74
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
1444 def userLeftRoom(self, room, user):
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1445 if not self.host.trigger.point("MUC user left", room, user, self.client.profile):
715
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
1446 return
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1447 if user.nick == room.nick:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1448 # we left the room
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1449 room_jid_s = room.roomJID.userhost()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1450 log.info(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1451 _("Room ({room}) left ({profile})").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1452 room=room_jid_s, profile=self.client.profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1453 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1454 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1455 self.host.memory.del_entity_cache(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1456 room.roomJID, profile_key=self.client.profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1457 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1458 self.host.bridge.muc_room_left(room.roomJID.userhost(), self.client.profile)
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1459 elif room.state != ROOM_STATE_LIVE:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1460 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1461 "Received user presence data in a room before its initialisation (current state: {state}),"
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1462 "this is not standard! Ignoring it: {room} ({nick})".format(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1463 state=room.state, room=room.roomJID.userhost(), nick=user.nick
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1464 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1465 )
1984
de4fac507dc4 xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents: 1977
diff changeset
1466 return
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1467 else:
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1468 if not room.fully_joined.called:
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1469 return
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1470 log.debug(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1471 _("user {nick} left room {room_id}").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1472 nick=user.nick, room_id=room.occupantJID.userhost()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1473 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1474 )
4245
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
1475 for cb in room.on_left_callbacks:
a7d4007a8fa5 plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents: 4196
diff changeset
1476 defer.ensureDeferred(cb(room, user))
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1477 extra = {
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1478 "info_type": ROOM_USER_LEFT,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1479 "user_affiliation": user.affiliation,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1480 "user_role": user.role,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1481 "user_nick": user.nick,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1482 }
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1483 if user.entity is not None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1484 extra["user_entity"] = user.entity.full()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1485 mess_data = { # dict is similar to the one used in client.onMessage
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1486 "from": room.roomJID,
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1487 "to": self.client.jid,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1488 "uid": str(uuid.uuid4()),
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1489 "message": {"": D_("<= {} has left the room").format(user.nick)},
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1490 "subject": {},
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1491 "type": C.MESS_TYPE_INFO,
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1492 "extra": extra,
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1493 "timestamp": time.time(),
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1494 }
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1495 # FIXME: disable history, see userJoinRoom comment
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1496 # self.client.message_add_to_history(mess_data)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1497 self.client.message_send_to_bridge(mess_data)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1498
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1499 def user_changed_nick(self, room, user, new_nick):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1500 self.host.bridge.muc_room_user_changed_nick(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1501 room.roomJID.userhost(), user.nick, new_nick, self.client.profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1502 )
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1503
77
1ae680f9682e wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents: 76
diff changeset
1504 def userUpdatedStatus(self, room, user, show, status):
2991
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1505 entity = jid.JID(tuple=(room.roomJID.user, room.roomJID.host, user.nick))
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1506 if hasattr(room, "_cache_presence"):
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1507 # room has a cache for presence, meaning it has not been fully
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1508 # joined yet. So we put presence in cache, and stop workflow.
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1509 # Or delete current presence and continue workflow if it's an
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1510 # "unavailable" presence
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1511 cache = room._cache_presence
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1512 cache[entity] = {
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1513 "room": room,
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1514 "user": user,
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1515 "show": show,
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1516 "status": status,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1517 }
2991
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1518 return
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1519 statuses = {C.PRESENCE_STATUSES_DEFAULT: status or ""}
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1520 self.host.bridge.presence_update(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1521 entity.full(), show or "", 0, statuses, self.client.profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1522 )
77
1ae680f9682e wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents: 76
diff changeset
1523
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1524 ## messages ##
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1525
1256
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
1526 def receivedGroupChat(self, room, user, body):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1527 log.debug(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1528 "receivedGroupChat: room=%s user=%s body=%s"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1529 % (room.roomJID.full(), user, body)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1530 )
1256
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
1531
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1532 ## subject ##
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1533
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1534 def groupChatReceived(self, message):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1535 """
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1536 A group chat message has been received from a MUC room.
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1537
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1538 There are a few event methods that may get called here.
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1539 L{receivedGroupChat}, L{receivedSubject} or L{receivedHistory}.
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1540 """
3060
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
1541 # We override this method to fix subject handling (empty strings were discarded)
730bbed77a89 plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
1542 # FIXME: remove this once fixed upstream
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1543 room, user = self._getRoomUser(message)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1544
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1545 if room is None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1546 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1547 "No room found for message: {message}".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1548 message=message.toElement().toXml()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1549 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1550 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1551 return
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1552
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1553 if message.subject is not None:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1554 self.receivedSubject(room, user, message.subject)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1555 elif message.delay is None:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1556 self.receivedGroupChat(room, user, message)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1557
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1558 def subject(self, room, subject):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1559 return muc.MUCClientProtocol.subject(self, room, subject)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1560
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1561 def _history_cb(self, __, room):
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1562 """Called when history have been written to database and subject is received
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1563
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1564 this method will finish joining by:
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1565 - sending message to bridge
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1566 - calling fully_joined deferred (for legacy history)
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1567 - sending stanza put in cache
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1568 - cleaning variables not needed anymore
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1569 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1570 args = self.plugin_parent._get_room_joined_args(room, self.client.profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1571 self.host.bridge.muc_room_joined(*args)
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1572 if room._history_type == HISTORY_LEGACY:
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
1573 room.fully_joined.callback(room)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1574 del room._history_d
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1575 del room._history_type
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1576 cache = room._cache
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1577 del room._cache
2822
5284be4c601b plugin XEP-0045: cache presences if they are received before the room is fully joined:
Goffi <goffi@goffi.org>
parents: 2815
diff changeset
1578 cache_presence = room._cache_presence
5284be4c601b plugin XEP-0045: cache presences if they are received before the room is fully joined:
Goffi <goffi@goffi.org>
parents: 2815
diff changeset
1579 del room._cache_presence
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1580 for elem in cache:
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1581 self.client.xmlstream.dispatch(elem)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1582 for presence_data in cache_presence.values():
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1583 if not presence_data["show"] and not presence_data["status"]:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1584 # occupants are already sent in muc_room_joined, so if we don't have
2991
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1585 # extra information like show or statuses, we can discard the signal
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1586 continue
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1587 else:
f4590ca2acff plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents: 2990
diff changeset
1588 self.userUpdatedStatus(**presence_data)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1589
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1590 def _history_eb(self, failure_, room):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3015
diff changeset
1591 log.error("Error while managing history: {}".format(failure_))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1592 self._history_cb(None, room)
1256
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
1593
405
10b4f577d0c0 MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents: 372
diff changeset
1594 def receivedSubject(self, room, user, subject):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1595 # when subject is received, we know that we have whole roster and history
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1596 # cf. http://xmpp.org/extensions/xep-0045.html#enter-subject
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1597 room.subject = subject # FIXME: subject doesn't handle xml:lang
2581
395a3d1c2888 plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1598 if room.state != ROOM_STATE_LIVE:
2715
b35c84ea73cf plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents: 2689
diff changeset
1599 if room._history_type == HISTORY_LEGACY:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
1600 self.change_room_state(room, ROOM_STATE_LIVE)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1601 room._history_d.addCallbacks(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1602 self._history_cb, self._history_eb, [room], errbackArgs=[room]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1603 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1604 else:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1605 # the subject has been changed
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1606 log.debug(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1607 _("New subject for room ({room_id}): {subject}").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1608 room_id=room.roomJID.full(), subject=subject
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1609 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1610 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1611 self.host.bridge.muc_room_new_subject(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1612 room.roomJID.userhost(), subject, self.client.profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1613 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1614
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1615 ## disco ##
1466
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
1616
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1617 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
1466
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
1618 return [disco.DiscoFeature(NS_MUC)]
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
1619
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4245
diff changeset
1620 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
1466
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
1621 # TODO: manage room queries ? Bad for privacy, must be disabled by default
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
1622 # see XEP-0045 § 6.7
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
1623 return []