annotate src/plugins/plugin_xep_0249.py @ 2208:c316c6f6a737

plugin invitations: fixed leak of uuid in jid
author Goffi <goffi@goffi.org>
date Sun, 26 Mar 2017 21:23:03 +0200
parents 33c8c4973743
children 8b37a62336c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for managing xep-0249
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
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: 594
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: 594
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: 594
diff changeset
10 # (at your option) any later version.
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
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: 594
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: 594
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: 594
diff changeset
15 # GNU Affero General Public License for more details.
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
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: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
19
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
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: 844
diff changeset
21 from sat.core.constants import Const as C
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
22 from sat.core import exceptions
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
23 from sat.core.log import getLogger
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
24 log = getLogger(__name__)
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
25 from sat.tools import xml_tools
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from twisted.words.xish import domish
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
27 from twisted.words.protocols.jabber import jid
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
28
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from zope.interface import implements
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
30
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
31 from wokkel import disco, iwokkel
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
32
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
33
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
34 try:
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from twisted.words.protocols.xmlstream import XMPPHandler
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
36 except ImportError:
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from wokkel.subprotocols import XMPPHandler
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
38
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
39 MESSAGE = '/message'
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
40 NS_DIRECT_MUC_INVITATION = 'jabber:x:conference'
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
41 DIRECT_MUC_INVITATION_REQUEST = MESSAGE + '/x[@xmlns="' + NS_DIRECT_MUC_INVITATION + '"]'
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
42 AUTOJOIN_KEY = "Misc"
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
43 AUTOJOIN_NAME = "Auto-join MUC on invitation"
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
44 AUTOJOIN_VALUES = ["ask", "always", "never"]
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
45
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
46 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
47 C.PI_NAME: "XEP 0249 Plugin",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
48 C.PI_IMPORT_NAME: "XEP-0249",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
49 C.PI_TYPE: "XEP",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
50 C.PI_PROTOCOLS: ["XEP-0249"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
51 C.PI_DEPENDENCIES: ["XEP-0045"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
52 C.PI_RECOMMENDATIONS: [C.TEXT_CMDS],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
53 C.PI_MAIN: "XEP_0249",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
54 C.PI_HANDLER: "yes",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
55 C.PI_DESCRIPTION: _("""Implementation of Direct MUC Invitations""")
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
56 }
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
57
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
58
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
59 class XEP_0249(object):
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
60
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
61 params = """
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
62 <params>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
63 <individual>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
64 <category name="%(category_name)s" label="%(category_label)s">
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 916
diff changeset
65 <param name="%(param_name)s" label="%(param_label)s" type="list" security="0">
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
66 %(param_options)s
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
67 </param>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
68 </category>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
69 </individual>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
70 </params>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
71 """ % {
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
72 'category_name': AUTOJOIN_KEY,
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
73 'category_label': _("Misc"),
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
74 'param_name': AUTOJOIN_NAME,
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
75 'param_label': _("Auto-join MUC on invitation"),
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 916
diff changeset
76 'param_options': '\n'.join(['<option value="%s" %s/>' % \
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 916
diff changeset
77 (value, 'selected="true"' if value == AUTOJOIN_VALUES[0] else '') \
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 916
diff changeset
78 for value in AUTOJOIN_VALUES])
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
79 }
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
80
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
82 log.info(_("Plugin XEP_0249 initialization"))
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self.host = host
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
84 host.memory.updateParams(self.params)
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
85 host.bridge.addMethod("inviteMUC", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._invite)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
86 try:
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
87 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
88 except KeyError:
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
89 log.info(_("Text commands not available"))
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
90
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
91 def getHandler(self, client):
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
92 return XEP_0249_handler(self)
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
93
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
94 def _invite(self, guest_jid_s, room_jid_s, options, profile_key):
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
95 """Invite an user to a room
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
96
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
97 @param guest_jid_s: jid of the user to invite
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
98 @param service: jid of the MUC service
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
99 @param roomId: name of the room
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
100 @param profile_key: %(doc_profile_key)s
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
101 """
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
102 #TODO: check parameters validity
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
103 client = self.host.getClient(profile_key)
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
104 self.invite(client, jid.JID(guest_jid_s), jid.JID(room_jid_s, options))
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
105
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
106 def invite(self, client, guest, room, options={}):
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
107 """Invite a user to a room
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
108
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
109 @param guest(jid.JID): jid of the user to invite
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
110 @param room(jid.JID): jid of the room where the user is invited
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
111 @param options(dict): attribute with extra info (reason, password) as in #XEP-0249
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
112 """
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
113 message = domish.Element((None, 'message'))
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
114 message["to"] = guest.full()
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
115 x_elt = message.addElement((NS_DIRECT_MUC_INVITATION, 'x'))
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
116 x_elt['jid'] = room.userhost()
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
117 for key, value in options.iteritems():
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
118 if key not in ('password', 'reason', 'thread'):
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
119 log.warning(u"Ignoring invalid invite option: {}".format(key))
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
120 continue
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
121 x_elt[key] = value
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
122 # there is not body in this message, so we can use directly send()
2129
6a66c8c5a567 core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents: 2045
diff changeset
123 client.send(message)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
124
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
125 def _accept(self, room_jid, profile_key=C.PROF_KEY_NONE):
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
126 """Accept the invitation to join a MUC.
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
127
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
128 @param room (jid.JID): JID of the room
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
129 """
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
130 client = self.host.getClient(profile_key)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
131 log.info(_(u'Invitation accepted for room %(room)s [%(profile)s]') % {'room': room_jid.userhost(), 'profile': client.profile})
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
132 d = self.host.plugins["XEP-0045"].join(client, room_jid, client.jid.user, {})
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
133 return d
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
134
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
135 def onInvitation(self, message, profile):
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
136 """
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
137 called when an invitation is received
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
138 @param message: message element
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
139 @profile: %(doc_profile)s
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
140 """
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
141 client = self.host.getClient(profile)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
142 try:
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
143 room_jid_s = message.firstChildElement()['jid']
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
144 log.info(_(u'Invitation received for room %(room)s [%(profile)s]') % {'room': room_jid_s, 'profile': profile})
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
145 except:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
146 log.error(_('Error while parsing invitation'))
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
147 return
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
148 from_jid_s = message["from"]
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
149 room_jid = jid.JID(room_jid_s)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
150 try:
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
151 self.host.plugins["XEP-0045"].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
152 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
153 pass
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
154 else:
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
155 log.info(_(u"Invitation silently discarded because user is already in the room."))
710
3344f1d8a232 plugin XEP-0249: silently discard MUC invitation if user is already in
souliane <souliane@mailoo.org>
parents: 689
diff changeset
156 return
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
157
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
158 autojoin = self.host.memory.getParamA(AUTOJOIN_NAME, AUTOJOIN_KEY, profile_key=profile)
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
159
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
160 if autojoin == "always":
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
161 self._accept(room_jid, profile)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
162 elif autojoin == "never":
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
163 msg = D_("An invitation from %(user)s to join the room %(room)s has been declined according to your personal settings.") % {'user': from_jid_s, 'room': room_jid_s}
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
164 title = D_("MUC invitation")
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
165 xml_tools.quickNote(self.host, client, msg, title, C.XMLUI_DATA_LVL_INFO)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
166 else: # leave the default value here
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
167 confirm_msg = D_("You have been invited by %(user)s to join the room %(room)s. Do you accept?") % {'user': from_jid_s, 'room': room_jid_s}
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
168 confirm_title = D_("MUC invitation")
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
169 d = xml_tools.deferConfirm(self.host, confirm_msg, confirm_title, profile=profile)
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
170 def accept_cb(accepted):
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
171 if accepted:
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
172 self._accept(room_jid, profile)
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
173
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
174 d.addCallback(accept_cb)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
175
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
176 def cmd_invite(self, client, mess_data):
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
177 """invite someone in the room
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
178
1373
6d0e01809893 plugin text commands: minor docstrings improvments
Goffi <goffi@goffi.org>
parents: 1371
diff changeset
179 @command (group): JID
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
180 - JID: the JID of the person to invite
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
181 """
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: 1373
diff changeset
182 contact_jid_s = mess_data["unparsed"].strip()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
183 my_host = client.jid.host
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
184 try:
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: 1373
diff changeset
185 contact_jid = jid.JID(contact_jid_s)
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: 1373
diff changeset
186 except (RuntimeError, jid.InvalidFormat, AttributeError):
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: 1373
diff changeset
187 feedback = _(u"You must provide a valid JID to invite, like in '/invite contact@{host}'").format(host=my_host)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
188 self.host.plugins[C.TEXT_CMDS].feedBack(client, feedback, mess_data)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
189 return False
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: 1373
diff changeset
190 if not contact_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: 1373
diff changeset
191 contact_jid.user, contact_jid.host = contact_jid.host, my_host
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
192 self.invite(client, contact_jid, mess_data["to"])
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
193 return False
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
194
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
195
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
196 class XEP_0249_handler(XMPPHandler):
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
197 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
198
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
199 def __init__(self, plugin_parent):
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
200 self.plugin_parent = plugin_parent
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
201 self.host = plugin_parent.host
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
202
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
203 def connectionInitialized(self):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
204 self.xmlstream.addObserver(DIRECT_MUC_INVITATION_REQUEST, self.plugin_parent.onInvitation, profile=self.parent.profile)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
205
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
206 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
207 return [disco.DiscoFeature(NS_DIRECT_MUC_INVITATION)]
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
208
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
209 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
210 return []