Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0045.py @ 2028:70bd7b242a9e
plugin XEP-0045: fixed options parameter handling in bridge callback
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 08 Aug 2016 00:50:01 +0200 |
parents | 6c51e8f17c92 |
children | b99bd02ea643 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1891
diff
changeset
|
1 #!/usr/bin/env python2 |
72 | 2 # -*- coding: utf-8 -*- |
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 |
1766 | 5 # Copyright (C) 2009-2016 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 |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
950
diff
changeset
|
23 log = getLogger(__name__) |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
24 from twisted.internet import defer |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
25 from twisted.words.protocols.jabber import jid |
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 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
27 from dateutil.tz import tzutc |
505
2402668b5d05
plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents:
488
diff
changeset
|
28 |
2402668b5d05
plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents:
488
diff
changeset
|
29 from sat.core import exceptions |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
30 from sat.memory import memory |
505
2402668b5d05
plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents:
488
diff
changeset
|
31 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
32 import calendar |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
33 import time |
319 | 34 import uuid |
1239
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
35 import copy |
72 | 36 |
1466
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
37 from wokkel import muc, disco, iwokkel |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
38 from sat.tools import xml_tools |
72 | 39 |
1466
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
40 from zope.interface import implements |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
41 |
72 | 42 |
43 PLUGIN_INFO = { | |
1986
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
44 "name": "XEP-0045 Plugin", |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
45 "import_name": "XEP-0045", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
46 "type": "XEP", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
47 "protocols": ["XEP-0045"], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
48 "dependencies": [], |
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
|
49 "recommendations": [C.TEXT_CMDS], |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
50 "main": "XEP_0045", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
51 "handler": "yes", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
52 "description": _("""Implementation of Multi-User Chat""") |
72 | 53 } |
54 | |
1466
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
55 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
|
56 AFFILIATIONS = ('owner', 'admin', 'member', 'none', 'outcast') |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
57 ROOM_USER_JOINED = 'ROOM_USER_JOINED' |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
58 ROOM_USER_LEFT = 'ROOM_USER_LEFT' |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
59 OCCUPANT_KEYS = ('nick', 'entity', 'affiliation', 'role') |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
60 ENTITY_TYPE_MUC = "MUC" |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
61 |
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
|
62 CONFIG_SECTION = u'plugin 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
|
63 |
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
|
64 default_conf = {"default_muc": u'sat@chat.jabberfr.org'} |
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
|
65 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
66 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
67 class XEP_0045(object): |
72 | 68 |
69 def __init__(self, host): | |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
950
diff
changeset
|
70 log.info(_("Plugin XEP_0045 initialization")) |
72 | 71 self.host = host |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
72 self._sessions = memory.Sessions() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
73 host.bridge.addMethod("mucJoin", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._join, async=True) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
74 host.bridge.addMethod("mucNick", ".plugin", in_sign='sss', out_sign='', method=self._nick) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
75 host.bridge.addMethod("mucLeave", ".plugin", in_sign='ss', out_sign='', method=self._leave, async=True) |
2021
6c51e8f17c92
plugin XEP-0045: added bridge method to change subject
Goffi <goffi@goffi.org>
parents:
1992
diff
changeset
|
76 host.bridge.addMethod("mucSubject", ".plugin", in_sign='sss', out_sign='', method=self._subject) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
77 host.bridge.addMethod("mucGetRoomsJoined", ".plugin", in_sign='s', out_sign='a(sa{sa{ss}}ss)', method=self._getRoomsJoined) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
78 host.bridge.addMethod("mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
79 host.bridge.addMethod("mucConfigureRoom", ".plugin", in_sign='ss', out_sign='s', method=self._configureRoom, async=True) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
80 host.bridge.addMethod("mucGetDefaultService", ".plugin", in_sign='', out_sign='s', method=self.getDefaultMUC) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
81 host.bridge.addSignal("mucRoomJoined", ".plugin", signature='sa{sa{ss}}sss') # args: room_jid, occupants, user_nick, subject, profile |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
82 host.bridge.addSignal("mucRoomLeft", ".plugin", signature='ss') # args: room_jid, profile |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
83 host.bridge.addSignal("mucRoomUserChangedNick", ".plugin", signature='ssss') # args: room_jid, old_nick, new_nick, profile |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
84 host.bridge.addSignal("mucRoomNewSubject", ".plugin", signature='sss') # args: room_jid, subject, profile |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
85 self.__submit_conf_id = host.registerCallback(self._submitConfiguration, with_data=True) |
1990
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
86 self._room_join_id = host.registerCallback(self._UIRoomJoinCb, with_data=True) |
1538
55967cf161b1
reverted patch ad4ec8d9235e: there must not be security limit on room configuration
Goffi <goffi@goffi.org>
parents:
1466
diff
changeset
|
87 host.importMenu((D_("MUC"), D_("configure")), self._configureRoomMenu, security_limit=0, 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
|
88 try: |
1992
d5befe7253aa
plugin XEP-0045: fixed typo in text commands
Goffi <goffi@goffi.org>
parents:
1990
diff
changeset
|
89 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
|
90 except KeyError: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
91 log.info(_(u"Text commands not available")) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
92 else: |
1992
d5befe7253aa
plugin XEP-0045: fixed typo in text commands
Goffi <goffi@goffi.org>
parents:
1990
diff
changeset
|
93 self.text_cmds.registerTextCommands(self) |
d5befe7253aa
plugin XEP-0045: fixed typo in text commands
Goffi <goffi@goffi.org>
parents:
1990
diff
changeset
|
94 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
|
95 |
1239
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
96 host.trigger.add("presence_available", self.presenceTrigger) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
97 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=1000000) |
1239
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
98 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
99 def profileConnected(self, profile): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
100 def assign_service(service): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
101 client = self.host.getClient(profile) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
102 client.muc_service = service |
1552
e0bde0d0b321
core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents:
1538
diff
changeset
|
103 return self.getMUCService(profile=profile).addCallback(assign_service) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
104 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
105 def MessageReceivedTrigger(self, client, message_elt, post_treat): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
106 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
107 if message_elt.subject or message_elt.delay: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
108 return False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
109 from_jid = jid.JID(message_elt['from']) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
110 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
|
111 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
|
112 room = client._muc_client.joined_rooms[room_jid] |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
113 if not room._room_ok: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
114 log.warning(u"Received non delayed message in a room before its initialisation: {}".format(message_elt.toXml())) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
115 room._cache.append(message_elt) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
116 return False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
117 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
118 log.warning(u"Received groupchat message for a room which has not been joined, ignoring it: {}".format(message_elt.toXml())) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
119 return False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
120 return True |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
121 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
122 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
|
123 """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
|
124 |
e8731b02f5ea
plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents:
1082
diff
changeset
|
125 @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
|
126 """ |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
127 if room_jid not 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
|
128 raise exceptions.NotFound(_(u"This room has not been joined")) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
129 |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
130 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
|
131 """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
|
132 |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
133 @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
|
134 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
135 try: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
136 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
|
137 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
|
138 return False |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
139 else: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
140 return True |
1083
e8731b02f5ea
plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents:
1082
diff
changeset
|
141 |
1990
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
142 def _UIRoomJoinCb(self, data, profile): |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
143 room_jid = jid.JID(data['index']) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
144 client = self.host.getClient(profile) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
145 self.join(client, room_jid) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
146 return {} |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
147 |
1986
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
148 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
|
149 """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
|
150 if C.bool(data.get(C.XMLUI_DATA_CANCELLED, "false")): |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
151 log.info(u"room join for {} is cancelled".format(room_jid.userhost())) |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
152 raise failure.Failure(exceptions.CancelError(D_(u"Room joining cancelled by user"))) |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
153 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
|
154 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
|
155 |
1990
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
156 def _showListUI(self, items, client, service): |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
157 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
|
158 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
|
159 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
|
160 for item in items: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
161 adv_list.setRowIndex(item.entity.full()) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
162 xmlui.addText(item.name) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
163 adv_list.end() |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
164 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
|
165 |
1986
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
166 def _joinCb(self, room, client, room_jid, nick): |
72 | 167 """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
|
168 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
|
169 # 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
|
170 # 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
|
171 # a proper configuration management should be done |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
172 log.debug(_(u"room locked !")) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
173 d = client._muc_client.configure(room.roomJID, {}) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
174 d.addErrback(lambda dummy: log.error(_(u'Error while configuring the room'))) |
319 | 175 return room |
176 | |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
177 def _joinEb(self, failure, client, room_jid, nick, password): |
72 | 178 """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
|
179 try: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
180 condition = failure.value.condition |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
181 except AttributeError: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
182 msg_suffix = '' |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
183 else: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
184 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
|
185 # 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
|
186 nick += '_' |
1986
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
187 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
|
188 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
|
189 # room is restricted, we need a password |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
190 password_ui = xml_tools.XMLUI("form", title=D_(u'Room {} is restricted').format(room_jid.userhost()), submit_id='') |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 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
|
195 return d |
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
196 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
197 msg_suffix = ' with condition "{}"'.format(failure.value.condition) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
198 |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
199 mess = D_(u"Error while joining the room {room}{suffix}".format( |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
200 room = room_jid.userhost(), suffix = msg_suffix)) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
950
diff
changeset
|
201 log.error(mess) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
202 xmlui = xml_tools.note(mess, D_(u"Group chat error"), level=C.XMLUI_DATA_LVL_ERROR) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
203 self.host.actionNew({'xmlui': xmlui.toXml()}, profile=client.profile) |
72 | 204 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
205 @staticmethod |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
206 def _getOccupants(room): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
207 """Get occupants of a room in a form suitable for bridge""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
208 return {u.nick: {k:unicode(getattr(u,k) or '') for k in OCCUPANT_KEYS} for u in room.roster.values()} |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
209 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
214 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
|
215 """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
|
216 result = [] |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
217 for room in client._muc_client.joined_rooms.values(): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
218 if room._room_ok: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
219 result.append((room.roomJID.userhost(), self._getOccupants(room), room.nick, room.subject)) |
78
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
77
diff
changeset
|
220 return result |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
77
diff
changeset
|
221 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
222 def getRoomNick(self, client, room_jid): |
93 | 223 """return nick used in room by user |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
224 |
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
|
225 @param room_jid (jid.JID): JID of the room |
93 | 226 @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
|
227 @return: nick or empty string in case of error |
715
f47d7c09c60b
plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents:
713
diff
changeset
|
228 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
229 try: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
230 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
|
231 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
|
232 return '' # FIXME: should not return empty string but raise the error |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
233 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
|
234 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
235 # FIXME: broken, to be removed ! |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
236 # def getRoomEntityNick(self, client, room_jid, entity_jid, =True): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
237 # """Returns the nick of the given user in the room. |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
238 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
239 # @param room (wokkel.muc.Room): the room |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
240 # @param user (jid.JID): bare JID of the user |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
241 # @param secure (bool): set to True for a secure check |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
242 # @return: unicode or None if the user didn't join the room. |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
243 # """ |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
244 # for user in room.roster.values(): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
245 # if user.entity is not None: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
246 # if user.entity.userhostJID() == user_jid.userhostJID(): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
247 # return user.nick |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
248 # elif not secure: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
249 # # FIXME: this is NOT ENOUGH to check an identity!! |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
250 # # See in which conditions user.entity could be None. |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
251 # if user.nick == user_jid.user: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
252 # return user.nick |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
253 # return None |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
254 |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
255 # def getRoomNicksOfUsers(self, room, users=[], secure=True): |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
256 # """Returns the nicks of the given users in the room. |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
257 |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
258 # @param room (wokkel.muc.Room): the room |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
259 # @param users (list[jid.JID]): list of users |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
260 # @param secure (True): set to True for a secure check |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
261 # @return: a couple (x, y) with: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
262 # - x (list[unicode]): nicks of the users who are in the room |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
263 # - y (list[jid.JID]): JID of the missing users. |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
264 # """ |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
265 # nicks = [] |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
266 # missing = [] |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
267 # for user in users: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
268 # nick = self.getRoomNickOfUser(room, user, secure) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
269 # if nick is None: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
270 # missing.append(user) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
271 # else: |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
272 # nicks.append(nick) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
273 # return nicks, missing |
715
f47d7c09c60b
plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents:
713
diff
changeset
|
274 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
275 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
|
276 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
|
277 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
|
278 d.addCallback(lambda xmlui: xmlui.toXml()) |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
279 return d |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
280 |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
281 def _configureRoomMenu(self, menu_data, profile): |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
282 """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
|
283 |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
284 @param menu_data: %(menu_data)s |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
285 @param profile: %(doc_profile)s |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
286 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
287 client = self.host.getClient(profile) |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
288 try: |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
289 room_jid = jid.JID(menu_data['room_jid']) |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
290 except KeyError: |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
291 log.error(_("room_jid key is not present !")) |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
292 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
|
293 |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
294 def xmluiReceived(xmlui): |
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
295 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
|
296 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
|
297 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
298 def configureRoom(self, client, room_jid): |
1094
4286a19e9e8a
pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents:
1083
diff
changeset
|
299 """return the room configuration form |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
300 |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
301 @param room: jid of the room to configure |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
302 @return: configuration form as XMLUI |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
303 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
304 self.checkRoomJoined(client, room_jid) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
305 |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
306 def config2XMLUI(result): |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
307 if not result: |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
308 return "" |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
309 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
|
310 session_data["room_jid"] = room_jid |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
311 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
|
312 xmlui.session_id = session_id |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
313 return xmlui |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
314 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
315 d = client._muc_client.getConfiguration(room_jid) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
316 d.addCallback(config2XMLUI) |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
317 return d |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
318 |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
319 def _submitConfiguration(self, raw_data, profile): |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
320 client = self.host.getClient(profile) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
321 try: |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
322 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
|
323 except KeyError: |
1068
1513511a0586
plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
324 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
|
325 _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
|
326 _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
|
327 return defer.succeed({'xmlui': _dialog.toXml()}) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
328 |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
329 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
|
330 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
|
331 _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
|
332 _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
|
333 d.addCallback(lambda ignore: {'xmlui': _dialog.toXml()}) |
801
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
334 del self._sessions[raw_data["session_id"]] |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
335 return d |
02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents:
791
diff
changeset
|
336 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
337 def isNickInRoom(self, client, room_jid, nick): |
522
3446ce33247d
plugin XEP-0045: added isNickInRoom method
Goffi <goffi@goffi.org>
parents:
519
diff
changeset
|
338 """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
|
339 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
|
340 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
|
341 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
342 @defer.inlineCallbacks |
1552
e0bde0d0b321
core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents:
1538
diff
changeset
|
343 def getMUCService(self, jid_=None, profile=C.PROF_KEY_NONE): |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
344 """Return first found MUC service of an entity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
345 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
346 @param jid_: entity which may have a MUC service, or None for our own server |
1552
e0bde0d0b321
core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents:
1538
diff
changeset
|
347 @param profile: %(doc_profile)s |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
348 """ |
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
|
349 muc_service = None |
1552
e0bde0d0b321
core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents:
1538
diff
changeset
|
350 services = yield self.host.findServiceEntities("conference", "text", jid_, profile=profile) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
351 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
|
352 if ".irc." not in service.userhost(): |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
353 # FIXME: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
354 # 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
|
355 # 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
|
356 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
|
357 break |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
358 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
|
359 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
360 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
|
361 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
|
362 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
|
363 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
364 def getUniqueName(self, client, muc_service=None): |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
365 """Return unique name for a room, avoiding collision |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
366 |
1356
c01cbd8fc8dd
plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
367 @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
|
368 @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
|
369 """ |
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
|
370 # TODO: we should use #RFC-0045 10.1.4 when available here |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
371 room_name = unicode(uuid.uuid4()) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
372 if muc_service is None: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
373 try: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
374 muc_service = client.muc_service |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
375 except AttributeError: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
376 raise exceptions.NotReady(u"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
|
377 if muc_service is None: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
950
diff
changeset
|
378 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
|
379 raise exceptions.FeatureNotFound |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
380 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
928
diff
changeset
|
381 muc_service = muc_service.userhost() |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
382 return jid.JID(u"{}@{}".format(room_name, muc_service)) |
319 | 383 |
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
|
384 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
|
385 """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
|
386 |
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
|
387 @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
|
388 """ |
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
|
389 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
|
390 |
2028
70bd7b242a9e
plugin XEP-0045: fixed options parameter handling in bridge callback
Goffi <goffi@goffi.org>
parents:
2021
diff
changeset
|
391 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
|
392 """join method used by bridge |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
393 |
1356
c01cbd8fc8dd
plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
394 @return: unicode (the room bare) |
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
|
395 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
396 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
|
397 if room_jid_s: |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
398 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
|
399 try: |
c01cbd8fc8dd
plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
400 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
|
401 except (RuntimeError, jid.InvalidFormat, AttributeError): |
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
|
402 return defer.fail(jid.InvalidFormat(_(u"Invalid room identifier: '%s'. Please give a room short or full identifier like 'room' or 'room@%s'.") % (room_jid_s, unicode(muc_service)))) |
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
|
403 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
|
404 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
|
405 else: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
406 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
|
407 # 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
|
408 d = self.join(client, room_jid, nick, options or None) |
1356
c01cbd8fc8dd
plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
409 return d.addCallback(lambda room: room.roomJID.userhost()) |
505
2402668b5d05
plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents:
488
diff
changeset
|
410 |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
411 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
|
412 if not nick: |
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
413 nick = client.jid.user |
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
414 if options is None: |
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
415 options = {} |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
416 def _errDeferred(exc_obj=Exception, txt=u'Error while joining room'): |
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
417 d = defer.Deferred() |
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
418 d.errback(exc_obj(txt)) |
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
419 return d |
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
420 |
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
421 if room_jid in client._muc_client.joined_rooms: |
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
422 log.warning(_(u'{profile} is already in room {room_jid}').format(profile=client.profile, room_jid = room_jid.userhost())) |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
423 raise failure.Failure(exceptions.ConflictError(_(u"The room has already been joined"))) |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
424 log.info(_(u"[{profile}] is joining room {room} with nick {nick}").format(profile=client.profile, room=room_jid.userhost(), nick=nick)) |
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
425 |
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
426 password = options["password"] if "password" in options else None |
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
427 |
1986
fbd313cfd40b
plugin xep-0045: ask for password when getting a "not-allowed" error
Goffi <goffi@goffi.org>
parents:
1984
diff
changeset
|
428 return client._muc_client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, (client, room_jid, nick), errbackArgs=(client, room_jid, nick, password)) |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
429 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
430 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
|
431 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
|
432 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
|
433 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
434 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
|
435 """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
|
436 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
|
437 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
|
438 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
443 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
|
444 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
|
445 return client._muc_client.leave(room_jid) |
505
2402668b5d05
plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents:
488
diff
changeset
|
446 |
2021
6c51e8f17c92
plugin XEP-0045: added bridge method to change subject
Goffi <goffi@goffi.org>
parents:
1992
diff
changeset
|
447 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
|
448 client = self.host.getClient(profile_key) |
6c51e8f17c92
plugin XEP-0045: added bridge method to change subject
Goffi <goffi@goffi.org>
parents:
1992
diff
changeset
|
449 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
|
450 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
451 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
|
452 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
|
453 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
|
454 |
72 | 455 def getHandler(self, profile): |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
456 # 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
|
457 client = self.host.getClient(profile) |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
458 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
|
459 return muc_client |
72 | 460 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
461 def kick(self, client, nick, room_jid, options=None): |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
462 """ |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
463 Kick a participant from the room |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
464 @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
|
465 @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
|
466 @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
|
467 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
468 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
|
469 options = {} |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
470 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
|
471 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
|
472 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
473 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
|
474 """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
|
475 |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
476 @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
|
477 @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
|
478 @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
|
479 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
480 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
|
481 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
|
482 options = {} |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
483 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
|
484 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
|
485 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
|
486 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
487 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
|
488 """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
|
489 |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
490 @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
|
491 @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
|
492 @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
|
493 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
494 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
|
495 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
|
496 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
|
497 assert 'affiliation' in options |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
498 # 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
|
499 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
|
500 |
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
|
501 # 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
|
502 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
503 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
|
504 """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
|
505 |
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
|
506 @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
|
507 - 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
|
508 """ |
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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 |
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
|
514 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
|
515 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
516 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
|
517 """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
|
518 |
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
|
519 @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
|
520 - 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
|
521 """ |
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
|
522 if mess_data["unparsed"].strip(): |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
523 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
|
524 nick = (self.getRoomNick(client, room_jid) or |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
525 client.jid.user) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
526 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
|
527 |
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
|
528 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
|
529 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
530 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
|
531 """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
|
532 |
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
|
533 @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
|
534 - 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
|
535 """ |
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
|
536 if mess_data["unparsed"].strip(): |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
537 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
|
538 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
|
539 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
|
540 |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
541 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
|
542 |
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
|
543 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
|
544 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
545 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
|
546 """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
|
547 |
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
|
548 @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
|
549 - 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
|
550 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
551 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
|
552 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
553 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
|
554 """kick a room member |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
555 |
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
|
556 @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
|
557 - 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
|
558 """ |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
559 options = mess_data["unparsed"].strip().split() |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
560 try: |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
561 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
|
562 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
|
563 except (IndexError, AssertionError): |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
564 feedback = _(u"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
|
565 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
|
566 return False |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
567 |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
568 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
|
569 |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
570 def cb(dummy): |
1890
0a45bc8e7cf4
plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents:
1789
diff
changeset
|
571 feedback_msg = _(u'You have kicked {}').format(nick) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
572 if len(options) > 1: |
1890
0a45bc8e7cf4
plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents:
1789
diff
changeset
|
573 feedback_msg += _(u' for the following reason: {}').format(options[1]) |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
574 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
|
575 return True |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
576 d.addCallback(cb) |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
577 return d |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
578 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
579 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
|
580 """ban an entity from the room |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
581 |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
582 @command (group): (JID) [reason] |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
583 - 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
|
584 - 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
|
585 """ |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
586 options = mess_data["unparsed"].strip().split() |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
587 try: |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
588 jid_s = options[0] |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
589 entity_jid = jid.JID(jid_s).userhostJID() |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
590 assert(entity_jid.user) |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
591 assert(entity_jid.host) |
1742
244a605623d6
complete the Exception's list when catching JID error:
souliane <souliane@mailoo.org>
parents:
1700
diff
changeset
|
592 except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, AssertionError): |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
593 feedback = _(u"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
|
594 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
|
595 return False |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
596 |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
597 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
|
598 |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
599 def cb(dummy): |
1890
0a45bc8e7cf4
plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents:
1789
diff
changeset
|
600 feedback_msg = _(u'You have banned {}').format(entity_jid) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
601 if len(options) > 1: |
1890
0a45bc8e7cf4
plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents:
1789
diff
changeset
|
602 feedback_msg += _(u' for the following reason: {}').format(options[1]) |
1989
757c512fe06c
plugin XEP-0045: various fixes/improvments:
Goffi <goffi@goffi.org>
parents:
1986
diff
changeset
|
603 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
|
604 return True |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
605 d.addCallback(cb) |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
606 return d |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
607 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
608 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
|
609 """affiliate an entity to the room |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
610 |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
611 @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
|
612 - 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
|
613 - owner: grant owner privileges |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
614 - admin: grant admin privileges |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
615 - member: grant member privileges |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
616 - none: reset entity privileges |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
617 - outcast: ban entity |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
618 """ |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
619 options = mess_data["unparsed"].strip().split() |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
620 try: |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
621 jid_s = options[0] |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
622 entity_jid = jid.JID(jid_s).userhostJID() |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
623 assert(entity_jid.user) |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
624 assert(entity_jid.host) |
1742
244a605623d6
complete the Exception's list when catching JID error:
souliane <souliane@mailoo.org>
parents:
1700
diff
changeset
|
625 except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, AssertionError): |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
626 feedback = _(u"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
|
627 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
|
628 return False |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
629 |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
630 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
|
631 if affiliation not in AFFILIATIONS: |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
632 feedback = _(u"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
|
633 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
|
634 return False |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
635 |
1977
bdc6a5b07922
plugin XEP-0045: fixed calls to join, nick, kick, ban and affiliate
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
636 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
|
637 |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
638 def cb(dummy): |
1890
0a45bc8e7cf4
plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents:
1789
diff
changeset
|
639 feedback_msg = _(u'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
|
640 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
|
641 return True |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
642 d.addCallback(cb) |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
643 return d |
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
644 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
645 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
|
646 """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
|
647 |
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
|
648 @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
|
649 - 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
|
650 """ |
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
|
651 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
|
652 |
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
|
653 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
|
654 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
|
655 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
|
656 |
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 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
|
658 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
659 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
|
660 """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
|
661 |
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 @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
|
663 - 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
|
664 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
665 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
|
666 |
1990
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
667 def cmd_list(self, client, mess_data): |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
668 """list available rooms in a muc server |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
669 |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
670 @command (all): [MUC_SERVICE] |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
671 - MUC_SERVICE: service to request |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
672 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
|
673 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
|
674 """ |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
675 unparsed = mess_data["unparsed"].strip() |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
676 try: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
677 service = jid.JID(unparsed) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
678 except RuntimeError: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
679 if mess_data['type'] == C.MESS_TYPE_GROUPCHAT: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
680 room_jid = mess_data["to"] |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
681 service = jid.JID(room_jid.host) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
682 elif client.muc_service is not None: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
683 service = client.muc_service |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
684 else: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
685 msg = D_(u"No known default MUC service".format(unparsed)) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
686 self.text_cmds.feedBack(client, msg, mess_data) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
687 return False |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
688 except jid.InvalidFormat: |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
689 msg = D_(u"{} is not a valid JID!".format(unparsed)) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
690 self.text_cmds.feedBack(client, msg, mess_data) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
691 return False |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
692 d = self.host.getDiscoItems(service, profile=client.profile) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
693 d.addCallback(self._showListUI, client, service) |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
694 |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
695 return False |
dfbe0bb056dc
plugin XEP-0045: added /list text command:
Goffi <goffi@goffi.org>
parents:
1989
diff
changeset
|
696 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
697 def _whois(self, client, whois_msg, mess_data, target_jid): |
1199 | 698 """ 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
|
699 if mess_data['type'] != "groupchat": |
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
700 return |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
701 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
|
702 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
|
703 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
|
704 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
|
705 return |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
706 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
|
707 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
|
708 if user.entity: |
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
709 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
|
710 if user.affiliation != 'none': |
928
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
711 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
|
712 if user.role != 'none': |
928
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
713 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
|
714 if user.status: |
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
715 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
|
716 if user.show: |
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
717 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
|
718 |
1239
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
719 def presenceTrigger(self, presence_elt, client): |
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
720 # XXX: shouldn't it be done by the server ?!! |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
721 muc_client = client._muc_client |
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
|
722 for room_jid, room in muc_client.joined_rooms.iteritems(): |
1239
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
723 elt = copy.deepcopy(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
|
724 elt['to'] = room_jid.userhost() + '/' + room.nick |
1239
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
725 client.presence.send(elt) |
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
726 return True |
b6dbac8ee485
plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
727 |
72 | 728 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
729 class SatMUCClient(muc.MUCClient): |
1466
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
730 implements(iwokkel.IDisco) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
731 |
72 | 732 def __init__(self, plugin_parent): |
733 self.plugin_parent = plugin_parent | |
734 self.host = plugin_parent.host | |
735 muc.MUCClient.__init__(self) | |
78
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
77
diff
changeset
|
736 self.rec_subjects = {} |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
737 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
|
738 # and to discard userJoinedRoom signal in this case |
72 | 739 print "init SatMUCClient OK" |
515
29b5ef129488
plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
740 |
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
|
741 @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
|
742 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
|
743 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
|
744 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
745 def _addRoom(self, room): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
746 super(SatMUCClient, self)._addRoom(room) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
747 room._roster_ok = False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
748 room._room_ok = None # False when roster, history and subject are available |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
749 # True when new messages are saved to database |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
750 room._history_d = defer.Deferred() # use to send bridge signal once backlog are written in history |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
751 room._history_d.callback(None) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
752 room._cache = [] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
753 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
754 def _gotLastDbHistory(self, mess_data_list, room_jid, nick, password): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
755 if mess_data_list: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
756 timestamp = mess_data_list[0][1] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
757 # 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
|
758 # 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
|
759 seconds = int(time.time() - timestamp) - 1 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
760 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
761 seconds = None |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
762 d = super(SatMUCClient, self).join(room_jid, nick, muc.HistoryOptions(seconds=seconds), password) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
763 return d |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
764 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
765 def join(self, room_jid, nick, password=None): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
766 d = self.host.memory.historyGet(self.parent.jid.userhostJID(), room_jid, 1, True, profile=self.parent.profile) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
767 d.addCallback(self._gotLastDbHistory, room_jid, nick, password) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
768 return d |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
769 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
770 ## presence/roster ## |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
771 |
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
|
772 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
|
773 """ |
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
|
774 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
|
775 """ |
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
|
776 # 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
|
777 # (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
|
778 |
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
|
779 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
|
780 |
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
|
781 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
|
782 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
|
783 |
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
|
784 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
|
785 nick = presence.sender.resource |
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
|
786 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
|
787 |
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
|
788 # 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
|
789 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
|
790 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
|
791 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
|
792 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
|
793 |
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
|
794 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
|
795 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
|
796 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
|
797 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
|
798 self.userJoinedRoom(room, user) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
799 |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
800 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
|
801 # 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
|
802 """ |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
803 Unavailable presence was received. |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
804 |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
805 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
|
806 left the room. |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
807 """ |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
808 room, user = self._getRoomUser(presence) |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
809 |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
810 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
|
811 return |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
812 |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
813 room.removeUser(user) |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
814 |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
815 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
|
816 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
|
817 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
|
818 else: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
819 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
|
820 self.userLeftRoom(room, user) |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
821 |
74
6e3a06b4dd36
plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
822 def userJoinedRoom(self, room, user): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
823 if user.nick == room.nick: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
824 # we have received our own nick, this mean that the full room roster was received |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
825 room._roster_ok = True |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
826 log.debug(u"room {room} joined with nick {nick}".format(room=room.occupantJID.userhost(), nick=user.nick)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
827 # We set type so we don't have use a deferred with disco to check entity type |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
828 self.host.memory.updateEntityData(room.roomJID, C.ENTITY_TYPE, ENTITY_TYPE_MUC, profile_key=self.parent.profile) |
1984
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
829 elif not room._room_ok: |
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
830 log.warning(u"Received user presence data in a room before its initialisation (and after our own presence)," |
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
831 "this is not standard! Ignoring it: {} ({})".format( |
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
832 room.roomJID.userhost(), |
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
833 user.nick)) |
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
834 return |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
835 elif room._roster_ok: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
836 try: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
837 self._changing_nicks.remove(user.nick) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
838 except KeyError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
839 # this is a new user |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
840 log.debug(_(u"user {nick} has joined room {room_id}").format(nick=user.nick, room_id=room.occupantJID.userhost())) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
841 if not self.host.trigger.point("MUC user joined", room, user, self.parent.profile): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
842 return |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
843 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
844 extra = {'info_type': ROOM_USER_JOINED, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
845 'user_affiliation': user.affiliation, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
846 'user_role': user.role, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
847 'user_nick': user.nick |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
848 } |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
849 if user.entity is not None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
850 extra['user_entity'] = user.entity.full() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
851 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
|
852 "from": room.roomJID, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
853 "to": self.parent.jid, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
854 "uid": unicode(uuid.uuid4()), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
855 "message": {'': D_(u"=> {} has joined the room").format(user.nick)}, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
856 "subject": {}, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
857 "type": C.MESS_TYPE_INFO, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
858 "extra": extra, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
859 "timestamp": time.time(), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
860 } |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
861 self.host.messageAddToHistory(mess_data, self.parent) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
862 self.host.messageSendToBridge(mess_data, self.parent) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
863 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
864 |
74
6e3a06b4dd36
plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
865 def userLeftRoom(self, room, user): |
715
f47d7c09c60b
plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents:
713
diff
changeset
|
866 if not self.host.trigger.point("MUC user left", room, user, self.parent.profile): |
f47d7c09c60b
plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents:
713
diff
changeset
|
867 return |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
868 if user.nick == room.nick: |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
869 # we left the room |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
870 room_jid_s = room.roomJID.userhost() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
871 log.info(_(u"Room ({room}) left ({profile})").format( |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
872 room = room_jid_s, profile = self.parent.profile)) |
1082
246712d2e7bc
plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents:
1068
diff
changeset
|
873 self.host.memory.delEntityCache(room.roomJID, profile_key=self.parent.profile) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
874 self.host.bridge.mucRoomLeft(room.roomJID.userhost(), self.parent.profile) |
1984
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
875 elif not room._room_ok: |
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
876 log.warning(u"Received user presence data in a room before its initialisation (and after our own presence)," |
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
877 "this is not standard! Ignoring it: {} ({})".format( |
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
878 room.roomJID.userhost(), |
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
879 user.nick)) |
de4fac507dc4
xep-0045: ignore non standard presence received between own presence and room subject
Goffi <goffi@goffi.org>
parents:
1977
diff
changeset
|
880 return |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
881 else: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
882 log.debug(_(u"user {nick} left room {room_id}").format(nick=user.nick, room_id=room.occupantJID.userhost())) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
883 extra = {'info_type': ROOM_USER_LEFT, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
884 'user_affiliation': user.affiliation, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
885 'user_role': user.role, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
886 'user_nick': user.nick |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
887 } |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
888 if user.entity is not None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
889 extra['user_entity'] = user.entity.full() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
890 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
|
891 "from": room.roomJID, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
892 "to": self.parent.jid, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
893 "uid": unicode(uuid.uuid4()), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
894 "message": {'': D_(u"<= {} has left the room").format(user.nick)}, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
895 "subject": {}, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
896 "type": C.MESS_TYPE_INFO, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
897 "extra": extra, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
898 "timestamp": time.time(), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
899 } |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
900 self.host.messageAddToHistory(mess_data, self.parent) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
901 self.host.messageSendToBridge(mess_data, self.parent) |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
902 |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
505
diff
changeset
|
903 def userChangedNick(self, room, user, new_nick): |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
904 self.host.bridge.mucRoomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile) |
72 | 905 |
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
|
906 def userUpdatedStatus(self, room, user, show, status): |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
907 self.host.bridge.presenceUpdate(room.roomJID.userhost() + '/' + user.nick, show or '', 0, {C.PRESENCE_STATUSES_DEFAULT: status or ''}, self.parent.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
|
908 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
909 ## messages ## |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
910 |
1256
4b27b9bf31b0
plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents:
1250
diff
changeset
|
911 def receivedGroupChat(self, room, user, body): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1407
diff
changeset
|
912 log.debug(u'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
|
913 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
914 def _addToHistory(self, dummy, user, message): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
915 # we check if message is not in history |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
916 # and raise ConflictError else |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
917 stamp = message.delay.stamp.astimezone(tzutc()).timetuple() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
918 timestamp = float(calendar.timegm(stamp)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
919 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
|
920 "from": message.sender, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
921 "to": message.recipient, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
922 "uid": unicode(uuid.uuid4()), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
923 "type": C.MESS_TYPE_GROUPCHAT, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
924 "extra": {}, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
925 "timestamp": timestamp, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
926 "received_timestamp": unicode(time.time()), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
927 } |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
928 # FIXME: message and subject don't handle xml:lang |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
929 data['message'] = {'': message.body} if message.body is not None else {} |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
930 data['subject'] = {'': message.subject} if message.subject is not None else {} |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
931 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
932 if data['message'] or data['subject']: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
933 return self.host.memory.addToHistory(self.parent, data) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
934 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
935 return defer.succeed(None) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
936 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
937 def _addToHistoryEb(self, failure): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
938 failure.trap(exceptions.CancelError) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
939 |
1256
4b27b9bf31b0
plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents:
1250
diff
changeset
|
940 def receivedHistory(self, room, user, message): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
941 """Called when history (backlog) message are received |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
942 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
943 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
|
944 and add it if needed |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
945 @param room(muc.Room): room instance |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
946 @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
|
947 None if the message come from the room |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
948 @param message(muc.GroupChat): the parsed message |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
949 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
950 room._history_d.addCallback(self._addToHistory, user, message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
951 room._history_d.addErrback(self._addToHistoryEb) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
952 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
953 ## subject ## |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
954 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
955 def groupChatReceived(self, message): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
956 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
957 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
|
958 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
959 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
|
960 L{receivedGroupChat}, L{receivedSubject} or L{receivedHistory}. |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
961 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
962 # We override this method to fix subject handling |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
963 # FIXME: remove this merge fixed upstream |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
964 room, user = self._getRoomUser(message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
965 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
966 if room is None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
967 return |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
968 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
969 if message.subject is not None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
970 self.receivedSubject(room, user, message.subject) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
971 elif message.delay is None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
972 self.receivedGroupChat(room, user, message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
973 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
974 self.receivedHistory(room, user, message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
975 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
976 def subject(self, room, subject): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
977 return muc.MUCClientProtocol.subject(self, room, subject) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
978 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
979 def _historyCb(self, dummy, room): |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
980 self.host.bridge.mucRoomJoined( |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
981 room.roomJID.userhost(), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
982 XEP_0045._getOccupants(room), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
983 room.nick, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
984 room.subject, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
985 self.parent.profile) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
986 del room._history_d |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
987 cache = room._cache |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
988 del room._cache |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
989 room._room_ok = True |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
990 for elem in cache: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
991 self.parent.xmlstream.dispatch(elem) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
992 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
993 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
994 def _historyEb(self, failure_, room): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
995 log.error(u"Error while managing history: {}".format(failure_)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
996 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
|
997 |
405
10b4f577d0c0
MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
998 def receivedSubject(self, room, user, subject): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
999 # 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
|
1000 # 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
|
1001 room.subject = subject # FIXME: subject doesn't handle xml:lang |
405
10b4f577d0c0
MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
1002 self.rec_subjects[room.roomJID.userhost()] = (room.roomJID.userhost(), subject) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1003 if room._room_ok is None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1004 # this is the first subject we receive |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1005 # that mean that we have received everything we need |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1006 room._room_ok = False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1007 room._history_d.addCallbacks(self._historyCb, self._historyEb, [room], errbackArgs=[room]) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1008 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1009 # the subject has been changed |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1010 log.debug(_(u"New subject for room ({room_id}): {subject}").format(room_id = room.roomJID.full(), subject = subject)) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
1011 self.host.bridge.mucRoomNewSubject(room.roomJID.userhost(), subject, self.parent.profile) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1012 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1013 ## disco ## |
1466
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1014 |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1015 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1016 return [disco.DiscoFeature(NS_MUC)] |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1017 |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1018 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1019 # 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
|
1020 # see XEP-0045 § 6.7 |
2184d5f496b5
plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
1021 return [] |