Example #1
0
        def resultReceived(result):
            items = [item.attributes for item in result.query.children]
            if items[0].has_key('node'):
                for item in reversed(items):
                    iq = IQ(client.admin.xmlstream, 'get')
                    iq['to'] = getXMPPDomain(site)
                    query = iq.addElement((NS_DISCO_ITEMS, 'query'))
                    query['node'] = item['node']
                    iq.send().addCallbacks(resultReceived)
            else:
                subscribe_jids = [item['jid'] for item in items]
                if settings.admin_jid in subscribe_jids:
                    subscribe_jids.remove(settings.admin_jid)

                if subscribe_jids:
                    getJID = lambda uid: JID(
                        "%s@%s" % (escapeNode(uid), settings.xmpp_domain))
                    roster_jids = [getJID(user_id.split('@')[0])
                                   for user_id in subscribe_jids]

                    for member_jid in member_jids:
                        client.chat.sendRosterItemAddSuggestion(member_jid,
                                                                roster_jids,
                                                                site)
                        log.info('Roster suggestion sent for %s' % member_jid)
                    # XXX: Somehow the last user's roster suggestions is
                    # dropped, unless we rest here for a bit.
                    time.sleep(3)
            return result
Example #2
0
        def resultReceived(result):
            items = [item.attributes for item in result.query.children]
            if items[0].has_key('node'):
                for item in reversed(items):
                    iq = IQ(client.admin.xmlstream, 'get')
                    iq['to'] = getXMPPDomain(site)
                    query = iq.addElement((NS_DISCO_ITEMS, 'query'))
                    query['node'] = item['node']
                    iq.send().addCallbacks(resultReceived)
            else:
                subscribe_jids = [item['jid'] for item in items]
                if settings.admin_jid in subscribe_jids:
                    subscribe_jids.remove(settings.admin_jid)

                if subscribe_jids:
                    getJID = lambda uid: JID("%s@%s" % (escapeNode(uid),
                                                        settings.xmpp_domain))
                    roster_jids = [
                        getJID(user_id.split('@')[0])
                        for user_id in subscribe_jids
                    ]

                    for member_jid in member_jids:
                        client.chat.sendRosterItemAddSuggestion(
                            member_jid, roster_jids, site)
                        log.info('Roster suggestion sent for %s' % member_jid)
                    # XXX: Somehow the last user's roster suggestions is
                    # dropped, unless we rest here for a bit.
                    time.sleep(3)
            return result
 def getUserJID(self, user_id):
     registry = getUtility(IRegistry)
     settings = registry.forInterface(IXMPPSettings, check=False)
     return JID("%s@%s" % (escapeNode(user_id), settings.xmpp_domain))