diff --git a/src/plugins/plugin_xep_0249.py b/src/plugins/plugin_xep_0249.py
index a8bfd937..b12f4c40 100755
--- a/src/plugins/plugin_xep_0249.py
+++ b/src/plugins/plugin_xep_0249.py
@@ -35,6 +35,9 @@ except ImportError:
MESSAGE = '/message'
NS_DIRECT_MUC_INVITATION = 'jabber:x:conference'
DIRECT_MUC_INVITATION_REQUEST = MESSAGE + '/x[@xmlns="' + NS_DIRECT_MUC_INVITATION + '"]'
+AUTOJOIN_KEY = "Misc"
+AUTOJOIN_NAME = "Auto-join MUC on invitation"
+AUTOJOIN_VALUES = ["ask", "always", "never"]
PLUGIN_INFO = {
"name": "XEP 0249 Plugin",
@@ -50,9 +53,29 @@ PLUGIN_INFO = {
class XEP_0249(object):
+ params = """
+
+
+
+
+ %(param_options)s
+
+
+
+
+ """ % {
+ 'category_name': AUTOJOIN_KEY,
+ 'category_label': _("Misc"),
+ 'param_name': AUTOJOIN_NAME,
+ 'param_label': _("Auto-join MUC on invitation"),
+ 'param_default': AUTOJOIN_VALUES[0],
+ 'param_options': ['' % value for value in AUTOJOIN_VALUES]
+ }
+
def __init__(self, host):
info(_("Plugin XEP_0249 initialization"))
self.host = host
+ host.memory.updateParams(self.params)
host.bridge.addMethod("inviteMUC", ".plugin", in_sign='sssa{ss}s', out_sign='', method=self._invite)
def getHandler(self, profile):
@@ -89,21 +112,45 @@ class XEP_0249(object):
#TODO: check parameters validity
self.invite(jid.JID(target), jid.JID("%s@%s" % (roomId, service)), options, profile_key)
+ def _accept(self, room, profile_key='@DEFAULT@'):
+ """
+ Accept the invitation to join a MUC
+ @param room: room jid as string
+ """
+ profile = self.host.memory.getProfileName(profile_key)
+ if not profile:
+ error(_("Profile doesn't exists !"))
+ return
+ info(_('Invitation accepted for room %(room)s [%(profile)s]') % {'room': room, 'profile': profile})
+ _jid, xmlstream = self.host.getJidNStream(profile)
+ d = self.host.plugins["XEP-0045"].join(jid.JID(room), _jid.user, {}, profile)
+
def onInvitation(self, message, profile):
"""
called when an invitation is received
@param message: message element
@profile: %(doc_profile)s
"""
- info(_('Invitation received for room %(room)s [%(profile)s]') % {'room': '', 'profile': profile})
try:
- room = jid.JID(message.firstChildElement()['jid'])
+ room = message.firstChildElement()['jid']
+ info(_('Invitation received for room %(room)s [%(profile)s]') % {'room': room, 'profile': profile})
except:
error(_('Error while parsing invitation'))
return
- _jid, xmlstream = self.host.getJidNStream(profile)
- #TODO: we always autojoin so far, we need to add a parameter to autojoin/ignore invitations or let user choose to follow it
- d = self.host.plugins["XEP-0045"].join(room, _jid.user, {}, profile)
+ autojoin = self.host.memory.getParamA(AUTOJOIN_NAME, AUTOJOIN_KEY, profile_key=profile)
+ from_ = message["from"]
+
+ def accept_cb(conf_id, accepted, data, profile):
+ if conf_id == room and accepted:
+ self._accept(room, profile)
+
+ if autojoin == "always":
+ self._accept(room, profile)
+ elif autojoin == "ask":
+ data = {"message": _("You have been invited by %s to join the room %s. Do you accept?") % (from_, room), "title": _("MUC invitation")}
+ self.host.askConfirmation(room, "YES/NO", data, accept_cb, profile)
+ else:
+ self.host.bridge.newAlert(_("An invitation from %s to join the room %s has been declined according to your personal settings.") % (from_, room), _("MUC invitation"), "INFO", profile)
class XEP_0249_handler(XMPPHandler):