Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0045.py @ 3479:be6d91572633
date update
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 19 Mar 2021 15:45:14 +0100 |
parents | 6cf4bd6972c2 |
children | 888109774673 f19718296c20 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
72 | 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 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
72 | 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 | 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 | 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 | 19 |
1068
1513511a0586
plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
20 from sat.core.i18n import _, D_ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
21 from sat.core.constants import Const as C |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
950
diff
changeset
|
22 from sat.core.log import getLogger |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
23 from twisted.internet import defer |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
24 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
|
25 from twisted.words.protocols.jabber import error as xmpp_error |
1986
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
26 from twisted.python import failure |
505
2402668b5d05
plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents:
488
diff
changeset
|
27 |
2402668b5d05
plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents:
488
diff
changeset
|
28 from sat.core import exceptions |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
29 from sat.memory import memory |
505
2402668b5d05
plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents:
488
diff
changeset
|
30 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
31 import time |
319 | 32 import uuid |
72 | 33 |
1466
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
34 from wokkel import muc, disco, iwokkel |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
35 from sat.tools import xml_tools |
72 | 36 |
3028 | 37 from zope.interface import implementer |
1466
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
38 |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
39 # XXX: mam and rsm come from sat_tmp.wokkel |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
40 from wokkel import rsm |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
41 from wokkel import mam |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
42 |
72 | 43 |
3080
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
44 log = getLogger(__name__) |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
45 |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
46 |
72 | 47 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
48 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
|
49 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
|
50 C.PI_TYPE: "XEP", |
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 | 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", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
56 C.PI_DESCRIPTION: _("""Implementation of Multi-User Chat""") |
72 | 57 } |
58 | |
1466
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
59 NS_MUC = 'http://jabber.org/protocol/muc' |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
60 AFFILIATIONS = ('owner', 'admin', 'member', 'none', 'outcast') |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
61 ROOM_USER_JOINED = 'ROOM_USER_JOINED' |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
62 ROOM_USER_LEFT = 'ROOM_USER_LEFT' |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
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 | 68 HISTORY_LEGACY = "legacy" |
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 |
3028 | 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 |
3028 | 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 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
84 class XEP_0045(object): |
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 | 87 |
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 | 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() |
3060
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
92 # return same arguments as mucRoomJoined + a boolean set to True is the room was |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
93 # already joined (first argument) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
94 host.bridge.addMethod( |
3101
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
95 "mucJoin", ".plugin", in_sign='ssa{ss}s', out_sign='(bsa{sa{ss}}ssass)', |
3060
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
96 method=self._join, async_=True) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
97 host.bridge.addMethod( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
98 "mucNick", ".plugin", in_sign='sss', out_sign='', method=self._nick) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
99 host.bridge.addMethod( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
100 "mucNickGet", ".plugin", in_sign='ss', out_sign='s', method=self._getRoomNick) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
101 host.bridge.addMethod( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
102 "mucLeave", ".plugin", in_sign='ss', out_sign='', method=self._leave, |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
103 async_=True) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
104 host.bridge.addMethod( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
105 "mucOccupantsGet", ".plugin", in_sign='ss', out_sign='a{sa{ss}}', |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
106 method=self._getRoomOccupants) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
107 host.bridge.addMethod( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
108 "mucSubject", ".plugin", in_sign='sss', out_sign='', method=self._subject) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
109 host.bridge.addMethod( |
3101
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
110 "mucGetRoomsJoined", ".plugin", in_sign='s', out_sign='a(sa{sa{ss}}ssas)', |
3060
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
111 method=self._getRoomsJoined) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
112 host.bridge.addMethod( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
113 "mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
114 method=self._getUniqueName) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
115 host.bridge.addMethod( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
116 "mucConfigureRoom", ".plugin", in_sign='ss', out_sign='s', |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
117 method=self._configureRoom, async_=True) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
118 host.bridge.addMethod( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
119 "mucGetDefaultService", ".plugin", in_sign='', out_sign='s', |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
120 method=self.getDefaultMUC) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
121 host.bridge.addMethod( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
122 "mucGetService", ".plugin", in_sign='ss', out_sign='s', |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
123 method=self._getMUCService, async_=True) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
124 # 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
|
125 # (room is prepared, history is getting retrieved) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
126 # args: room_jid, profile |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
127 host.bridge.addSignal( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
128 "mucRoomPrepareJoin", ".plugin", signature='ss') |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
129 # args: room_jid, occupants, user_nick, subject, profile |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
130 host.bridge.addSignal( |
3101
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
131 "mucRoomJoined", ".plugin", signature='sa{sa{ss}}ssass') |
3060
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
132 # args: room_jid, profile |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
133 host.bridge.addSignal( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
134 "mucRoomLeft", ".plugin", signature='ss') |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
135 # args: room_jid, old_nick, new_nick, profile |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
136 host.bridge.addSignal( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
137 "mucRoomUserChangedNick", ".plugin", signature='ssss') |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
138 # args: room_jid, subject, profile |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
139 host.bridge.addSignal( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
140 "mucRoomNewSubject", ".plugin", signature='sss') |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
141 self.__submit_conf_id = host.registerCallback( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
142 self._submitConfiguration, with_data=True) |
1990
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
143 self._room_join_id = host.registerCallback(self._UIRoomJoinCb, with_data=True) |
3060
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
144 host.importMenu( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
145 (D_("MUC"), D_("configure")), self._configureRoomMenu, security_limit=0, |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
146 help_string=D_("Configure Multi-User Chat room"), type_=C.MENU_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
|
147 try: |
1992
d5befe7253aa
plugin XEP-0045: fixed typo in text commands
Goffi <goffi@goffi.org>
parents:
1990
diff
changeset
|
148 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
|
149 except KeyError: |
3028 | 150 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
|
151 else: |
1992
d5befe7253aa
plugin XEP-0045: fixed typo in text commands
Goffi <goffi@goffi.org>
parents:
1990
diff
changeset
|
152 self.text_cmds.registerTextCommands(self) |
d5befe7253aa
plugin XEP-0045: fixed typo in text commands
Goffi <goffi@goffi.org>
parents:
1990
diff
changeset
|
153 self.text_cmds.addWhoIsCb(self._whois, 100) |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
154 |
3028 | 155 self._mam = self.host.plugins.get("XEP-0313") |
156 self._si = self.host.plugins["XEP-0359"] | |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
157 |
1239
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
158 host.trigger.add("presence_available", self.presenceTrigger) |
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
|
159 host.trigger.add("presence_received", self.presenceReceivedTrigger) |
3172
dcebc585c29f
core: renamed "MessageReceived" trigger to "messageReceived" for consistency.
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
160 host.trigger.add("messageReceived", self.messageReceivedTrigger, priority=1000000) |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
161 host.trigger.add("message_parse", self._message_parseTrigger) |
1239
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
162 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
163 def profileConnected(self, client): |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
164 def assign_service(service): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
165 client.muc_service = service |
2468
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
166 return self.getMUCService(client).addCallback(assign_service) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
167 |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
168 def _message_parseTrigger(self, client, message_elt, data): |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
169 """Add stanza-id from the room if present""" |
3028 | 170 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
|
171 return True |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
172 |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
173 # stanza_id will not be filled by parseMessage because the emitter |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
174 # is the room and not our server, so we have to parse it here |
3028 | 175 room_jid = data["from"].userhostJID() |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
176 stanza_id = self._si.getStanzaId(message_elt, room_jid) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
177 if stanza_id: |
3028 | 178 data["extra"]["stanza_id"] = stanza_id |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
179 |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
180 def messageReceivedTrigger(self, client, message_elt, post_treat): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
181 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
182 if message_elt.subject or message_elt.delay: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
183 return False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
184 from_jid = jid.JID(message_elt['from']) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
185 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
|
186 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
|
187 room = client._muc_client.joined_rooms[room_jid] |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 if room.state != ROOM_STATE_LIVE: |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
189 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
|
190 # 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
|
191 # 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
|
192 # but an expected case. |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
193 # On the other hand, with legacy history, it's not normal. |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
194 log.warning(_( |
3028 | 195 "Received non delayed message in a room before its " |
196 "initialisation: state={state}, msg={msg}").format( | |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
197 state=room.state, |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
198 msg=message_elt.toXml())) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
199 room._cache.append(message_elt) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
200 return False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
201 else: |
3028 | 202 log.warning("Received groupchat message for a room which has not been " |
203 "joined, ignoring it: {}".format(message_elt.toXml())) | |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
204 return False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
205 return True |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
206 |
2844
fa1cc09df195
plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents:
2827
diff
changeset
|
207 def getRoom(self, client, 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
|
208 """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
|
209 |
fa1cc09df195
plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents:
2827
diff
changeset
|
210 @param room_jid(jid.JID): jid of the room |
fa1cc09df195
plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents:
2827
diff
changeset
|
211 @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
|
212 """ |
fa1cc09df195
plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents:
2827
diff
changeset
|
213 try: |
fa1cc09df195
plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents:
2827
diff
changeset
|
214 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
|
215 except KeyError: |
3028 | 216 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
|
217 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
218 def checkRoomJoined(self, client, room_jid): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
219 """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
|
220 |
e8731b02f5ea
plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents:
1082
diff
changeset
|
221 @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
|
222 """ |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
223 if room_jid not in client._muc_client.joined_rooms: |
3028 | 224 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
|
225 |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
226 def isJoinedRoom(self, client, room_jid): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
227 """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
|
228 |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
229 @room_jid(jid.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
|
230 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
231 try: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
232 self.checkRoomJoined(client, room_jid) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
233 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
|
234 return False |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
235 else: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
236 return True |
1083
e8731b02f5ea
plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents:
1082
diff
changeset
|
237 |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
238 def isRoom(self, client, entity_jid): |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
239 """Tell if a jid is a joined MUC |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
240 |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
241 similar to isJoinedRoom but returns a boolean |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
242 @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
|
243 @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
|
244 """ |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
245 try: |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
246 self.checkRoomJoined(client, entity_jid.userhostJID()) |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
247 except exceptions.NotFound: |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
248 return False |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
249 else: |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
250 return True |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
251 |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
252 def getBareOrFull(self, client, peer_jid): |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
253 """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
|
254 |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
255 @param peer_jid(jid.JID): entity to test |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
256 @return (jid.JID): bare or full jid |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
257 """ |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
258 if peer_jid.resource: |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
259 if not self.isRoom(client, peer_jid): |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
260 return peer_jid.userhostJID() |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
261 return peer_jid |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
262 |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
263 def _getRoomJoinedArgs(self, room, profile): |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
264 return [ |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
265 room.roomJID.userhost(), |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
266 XEP_0045._getOccupants(room), |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
267 room.nick, |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
268 room.subject, |
3101
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
269 [s.name for s in room.statuses], |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
270 profile |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
271 ] |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
272 |
1990
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
273 def _UIRoomJoinCb(self, data, profile): |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
274 room_jid = jid.JID(data['index']) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
275 client = self.host.getClient(profile) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
276 self.join(client, room_jid) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
277 return {} |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
278 |
1986
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
279 def _passwordUICb(self, data, client, room_jid, nick): |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
280 """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
|
281 if C.bool(data.get(C.XMLUI_DATA_CANCELLED, "false")): |
3028 | 282 log.info("room join for {} is cancelled".format(room_jid.userhost())) |
283 raise failure.Failure(exceptions.CancelError(D_("Room joining cancelled by user"))) | |
1986
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
284 password = data[xml_tools.formEscape('password')] |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
285 return client._muc_client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, (client, room_jid, nick), errbackArgs=(client, room_jid, nick, password)) |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
286 |
1990
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
287 def _showListUI(self, items, client, service): |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
288 xmlui = xml_tools.XMLUI(title=D_('Rooms in {}'.format(service.full()))) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
289 adv_list = xmlui.changeContainer('advanced_list', columns=1, selectable='single', callback_id=self._room_join_id) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
290 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
|
291 for item in items: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
292 adv_list.setRowIndex(item.entity.full()) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
293 xmlui.addText(item.name) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
294 adv_list.end() |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
295 self.host.actionNew({'xmlui': xmlui.toXml()}, profile=client.profile) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
296 |
1986
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
297 def _joinCb(self, room, client, room_jid, nick): |
72 | 298 """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
|
299 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
|
300 # 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
|
301 # 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
|
302 # a proper configuration management should be done |
3028 | 303 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
|
304 d = client._muc_client.configure(room.roomJID, {}) |
2990
6959c71ab8bf
plugin XEP-0045: log "failure" on configure error
Goffi <goffi@goffi.org>
parents:
2986
diff
changeset
|
305 d.addErrback(self.host.logErrback, |
3028 | 306 msg=_('Error while configuring the room: {failure_}')) |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
307 return room.fully_joined |
319 | 308 |
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
|
309 def _joinEb(self, failure_, client, room_jid, nick, password): |
72 | 310 """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
|
311 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
|
312 condition = failure_.value.condition |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
313 except AttributeError: |
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
|
314 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
|
315 else: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
316 if condition == 'conflict': |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
317 # we have a nickname conflict, we try again with "_" suffixed to current nickname |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
318 nick += '_' |
1986
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
319 return client._muc_client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, (client, room_jid, nick), errbackArgs=(client, room_jid, nick, password)) |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
320 elif condition == 'not-allowed': |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
321 # room is restricted, we need a password |
3028 | 322 password_ui = xml_tools.XMLUI("form", title=D_('Room {} is restricted').format(room_jid.userhost()), submit_id='') |
1986
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
323 password_ui.addText(D_("This room is restricted, please enter the password")) |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
324 password_ui.addPassword('password') |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
325 d = xml_tools.deferXMLUI(self.host, password_ui, profile=client.profile) |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
326 d.addCallback(self._passwordUICb, client, room_jid, nick) |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
327 return d |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
328 |
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
|
329 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
|
330 |
3028 | 331 mess = D_("Error while joining the room {room}{suffix}".format( |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
332 room = room_jid.userhost(), suffix = msg_suffix)) |
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
|
333 log.warning(mess) |
3028 | 334 xmlui = xml_tools.note(mess, D_("Group chat error"), level=C.XMLUI_DATA_LVL_ERROR) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
335 self.host.actionNew({'xmlui': xmlui.toXml()}, profile=client.profile) |
72 | 336 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
337 @staticmethod |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
338 def _getOccupants(room): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
339 """Get occupants of a room in a form suitable for bridge""" |
3028 | 340 return {u.nick: {k:str(getattr(u,k) or '') for k in OCCUPANT_KEYS} for u in list(room.roster.values())} |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
341 |
2844
fa1cc09df195
plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents:
2827
diff
changeset
|
342 def _getRoomOccupants(self, room_jid_s, profile_key): |
fa1cc09df195
plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents:
2827
diff
changeset
|
343 client = self.host.getClient(profile_key) |
fa1cc09df195
plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents:
2827
diff
changeset
|
344 room_jid = jid.JID(room_jid_s) |
fa1cc09df195
plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents:
2827
diff
changeset
|
345 return self.getRoomOccupants(client, 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
|
346 |
fa1cc09df195
plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents:
2827
diff
changeset
|
347 def getRoomOccupants(self, client, 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
|
348 room = self.getRoom(client, 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
|
349 return self._getOccupants(room) |
fa1cc09df195
plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
Goffi <goffi@goffi.org>
parents:
2827
diff
changeset
|
350 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
351 def _getRoomsJoined(self, profile_key=C.PROF_KEY_NONE): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
352 client = self.host.getClient(profile_key) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
353 return self.getRoomsJoined(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
|
354 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
355 def getRoomsJoined(self, client): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
356 """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
|
357 result = [] |
3028 | 358 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
|
359 if room.state == ROOM_STATE_LIVE: |
3101
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
360 result.append( |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
361 (room.roomJID.userhost(), |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
362 self._getOccupants(room), |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
363 room.nick, |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
364 room.subject, |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
365 [s.name for s in room.statuses], |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
366 ) |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
367 ) |
78
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
77
diff
changeset
|
368 return result |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
77
diff
changeset
|
369 |
2461
34cb8b713370
plugin XEP-0045: added mucNickGet to retrieve our nickname in a MUC room
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
370 def _getRoomNick(self, room_jid_s, profile_key=C.PROF_KEY_NONE): |
34cb8b713370
plugin XEP-0045: added mucNickGet to retrieve our nickname in a MUC room
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
371 client = self.host.getClient(profile_key) |
34cb8b713370
plugin XEP-0045: added mucNickGet to retrieve our nickname in a MUC room
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
372 return self.getRoomNick(client, jid.JID(room_jid_s)) |
34cb8b713370
plugin XEP-0045: added mucNickGet to retrieve our nickname in a MUC room
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
373 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
374 def getRoomNick(self, client, room_jid): |
93 | 375 """return nick used in room by user |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
376 |
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 @param room_jid (jid.JID): JID of the room |
93 | 378 @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
|
379 @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
|
380 @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
|
381 """ |
2461
34cb8b713370
plugin XEP-0045: added mucNickGet to retrieve our nickname in a MUC room
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
382 self.checkRoomJoined(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
|
383 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
|
384 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
385 def _configureRoom(self, room_jid_s, profile_key=C.PROF_KEY_NONE): |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
386 client = self.host.getClient(profile_key) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
387 d = self.configureRoom(client, jid.JID(room_jid_s)) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
388 d.addCallback(lambda xmlui: xmlui.toXml()) |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
389 return d |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
390 |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
391 def _configureRoomMenu(self, menu_data, profile): |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
392 """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
|
393 |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
394 @param menu_data: %(menu_data)s |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
395 @param profile: %(doc_profile)s |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
396 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
397 client = self.host.getClient(profile) |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
398 try: |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
399 room_jid = jid.JID(menu_data['room_jid']) |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
400 except KeyError: |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
401 log.error(_("room_jid key is not present !")) |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
402 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
|
403 |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
404 def xmluiReceived(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
|
405 if not xmlui: |
3028 | 406 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
|
407 return {"xmlui": xml_tools.note(msg).toXml()} |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
408 return {"xmlui": xmlui.toXml()} |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
409 return self.configureRoom(client, room_jid).addCallback(xmluiReceived) |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
410 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
411 def configureRoom(self, client, room_jid): |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
412 """return the room configuration form |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
413 |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
414 @param room: jid of the room to configure |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
415 @return: configuration form as XMLUI |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
416 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
417 self.checkRoomJoined(client, room_jid) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
418 |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
419 def config2XMLUI(result): |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
420 if not result: |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
421 return "" |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
422 session_id, session_data = self._sessions.newSession(profile=client.profile) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
423 session_data["room_jid"] = room_jid |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
424 xmlui = xml_tools.dataForm2XMLUI(result, submit_id=self.__submit_conf_id) |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
425 xmlui.session_id = session_id |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
426 return xmlui |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
427 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
428 d = client._muc_client.getConfiguration(room_jid) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
429 d.addCallback(config2XMLUI) |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
430 return d |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
431 |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
432 def _submitConfiguration(self, raw_data, profile): |
2583
8378806a70fe
plugin XEP-0045: fixed room configuration cancellation
Goffi <goffi@goffi.org>
parents:
2581
diff
changeset
|
433 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
|
434 if cancelled: |
8378806a70fe
plugin XEP-0045: fixed room configuration cancellation
Goffi <goffi@goffi.org>
parents:
2581
diff
changeset
|
435 return defer.succeed({}) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
436 client = self.host.getClient(profile) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
437 try: |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
438 session_data = self._sessions.profileGet(raw_data["session_id"], profile) |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
439 except KeyError: |
1068
1513511a0586
plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
440 log.warning(D_("Session ID doesn't exist, session has probably expired.")) |
1513511a0586
plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
441 _dialog = xml_tools.XMLUI('popup', title=D_('Room configuration failed')) |
1513511a0586
plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
442 _dialog.addText(D_("Session ID doesn't exist, session has probably expired.")) |
1513511a0586
plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
443 return defer.succeed({'xmlui': _dialog.toXml()}) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
444 |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
445 data = xml_tools.XMLUIResult2DataFormResult(raw_data) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
446 d = client._muc_client.configure(session_data['room_jid'], data) |
1068
1513511a0586
plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
447 _dialog = xml_tools.XMLUI('popup', title=D_('Room configuration succeed')) |
1513511a0586
plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
448 _dialog.addText(D_("The new settings have been saved.")) |
1513511a0586
plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
449 d.addCallback(lambda ignore: {'xmlui': _dialog.toXml()}) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
450 del self._sessions[raw_data["session_id"]] |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
451 return d |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
452 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
453 def isNickInRoom(self, client, room_jid, nick): |
522
3446ce33247d
plugin XEP-0045: added isNickInRoom method
Goffi <goffi@goffi.org>
parents:
519
diff
changeset
|
454 """Tell if a nick is currently present in a room""" |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
455 self.checkRoomJoined(client, room_jid) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
456 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
|
457 |
2468
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
458 def _getMUCService(self, jid_=None, profile=C.PROF_KEY_NONE): |
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
459 client = self.host.getClient(profile) |
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
460 d = self.getMUCService(client, jid_ or None) |
3028 | 461 d.addCallback(lambda service_jid: service_jid.full() if service_jid is not None else '') |
2468
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
462 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
|
463 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
464 @defer.inlineCallbacks |
2468
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
465 def getMUCService(self, client, jid_=None): |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
466 """Return first found MUC service of an entity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
467 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
468 @param jid_: entity which may have a MUC service, or None for our own server |
2468
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
469 @return (jid.JID, None): found service jid or None |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
470 """ |
2468
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
471 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
|
472 try: |
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
473 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
|
474 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
|
475 pass |
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
476 else: |
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
477 # we have a cached value, we return it |
8f14c1865e9e
plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
Goffi <goffi@goffi.org>
parents:
2461
diff
changeset
|
478 defer.returnValue(muc_service) |
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
|
479 services = yield self.host.findServiceEntities(client, "conference", "text", jid_) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
480 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
|
481 if ".irc." not in service.userhost(): |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
482 # FIXME: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
483 # 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
|
484 # 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
|
485 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
|
486 break |
2613
9680cd958529
plugin XEP-0045: fixed crash when muc service is not found
Goffi <goffi@goffi.org>
parents:
2584
diff
changeset
|
487 else: |
9680cd958529
plugin XEP-0045: fixed crash when muc service is not found
Goffi <goffi@goffi.org>
parents:
2584
diff
changeset
|
488 muc_service = None |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
489 defer.returnValue(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
|
490 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
491 def _getUniqueName(self, muc_service="", profile_key=C.PROF_KEY_NONE): |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
492 client = self.host.getClient(profile_key) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
493 return self.getUniqueName(client, muc_service or None).full() |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
494 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
495 def getUniqueName(self, client, muc_service=None): |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
496 """Return unique name for a room, avoiding collision |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
497 |
1356
c01cbd8fc8dd
plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
498 @param muc_service (jid.JID) : leave empty string to use the default service |
c01cbd8fc8dd
plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
499 @return: jid.JID (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
|
500 """ |
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
|
501 # TODO: we should use #RFC-0045 10.1.4 when available here |
3028 | 502 room_name = str(uuid.uuid4()) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
503 if muc_service is None: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
504 try: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
505 muc_service = client.muc_service |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
506 except AttributeError: |
3028 | 507 raise exceptions.NotReady("Main server MUC service has not been checked yet") |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
508 if muc_service is None: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
950
diff
changeset
|
509 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
|
510 raise exceptions.FeatureNotFound |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
511 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
512 muc_service = muc_service.userhost() |
3028 | 513 return jid.JID("{}@{}".format(room_name, muc_service)) |
319 | 514 |
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
|
515 def getDefaultMUC(self): |
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
|
516 """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
|
517 |
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
|
518 @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
|
519 """ |
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
|
520 return self.host.memory.getConfig(CONFIG_SECTION, 'default_muc', default_conf['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
|
521 |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
522 def _join_eb(self, failure_, client): |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
523 failure_.trap(AlreadyJoined) |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
524 room = failure_.value.room |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
525 return [True] + self._getRoomJoinedArgs(room, client.profile) |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
526 |
2028
70bd7b242a9e
plugin XEP-0045: fixed options parameter handling in bridge callback
Goffi <goffi@goffi.org>
parents:
2021
diff
changeset
|
527 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
|
528 """join method used by bridge |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
529 |
2461
34cb8b713370
plugin XEP-0045: added mucNickGet to retrieve our nickname in a MUC room
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
530 @return (tuple): already_joined boolean + room joined arguments (see [_getRoomJoinedArgs]) |
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
|
531 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
532 client = self.host.getClient(profile_key) |
1356
c01cbd8fc8dd
plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
533 if room_jid_s: |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
534 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
|
535 try: |
c01cbd8fc8dd
plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
536 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
|
537 except (RuntimeError, jid.InvalidFormat, AttributeError): |
3028 | 538 return defer.fail(jid.InvalidFormat(_("Invalid room identifier: {room_id}'. Please give a room short or full identifier like 'room' or 'room@{muc_service}'.").format( |
2170 | 539 room_id=room_jid_s, |
3028 | 540 muc_service=str(muc_service)))) |
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
|
541 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
|
542 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
|
543 else: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
544 room_jid = self.getUniqueName(profile_key=client.profile) |
743
5a131930348d
plugin XEP-0045: remove redondant errback from _join
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
545 # TODO: error management + signal in bridge |
2028
70bd7b242a9e
plugin XEP-0045: fixed options parameter handling in bridge callback
Goffi <goffi@goffi.org>
parents:
2021
diff
changeset
|
546 d = self.join(client, room_jid, nick, options or None) |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
547 d.addCallback(lambda room: [False] + self._getRoomJoinedArgs(room, client.profile)) |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
548 d.addErrback(self._join_eb, client) |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
549 return d |
505
2402668b5d05
plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents:
488
diff
changeset
|
550 |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
551 def join(self, client, room_jid, nick=None, options=None): |
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
552 if not nick: |
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
553 nick = client.jid.user |
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
554 if options is None: |
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
555 options = {} |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
556 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
|
557 room = client._muc_client.joined_rooms[room_jid] |
3028 | 558 log.info(_('{profile} is already in room {room_jid}').format( |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2994
diff
changeset
|
559 profile=client.profile, room_jid = room_jid.userhost())) |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
560 return defer.fail(AlreadyJoined(room)) |
3028 | 561 log.info(_("[{profile}] is joining room {room} with nick {nick}").format( |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2994
diff
changeset
|
562 profile=client.profile, room=room_jid.userhost(), nick=nick)) |
3060
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
563 self.host.bridge.mucRoomPrepareJoin(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
|
564 |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
565 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
|
566 |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2994
diff
changeset
|
567 d = client._muc_client.join(room_jid, nick, password) |
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2994
diff
changeset
|
568 d.addCallbacks(self._joinCb, self._joinEb, |
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2994
diff
changeset
|
569 (client, room_jid, nick), |
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2994
diff
changeset
|
570 errbackArgs=(client, room_jid, nick, password)) |
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2994
diff
changeset
|
571 return d |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
572 |
3008
c8c68a3b0a79
plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents:
3002
diff
changeset
|
573 def popRooms(self, client): |
c8c68a3b0a79
plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents:
3002
diff
changeset
|
574 """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
|
575 |
c8c68a3b0a79
plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents:
3002
diff
changeset
|
576 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
|
577 @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
|
578 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
|
579 """ |
c8c68a3b0a79
plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
Goffi <goffi@goffi.org>
parents:
3002
diff
changeset
|
580 args_list = [] |
3028 | 581 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
|
582 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
|
583 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
|
584 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
|
585 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
586 def _nick(self, room_jid_s, nick, profile_key=C.PROF_KEY_NONE): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
587 client = self.host.getClient(profile_key) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
588 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
|
589 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
590 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
|
591 """Change nickname in a room""" |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
592 self.checkRoomJoined(client, room_jid) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
593 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
|
594 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
595 def _leave(self, room_jid, profile_key): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
596 client = self.host.getClient(profile_key) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
597 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
|
598 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
599 def leave(self, client, room_jid): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
600 self.checkRoomJoined(client, room_jid) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
601 return client._muc_client.leave(room_jid) |
505
2402668b5d05
plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents:
488
diff
changeset
|
602 |
2021
6c51e8f17c92
plugin XEP-0045: added bridge method to change subject
Goffi <goffi@goffi.org>
parents:
1992
diff
changeset
|
603 def _subject(self, room_jid_s, new_subject, profile_key): |
6c51e8f17c92
plugin XEP-0045: added bridge method to change subject
Goffi <goffi@goffi.org>
parents:
1992
diff
changeset
|
604 client = self.host.getClient(profile_key) |
6c51e8f17c92
plugin XEP-0045: added bridge method to change subject
Goffi <goffi@goffi.org>
parents:
1992
diff
changeset
|
605 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
|
606 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
607 def subject(self, client, room_jid, subject): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
608 self.checkRoomJoined(client, room_jid) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
609 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
|
610 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
611 def getHandler(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
|
612 # create a MUC client and associate it with profile' session |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
613 muc_client = client._muc_client = SatMUCClient(self) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
614 return muc_client |
72 | 615 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
616 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
|
617 """Kick a participant from the room |
d715d912afac
plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
2613
diff
changeset
|
618 |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
619 @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
|
620 @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
|
621 @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
|
622 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
623 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
|
624 options = {} |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
625 self.checkRoomJoined(client, room_jid) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
626 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
|
627 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
628 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
|
629 """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
|
630 |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
631 @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
|
632 @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
|
633 @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
|
634 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
635 self.checkRoomJoined(client, room_jid) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
636 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
|
637 options = {} |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
638 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
|
639 assert not room_jid.resource |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
640 return client._muc_client.ban(room_jid, entity_jid, reason=options.get('reason', None)) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
641 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
642 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
|
643 """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
|
644 |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
645 @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
|
646 @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
|
647 @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
|
648 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
649 self.checkRoomJoined(client, room_jid) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
650 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
|
651 assert not room_jid.resource |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
652 assert 'affiliation' in options |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
653 # TODO: handles reason and nick |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
654 return client._muc_client.modifyAffiliationList(room_jid, [entity_jid], options['affiliation']) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
655 |
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
|
656 # 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
|
657 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
658 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
|
659 """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
|
660 |
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
|
661 @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
|
662 - 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
|
663 """ |
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
|
664 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
|
665 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
|
666 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
|
667 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
|
668 |
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
|
669 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
|
670 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
671 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
|
672 """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
|
673 |
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
|
674 @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
|
675 - 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
|
676 """ |
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
|
677 if mess_data["unparsed"].strip(): |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
678 room_jid = self.text_cmds.getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
679 nick = (self.getRoomNick(client, room_jid) or |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
680 client.jid.user) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
681 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
|
682 |
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
|
683 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
|
684 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
685 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
|
686 """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
|
687 |
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
|
688 @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
|
689 - 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
|
690 """ |
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
|
691 if mess_data["unparsed"].strip(): |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
692 room = self.text_cmds.getRoomJID(mess_data["unparsed"].strip(), 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
|
693 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
|
694 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
|
695 |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
696 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
|
697 |
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
|
698 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
|
699 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
700 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
|
701 """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
|
702 |
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
|
703 @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
|
704 - 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
|
705 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
706 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
|
707 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
708 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
|
709 """kick a room member |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
710 |
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
|
711 @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
|
712 - 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
|
713 """ |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
714 options = mess_data["unparsed"].strip().split() |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
715 try: |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
716 nick = options[0] |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
717 assert self.isNickInRoom(client, mess_data["to"], nick) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
718 except (IndexError, AssertionError): |
3028 | 719 feedback = _("You must provide a member's nick to kick.") |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
720 self.text_cmds.feedBack(client, feedback, mess_data) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
721 return False |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
722 |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
723 d = self.kick(client, nick, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
724 |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
725 def cb(__): |
3028 | 726 feedback_msg = _('You have kicked {}').format(nick) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
727 if len(options) > 1: |
3028 | 728 feedback_msg += _(' for the following reason: {}').format(options[1]) |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
729 self.text_cmds.feedBack(client, feedback_msg, mess_data) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
730 return True |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
731 d.addCallback(cb) |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
732 return d |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
733 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
734 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
|
735 """ban an entity from the room |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
736 |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
737 @command (group): (JID) [reason] |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
738 - 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
|
739 - 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
|
740 """ |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
741 options = mess_data["unparsed"].strip().split() |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
742 try: |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
743 jid_s = options[0] |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
744 entity_jid = jid.JID(jid_s).userhostJID() |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
745 assert(entity_jid.user) |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
746 assert(entity_jid.host) |
1742
244a605623d6
complete the Exception's list when catching JID error:
souliane <souliane@mailoo.org>
parents:
1700
diff
changeset
|
747 except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, AssertionError): |
3028 | 748 feedback = _("You must provide a valid JID to ban, like in '/ban contact@example.net'") |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
749 self.text_cmds.feedBack(client, feedback, mess_data) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
750 return False |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
751 |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
752 d = self.ban(client, entity_jid, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
753 |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
754 def cb(__): |
3028 | 755 feedback_msg = _('You have banned {}').format(entity_jid) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
756 if len(options) > 1: |
3028 | 757 feedback_msg += _(' for the following reason: {}').format(options[1]) |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
758 self.text_cmds.feedBack(client, feedback_msg, mess_data) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
759 return True |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
760 d.addCallback(cb) |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
761 return d |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
762 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
763 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
|
764 """affiliate an entity to the room |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
765 |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
766 @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
|
767 - 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
|
768 - owner: grant owner privileges |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
769 - admin: grant admin privileges |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
770 - member: grant member privileges |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
771 - none: reset entity privileges |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
772 - outcast: ban entity |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
773 """ |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
774 options = mess_data["unparsed"].strip().split() |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
775 try: |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
776 jid_s = options[0] |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
777 entity_jid = jid.JID(jid_s).userhostJID() |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
778 assert(entity_jid.user) |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
779 assert(entity_jid.host) |
1742
244a605623d6
complete the Exception's list when catching JID error:
souliane <souliane@mailoo.org>
parents:
1700
diff
changeset
|
780 except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, AssertionError): |
3028 | 781 feedback = _("You must provide a valid JID to affiliate, like in '/affiliate contact@example.net member'") |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
782 self.text_cmds.feedBack(client, feedback, mess_data) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
783 return False |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
784 |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
785 affiliation = options[1] if len(options) > 1 else 'none' |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
786 if affiliation not in AFFILIATIONS: |
3028 | 787 feedback = _("You must provide a valid affiliation: %s") % ' '.join(AFFILIATIONS) |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
788 self.text_cmds.feedBack(client, feedback, mess_data) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
789 return False |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
790 |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
791 d = self.affiliate(client, entity_jid, mess_data["to"], {'affiliation': affiliation}) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
792 |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
793 def cb(__): |
3028 | 794 feedback_msg = _('New affiliation for %(entity)s: %(affiliation)s').format(entity=entity_jid, affiliation=affiliation) |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
795 self.text_cmds.feedBack(client, feedback_msg, mess_data) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
796 return True |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
797 d.addCallback(cb) |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
798 return d |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
799 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
800 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
|
801 """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
|
802 |
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
|
803 @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
|
804 - 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
|
805 """ |
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
|
806 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
|
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 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
|
809 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
|
810 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
|
811 |
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 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
|
813 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
814 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
|
815 """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
|
816 |
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
|
817 @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
|
818 - 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
|
819 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
820 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
|
821 |
1990
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
822 def cmd_list(self, client, mess_data): |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
823 """list available rooms in a muc server |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
824 |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
825 @command (all): [MUC_SERVICE] |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
826 - MUC_SERVICE: service to request |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
827 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
|
828 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
|
829 """ |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
830 unparsed = mess_data["unparsed"].strip() |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
831 try: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
832 service = jid.JID(unparsed) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
833 except RuntimeError: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
834 if mess_data['type'] == C.MESS_TYPE_GROUPCHAT: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
835 room_jid = mess_data["to"] |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
836 service = jid.JID(room_jid.host) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
837 elif client.muc_service is not None: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
838 service = client.muc_service |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
839 else: |
3028 | 840 msg = D_("No known default MUC service".format(unparsed)) |
1990
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
841 self.text_cmds.feedBack(client, msg, mess_data) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
842 return False |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
843 except jid.InvalidFormat: |
3028 | 844 msg = D_("{} is not a valid JID!".format(unparsed)) |
1990
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
845 self.text_cmds.feedBack(client, msg, mess_data) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
846 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
|
847 d = self.host.getDiscoItems(client, service) |
1990
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
848 d.addCallback(self._showListUI, client, service) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
849 |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
850 return False |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
851 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
852 def _whois(self, client, whois_msg, mess_data, target_jid): |
1199 | 853 """ Add MUC user information to whois """ |
928
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
854 if mess_data['type'] != "groupchat": |
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
855 return |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
856 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
|
857 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
|
858 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
|
859 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
|
860 return |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
861 user = client._muc_client.joined_rooms[target_jid.userhostJID()].getUser(target_jid.resource) |
928
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
862 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
|
863 if user.entity: |
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
864 whois_msg.append(_("Entity: %s") % user.entity) |
1083
e8731b02f5ea
plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents:
1082
diff
changeset
|
865 if user.affiliation != 'none': |
928
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
866 whois_msg.append(_("Affiliation: %s") % user.affiliation) |
1083
e8731b02f5ea
plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents:
1082
diff
changeset
|
867 if user.role != 'none': |
928
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
868 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
|
869 if user.status: |
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
870 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
|
871 if user.show: |
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
872 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
|
873 |
1239
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
874 def presenceTrigger(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
|
875 # 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
|
876 # 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
|
877 muc_client = client._muc_client |
3028 | 878 for room_jid, room in muc_client.joined_rooms.items(): |
2815
27d9d25ec3cd
plugin XEP-0045: fixed issue with deepcopy by using new xml_tools.elementCopy method
Goffi <goffi@goffi.org>
parents:
2794
diff
changeset
|
879 elt = xml_tools.elementCopy(presence_elt) |
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
|
880 elt['to'] = room_jid.userhost() + '/' + room.nick |
1239
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
881 client.presence.send(elt) |
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
882 return True |
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
883 |
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
|
884 def presenceReceivedTrigger(self, client, entity, show, priority, statuses): |
5284be4c601b
plugin XEP-0045: cache presences if they are received before the room is fully joined:
Goffi <goffi@goffi.org>
parents:
2815
diff
changeset
|
885 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
|
886 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
|
887 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
|
888 # presence is already handled in (un)availableReceived |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
889 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
|
890 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
|
891 |
72 | 892 |
3028 | 893 @implementer(iwokkel.IDisco) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
894 class SatMUCClient(muc.MUCClient): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
895 |
72 | 896 def __init__(self, plugin_parent): |
897 self.plugin_parent = plugin_parent | |
898 muc.MUCClient.__init__(self) | |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
899 self._changing_nicks = set() # used to keep trace of who is changing nick, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
900 # and to discard userJoinedRoom signal in this case |
3028 | 901 print("init SatMUCClient OK") |
515
29b5ef129488
plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
902 |
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
|
903 @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
|
904 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
|
905 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
|
906 |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
907 @property |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
908 def host(self): |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
909 return self.plugin_parent.host |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
910 |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
911 @property |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
912 def client(self): |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
913 return self.parent |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
914 |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
915 @property |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
916 def _mam(self): |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
917 return self.plugin_parent._mam |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
918 |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
919 @property |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
920 def _si(self): |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
921 return self.plugin_parent._si |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
922 |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
923 def changeRoomState(self, room, new_state): |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
924 """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
|
925 |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
926 @param new_state: one of ROOM_STATE_* |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
927 """ |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
928 new_state_idx = ROOM_STATES.index(new_state) |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
929 if new_state_idx == -1: |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
930 raise exceptions.InternalError("unknown room state") |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
931 if new_state_idx < 1: |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
932 raise exceptions.InternalError("unexpected new room state ({room}): {state}".format( |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
933 room=room.userhost(), |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
934 state=new_state)) |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
935 expected_state = ROOM_STATES[new_state_idx-1] |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
936 if room.state != expected_state: |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
937 log.error(_( |
3028 | 938 "room {room} is not in expected state: room is in state {current_state} " |
939 "while we were expecting {expected_state}").format( | |
3015
7b8d40b17451
plugin XEP-0045: fixed a bad attribute in a log message.
Goffi <goffi@goffi.org>
parents:
3008
diff
changeset
|
940 room=room.roomJID.userhost(), |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
941 current_state=room.state, |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
942 expected_state=expected_state)) |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
943 room.state = new_state |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
944 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
945 def _addRoom(self, room): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
946 super(SatMUCClient, self)._addRoom(room) |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
947 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
|
948 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
|
949 # 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
|
950 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
|
951 # cache data until room is ready |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
952 # 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
|
953 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
|
954 # 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
|
955 room._cache_presence = {} |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
956 |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
957 @defer.inlineCallbacks |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
958 def _joinLegacy(self, client, room_jid, nick, password): |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
959 """Join room an retrieve history with legacy method""" |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
960 mess_data_list = yield self.host.memory.historyGet(room_jid, |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
961 client.jid.userhostJID(), |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
962 limit=1, |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
963 between=True, |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
964 profile=client.profile) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
965 if mess_data_list: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
966 timestamp = mess_data_list[0][1] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
967 # 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
|
968 # 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
|
969 seconds = int(time.time() - timestamp) - 1 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
970 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
971 seconds = None |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
972 |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
973 room = yield super(SatMUCClient, self).join( |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
974 room_jid, nick, muc.HistoryOptions(seconds=seconds), password) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
975 # 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
|
976 room._history_type = HISTORY_LEGACY |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
977 room._history_d = defer.Deferred() |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
978 room._history_d.callback(None) |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
979 defer.returnValue(room) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
980 |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
981 @defer.inlineCallbacks |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
982 def _joinMAM(self, client, room_jid, nick, password): |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
983 """Join room and retrieve history using MAM""" |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
984 room = yield super(SatMUCClient, self).join( |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
985 # we don't want any history from room as we'll get it with MAM |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
986 room_jid, nick, muc.HistoryOptions(maxStanzas=0), password=password) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
987 room._history_type = HISTORY_MAM |
3060
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
988 history_d = room._history_d = defer.Deferred() |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
989 # 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
|
990 # and in order |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
991 history_d.callback(None) |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
992 |
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
|
993 last_mess = yield self.host.memory.historyGet( |
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
|
994 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
|
995 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
|
996 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
|
997 between=False, |
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
|
998 filters={ |
3028 | 999 'types': C.MESS_TYPE_GROUPCHAT, |
1000 'last_stanza_id': True}, | |
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
|
1001 profile=client.profile) |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1002 if last_mess: |
3028 | 1003 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
|
1004 rsm_req = rsm.RSMRequest(max_=20, after=stanza_id) |
2724
35a0ab3032bb
plugin XEP-0045: don't loop when initiating MAM archive
Goffi <goffi@goffi.org>
parents:
2723
diff
changeset
|
1005 no_loop=False |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1006 else: |
3028 | 1007 log.info("We have no MAM archive for room {room_jid}.".format( |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1008 room_jid=room_jid)) |
2718
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1009 # 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
|
1010 # as it can be huge |
3028 | 1011 rsm_req = rsm.RSMRequest(max_=50, before='') |
2724
35a0ab3032bb
plugin XEP-0045: don't loop when initiating MAM archive
Goffi <goffi@goffi.org>
parents:
2723
diff
changeset
|
1012 no_loop=True |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1013 |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1014 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
|
1015 complete = False |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1016 count = 0 |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1017 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
|
1018 try: |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1019 mam_data = yield self._mam.getArchives(client, mam_req, |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1020 service=room_jid) |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1021 except xmpp_error.StanzaError as e: |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1022 if last_mess and e.condition == 'item-not-found': |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1023 log.info( |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1024 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
|
1025 f"history of {room_jid}, history has probably been purged on " |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1026 f"server.") |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1027 # we get last items like for a new room |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1028 rsm_req = rsm.RSMRequest(max_=50, before='') |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1029 mam_req = mam.MAMRequest(rsm_=rsm_req) |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1030 no_loop=True |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1031 continue |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1032 else: |
16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Goffi <goffi@goffi.org>
parents:
3060
diff
changeset
|
1033 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
|
1034 elt_list, rsm_response, mam_response = mam_data |
3028 | 1035 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
|
1036 # 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
|
1037 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
|
1038 |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1039 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
|
1040 break |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1041 else: |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1042 count += len(elt_list) |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1043 |
2718
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1044 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
|
1045 try: |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1046 fwd_message_elt = self._mam.getMessageFromResult( |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1047 client, mess_elt, mam_req, service=room_jid) |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1048 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
|
1049 continue |
3028 | 1050 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
|
1051 log.warning( |
3028 | 1052 'Forwarded message element has a "to" attribute while it is ' |
1053 'forbidden by specifications') | |
1054 fwd_message_elt["to"] = client.jid.full() | |
3060
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1055 try: |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1056 mess_data = client.messageProt.parseMessage(fwd_message_elt) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1057 except Exception as e: |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1058 log.error( |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1059 f"Can't parse message, ignoring it: {e}\n" |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1060 f"{fwd_message_elt.toXml()}" |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1061 ) |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1062 continue |
2718
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1063 # we attache parsed message data to element, to avoid parsing |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1064 # again in _addToHistory |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1065 fwd_message_elt._mess_data = mess_data |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1066 # and we inject to MUC workflow |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1067 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
|
1068 |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1069 if not count: |
3028 | 1070 log.info(_("No message received while offline in {room_jid}".format( |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1071 room_jid=room_jid))) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1072 else: |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1073 log.info( |
3028 | 1074 _("We have received {num_mess} message(s) in {room_jid} while " |
1075 "offline.") | |
2718
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2715
diff
changeset
|
1076 .format(num_mess=count, room_jid=room_jid)) |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1077 |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1078 # 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
|
1079 # 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
|
1080 # is received before archive), so we change state and add the callbacks here. |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1081 self.changeRoomState(room, ROOM_STATE_LIVE) |
3060
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1082 history_d.addCallbacks(self._historyCb, self._historyEb, [room], |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1083 errbackArgs=[room]) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1084 |
3060
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1085 # we wait for all callbacks to be processed |
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1086 yield history_d |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1087 |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1088 defer.returnValue(room) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1089 |
2728
1b11da85492c
plugin XEP-0045: fixed bad MAM detection on join
Goffi <goffi@goffi.org>
parents:
2724
diff
changeset
|
1090 @defer.inlineCallbacks |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1091 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
|
1092 room_service = jid.JID(room_jid.host) |
9a3b99acad91
plugin XEP-0045: fixed item-not-found exception when creating a room:
Goffi <goffi@goffi.org>
parents:
2826
diff
changeset
|
1093 has_mam = yield 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
|
1094 if not self._mam or not has_mam: |
1b11da85492c
plugin XEP-0045: fixed bad MAM detection on join
Goffi <goffi@goffi.org>
parents:
2724
diff
changeset
|
1095 room = yield self._joinLegacy(self.client, room_jid, nick, password) |
1b11da85492c
plugin XEP-0045: fixed bad MAM detection on join
Goffi <goffi@goffi.org>
parents:
2724
diff
changeset
|
1096 defer.returnValue(room) |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1097 else: |
2728
1b11da85492c
plugin XEP-0045: fixed bad MAM detection on join
Goffi <goffi@goffi.org>
parents:
2724
diff
changeset
|
1098 room = yield self._joinMAM(self.client, room_jid, nick, password) |
1b11da85492c
plugin XEP-0045: fixed bad MAM detection on join
Goffi <goffi@goffi.org>
parents:
2724
diff
changeset
|
1099 defer.returnValue(room) |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1100 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1101 ## presence/roster ## |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1102 |
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
|
1103 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
|
1104 """ |
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
|
1105 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
|
1106 """ |
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
|
1107 # 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
|
1108 # (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
|
1109 |
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
|
1110 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
|
1111 |
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
|
1112 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
|
1113 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
|
1114 |
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
|
1115 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
|
1116 nick = presence.sender.resource |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1117 if not nick: |
3028 | 1118 log.warning(_("missing nick in presence: {xml}").format( |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1119 xml = presence.toElement().toXml())) |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1120 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
|
1121 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
|
1122 |
3101
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
1123 # we want to keep statuses with room |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
1124 # 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
|
1125 # 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
|
1126 # 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
|
1127 # thus we check if attribute already exists |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
1128 if (not hasattr(room, 'statuses') |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
1129 and muc.STATUS_CODE.SELF_PRESENCE in presence.mucStatuses): |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
1130 room.statuses = presence.mucStatuses |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3086
diff
changeset
|
1131 |
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
|
1132 # 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
|
1133 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
|
1134 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
|
1135 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
|
1136 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
|
1137 |
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
|
1138 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
|
1139 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
|
1140 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
|
1141 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
|
1142 self.userJoinedRoom(room, user) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1143 |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1144 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
|
1145 # 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
|
1146 """ |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1147 Unavailable presence was received. |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1148 |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1149 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
|
1150 left the room. |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1151 """ |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1152 room, user = self._getRoomUser(presence) |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1153 |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1154 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
|
1155 return |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1156 |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1157 room.removeUser(user) |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1158 |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1159 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
|
1160 self._changing_nicks.add(presence.nick) |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1161 self.userChangedNick(room, user, presence.nick) |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1162 else: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1163 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
|
1164 self.userLeftRoom(room, user) |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1165 |
74
6e3a06b4dd36
plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
1166 def userJoinedRoom(self, room, user): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1167 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
|
1168 # 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
|
1169 # this mean that the full room roster was received |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1170 self.changeRoomState(room, ROOM_STATE_SELF_PRESENCE) |
3028 | 1171 log.debug("room {room} joined with nick {nick}".format( |
2994
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2991
diff
changeset
|
1172 room=room.occupantJID.userhost(), nick=user.nick)) |
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2991
diff
changeset
|
1173 # 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
|
1174 # with disco to check entity type |
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2991
diff
changeset
|
1175 self.host.memory.updateEntityData( |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
1176 self.client, room.roomJID, C.ENTITY_TYPE, C.ENTITY_TYPE_MUC |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
1177 ) |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1178 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
|
1179 log.warning( |
3028 | 1180 "Received user presence data in a room before its initialisation " |
1181 "(current state: {state})," | |
1182 "this is not standard! Ignoring it: {room} ({nick})".format( | |
2994
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2991
diff
changeset
|
1183 state=room.state, |
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2991
diff
changeset
|
1184 room=room.roomJID.userhost(), |
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2991
diff
changeset
|
1185 nick=user.nick)) |
1984
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
1186 return |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1187 else: |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1188 if not room.fully_joined.called: |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1189 return |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1190 try: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1191 self._changing_nicks.remove(user.nick) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1192 except KeyError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1193 # this is a new user |
3028 | 1194 log.debug(_("user {nick} has joined room {room_id}").format( |
2994
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2991
diff
changeset
|
1195 nick=user.nick, room_id=room.occupantJID.userhost())) |
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2991
diff
changeset
|
1196 if not self.host.trigger.point( |
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2991
diff
changeset
|
1197 "MUC user joined", room, user, self.client.profile): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1198 return |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1199 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1200 extra = {'info_type': ROOM_USER_JOINED, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1201 'user_affiliation': user.affiliation, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1202 'user_role': user.role, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1203 'user_nick': user.nick |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1204 } |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1205 if user.entity is not None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1206 extra['user_entity'] = user.entity.full() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1207 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
|
1208 "from": room.roomJID, |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1209 "to": self.client.jid, |
3028 | 1210 "uid": str(uuid.uuid4()), |
1211 "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
|
1212 "subject": {}, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1213 "type": C.MESS_TYPE_INFO, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1214 "extra": extra, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1215 "timestamp": time.time(), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1216 } |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1217 # 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
|
1218 # 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
|
1219 # to re-enable it |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1220 # self.client.messageAddToHistory(mess_data) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1221 self.client.messageSendToBridge(mess_data) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1222 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1223 |
74
6e3a06b4dd36
plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
1224 def userLeftRoom(self, room, user): |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1225 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
|
1226 return |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1227 if user.nick == room.nick: |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1228 # we left the room |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1229 room_jid_s = room.roomJID.userhost() |
3028 | 1230 log.info(_("Room ({room}) left ({profile})").format( |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1231 room = room_jid_s, profile = self.client.profile)) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1232 self.host.memory.delEntityCache(room.roomJID, profile_key=self.client.profile) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1233 self.host.bridge.mucRoomLeft(room.roomJID.userhost(), self.client.profile) |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1234 elif room.state != ROOM_STATE_LIVE: |
3028 | 1235 log.warning("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
|
1236 "this is not standard! Ignoring it: {room} ({nick})".format( |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1237 state=room.state, |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1238 room=room.roomJID.userhost(), |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1239 nick=user.nick)) |
1984
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
1240 return |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1241 else: |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1242 if not room.fully_joined.called: |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1243 return |
3028 | 1244 log.debug(_("user {nick} left room {room_id}").format(nick=user.nick, room_id=room.occupantJID.userhost())) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1245 extra = {'info_type': ROOM_USER_LEFT, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1246 'user_affiliation': user.affiliation, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1247 'user_role': user.role, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1248 'user_nick': user.nick |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1249 } |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1250 if user.entity is not None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1251 extra['user_entity'] = user.entity.full() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1252 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
|
1253 "from": room.roomJID, |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1254 "to": self.client.jid, |
3028 | 1255 "uid": str(uuid.uuid4()), |
1256 "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
|
1257 "subject": {}, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1258 "type": C.MESS_TYPE_INFO, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1259 "extra": extra, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1260 "timestamp": time.time(), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1261 } |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1262 # FIXME: disable history, see userJoinRoom comment |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1263 # self.client.messageAddToHistory(mess_data) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1264 self.client.messageSendToBridge(mess_data) |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1265 |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
1266 def userChangedNick(self, room, user, new_nick): |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1267 self.host.bridge.mucRoomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.client.profile) |
72 | 1268 |
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
|
1269 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
|
1270 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
|
1271 if hasattr(room, "_cache_presence"): |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1272 # 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
|
1273 # 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
|
1274 # 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
|
1275 # "unavailable" presence |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1276 cache = room._cache_presence |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1277 cache[entity] = { |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1278 "room": room, |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1279 "user": user, |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1280 "show": show, |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1281 "status": status, |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1282 } |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1283 return |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1284 statuses = {C.PRESENCE_STATUSES_DEFAULT: status or ''} |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1285 self.host.bridge.presenceUpdate( |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1286 entity.full(), show or '', 0, statuses, self.client.profile) |
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
|
1287 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1288 ## messages ## |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1289 |
1256
4b27b9bf31b0
plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents:
1250
diff
changeset
|
1290 def receivedGroupChat(self, room, user, body): |
3028 | 1291 log.debug('receivedGroupChat: room=%s user=%s body=%s' % (room.roomJID.full(), user, body)) |
1256
4b27b9bf31b0
plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents:
1250
diff
changeset
|
1292 |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1293 def _addToHistory(self, __, user, message): |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1294 try: |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1295 # message can be already parsed (with MAM), in this case mess_data |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1296 # it attached to the element |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1297 mess_data = message.element._mess_data |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1298 except AttributeError: |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1299 mess_data = self.client.messageProt.parseMessage(message.element) |
3028 | 1300 if mess_data['message'] or mess_data['subject']: |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1301 return self.host.memory.addToHistory(self.client, mess_data) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1302 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1303 return defer.succeed(None) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1304 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1305 def _addToHistoryEb(self, failure): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1306 failure.trap(exceptions.CancelError) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1307 |
1256
4b27b9bf31b0
plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents:
1250
diff
changeset
|
1308 def receivedHistory(self, room, user, message): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1309 """Called when history (backlog) message are received |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1310 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1311 we check if message is not already in our history |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1312 and add it if needed |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1313 @param room(muc.Room): room instance |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1314 @param user(muc.User, None): the user that sent the message |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1315 None if the message come from the room |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1316 @param message(muc.GroupChat): the parsed message |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1317 """ |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1318 if room.state != ROOM_STATE_SELF_PRESENCE: |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1319 log.warning(_( |
3028 | 1320 "received history in unexpected state in room {room} (state: " |
1321 "{state})").format(room = room.roomJID.userhost(), | |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1322 state = room.state)) |
2794
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1323 if not hasattr(room, "_history_d"): |
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1324 # XXX: this hack is due to buggy behaviour seen in the wild because of the |
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1325 # "mod_delay" prosody module being activated. This module add an |
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1326 # unexpected <delay> elements which break our workflow. |
3028 | 1327 log.warning(_("storing the unexpected message anyway, to avoid loss")) |
2794
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1328 # we have to restore URI which are stripped by wokkel parsing |
2979
f44a95f566d2
core, plugin XEP-0045: fix crashes when changing URIs:
Goffi <goffi@goffi.org>
parents:
2844
diff
changeset
|
1329 for c in message.element.elements(): |
2794
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1330 if c.uri is None: |
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1331 c.uri = C.NS_CLIENT |
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1332 mess_data = self.client.messageProt.parseMessage(message.element) |
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1333 message.element._mess_data = mess_data |
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1334 self._addToHistory(None, user, message) |
3028 | 1335 if mess_data['message'] or mess_data['subject']: |
2794
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1336 self.host.bridge.messageNew( |
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1337 *self.client.messageGetBridgeArgs(mess_data), |
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1338 profile=self.client.profile |
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1339 ) |
33fa70c102de
plugin XEP-0045: fixed crash when <delay> is used at an unexpected time.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1340 return |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1341 room._history_d.addCallback(self._addToHistory, user, message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1342 room._history_d.addErrback(self._addToHistoryEb) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1343 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1344 ## subject ## |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1345 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1346 def groupChatReceived(self, message): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1347 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1348 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
|
1349 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1350 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
|
1351 L{receivedGroupChat}, L{receivedSubject} or L{receivedHistory}. |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1352 """ |
3060
730bbed77a89
plugin XEP-0045: join / MAM history improvements:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
1353 # 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
|
1354 # FIXME: remove this once fixed upstream |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1355 room, user = self._getRoomUser(message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1356 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1357 if room is None: |
3028 | 1358 log.warning("No room found for message: {message}" |
2986
37b55d87d027
plugin XEP-0045: added a warning if a message is discarded because the room has not been found
Goffi <goffi@goffi.org>
parents:
2979
diff
changeset
|
1359 .format(message=message.toElement().toXml())) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1360 return |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1361 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1362 if message.subject is not None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1363 self.receivedSubject(room, user, message.subject) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1364 elif message.delay is None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1365 self.receivedGroupChat(room, user, message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1366 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1367 self.receivedHistory(room, user, message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1368 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1369 def subject(self, room, subject): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1370 return muc.MUCClientProtocol.subject(self, room, subject) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1371 |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1372 def _historyCb(self, __, room): |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1373 """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
|
1374 |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1375 this method will finish joining by: |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1376 - sending message to bridge |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1377 - calling fully_joined deferred |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1378 - sending stanza put in cache |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1379 - cleaning variables not needed anymore |
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1380 """ |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1381 args = self.plugin_parent._getRoomJoinedArgs(room, self.client.profile) |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2058
diff
changeset
|
1382 self.host.bridge.mucRoomJoined(*args) |
2581
395a3d1c2888
plugin XEP-0045: fixed joining workflow:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1383 room.fully_joined.callback(room) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1384 del room._history_d |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1385 del room._history_type |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1386 cache = room._cache |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1387 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
|
1388 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
|
1389 del room._cache_presence |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1390 for elem in cache: |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1391 self.client.xmlstream.dispatch(elem) |
3028 | 1392 for presence_data in cache_presence.values(): |
1393 if not presence_data['show'] and not presence_data['status']: | |
2991
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1394 # occupants are already sent in mucRoomJoined, so if we don't have |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1395 # 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
|
1396 continue |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1397 else: |
f4590ca2acff
plugin XEP-0045: avoid sending useless presence signals:
Goffi <goffi@goffi.org>
parents:
2990
diff
changeset
|
1398 self.userUpdatedStatus(**presence_data) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1399 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1400 def _historyEb(self, failure_, room): |
3028 | 1401 log.error("Error while managing history: {}".format(failure_)) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1402 self._historyCb(None, room) |
1256
4b27b9bf31b0
plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents:
1250
diff
changeset
|
1403 |
405
10b4f577d0c0
MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
1404 def receivedSubject(self, room, user, subject): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1405 # 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
|
1406 # 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
|
1407 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
|
1408 if room.state != ROOM_STATE_LIVE: |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1409 if room._history_type == HISTORY_LEGACY: |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1410 self.changeRoomState(room, ROOM_STATE_LIVE) |
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1411 room._history_d.addCallbacks(self._historyCb, self._historyEb, [room], errbackArgs=[room]) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1412 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1413 # the subject has been changed |
3028 | 1414 log.debug(_("New subject for room ({room_id}): {subject}").format(room_id = room.roomJID.full(), subject = subject)) |
2715
b35c84ea73cf
plugin XEP-0045: MAM implementation for MUC
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
1415 self.host.bridge.mucRoomNewSubject(room.roomJID.userhost(), subject, self.client.profile) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1416 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1417 ## disco ## |
1466
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1418 |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1419 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1420 return [disco.DiscoFeature(NS_MUC)] |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1421 |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1422 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1423 # 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
|
1424 # see XEP-0045 § 6.7 |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1425 return [] |