# HG changeset patch # User Goffi # Date 1495390122 -7200 # Node ID 61e836cc95120cf0bed889317a73795c63c034f2 # Parent ba613d32ca60d7e58f1ca2f9143d295779b3f26c plugin invitations: name is now registered as nickname on XMPP server thanks to plugin identity diff -r ba613d32ca60 -r 61e836cc9512 src/plugins/plugin_misc_invitations.py --- a/src/plugins/plugin_misc_invitations.py Sun May 21 20:07:54 2017 +0200 +++ b/src/plugins/plugin_misc_invitations.py Sun May 21 20:08:42 2017 +0200 @@ -36,6 +36,7 @@ C.PI_IMPORT_NAME: "INVITATIONS", C.PI_TYPE: C.PLUG_TYPE_MISC, C.PI_DEPENDENCIES: ['XEP-0077'], + C.PI_RECOMMENDATIONS: ["IDENTITY"], C.PI_MAIN: "InvitationsPlugin", C.PI_HANDLER: "no", C.PI_DESCRIPTION: _(u"""invitation of people without XMPP account""") @@ -125,6 +126,7 @@ password(unicode, None): password to use (will be used for XMPP account and profile) None to automatically generate one name(unicode, None): name of the invitee + will be set as profile identity if present host_name(unicode, None): name of the host email(unicode, None): email to send the invitation to if None, no invitation email is sent, you can still associate email using extra @@ -170,7 +172,6 @@ if email is not None and not 'url_template' in kwargs and not 'message_body' in kwargs: raise ValueError(_(u"You need to provide url_template if you use default message body")) - ## uuid log.info(_(u"creating an invitation")) id_ = unicode(shortuuid.uuid()) @@ -220,12 +221,25 @@ log.info(_(u"account {jid_} created").format(jid_=jid_.full())) ## profile creation + extra[KEY_GUEST_PROFILE] = guest_profile = INVITEE_PROFILE_TPL.format(uuid=id_) # profile creation should not fail as we generate unique name ourselves yield self.host.memory.createProfile(guest_profile, password) yield self.host.memory.startSession(password, guest_profile) yield self.host.memory.setParam("JabberID", jid_.full(), "Connection", profile_key=guest_profile) yield self.host.memory.setParam("Password", password, "Connection", profile_key=guest_profile) + name = kwargs.pop(u'name', None) + if name is not None: + extra[u'name'] = name + try: + id_plugin = self.host.plugins[u'IDENTITY'] + except KeyError: + pass + else: + yield self.host.connect(guest_profile, password) + guest_client = self.host.getClient(guest_profile) + yield id_plugin.setIdentity(guest_client, {u'nick': name}) + yield self.host.disconnect(guest_profile) ## email language = kwargs.pop(u'language', None) @@ -240,11 +254,10 @@ u'app_name': C.APP_NAME, u'app_url': C.APP_URL} - name = kwargs.pop(u'name', None) if name is None: format_args[u'name'] = email else: - format_args[u'name'] = extra[u'name'] = name + format_args[u'name'] = name profile = kwargs.pop(u'profile', None) if profile is None: