Mercurial > libervia-backend
diff src/sat.tac @ 305:15a12bf2bb62
core: server identities are now save in memory
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 07 Apr 2011 22:21:16 +0200 |
parents | f7bd973bba5a |
children | cc8ffbfe938c |
line wrap: on
line diff
--- a/src/sat.tac Sat Mar 26 17:51:19 2011 +0100 +++ b/src/sat.tac Thu Apr 07 22:21:16 2011 +0200 @@ -29,7 +29,7 @@ gettext.install('sat', "i18n", unicode=True) from twisted.application import internet, service -from twisted.internet import glib2reactor, protocol, task +from twisted.internet import glib2reactor, protocol, task, defer glib2reactor.install() from twisted.words.protocols.jabber import jid, xmlstream @@ -80,6 +80,7 @@ self.__connected=False self.profile = profile self.host_app = host_app + self.client_initialized = defer.Deferred() def _authd(self, xmlstream): if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile): @@ -110,6 +111,7 @@ self.presence.available() self.disco.requestInfo(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDisco, self.profile) #FIXME: use these informations + self.disco.requestItems(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDiscoItems, self.disco, self.profile, self.client_initialized) def initializationFailed(self, reason): print ("initializationFailed: %s" % reason) @@ -155,6 +157,7 @@ def __init__(self, host): xmppim.RosterClientProtocol.__init__(self) self.host = host + self._groups=set() def rosterCb(self, roster): for raw_jid, item in roster.iteritems(): @@ -188,6 +191,7 @@ info (_("new contact in roster list: %s"), item.jid.full()) self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile) self.host.bridge.newContact(item.jid.full(), item_attr, item.groups, self.parent.profile) + self._groups.update(item.groups) def onRosterRemove(self, entity): """Called when a roster removal event is received""" @@ -195,6 +199,10 @@ print _("removing %s from roster list") % entity.full() self.host.memory.delContact(entity, self.parent.profile) + def getGroups(self): + """Return a set of groups""" + return self._groups + class SatPresenceProtocol(xmppim.PresenceClientProtocol): def __init__(self, host): @@ -714,6 +722,23 @@ for cat, type in disco.identities: debug (_("Identity found: [%(category)s/%(type)s] %(identity)s") % {'category':cat, 'type':type, 'identity':disco.identities[(cat,type)]}) + def serverDiscoItems(self, disco_result, disco_client, profile, initialized): + """xep-0030 Discovery Protocol. + @param disco_result: result of the disco item querry + @param disco_client: SatDiscoProtocol instance + @param profile: profile of the user + @param initialized: deferred which must be chained when everything is done""" + def _check_entity_cb(result, entity, profile): + for category, type in result.identities: + debug (_('Identity added: (%(category)s,%(type)s) ==> %(entity)s [%(profile)s]') % { + 'category':category, 'type':type, 'entity':entity, 'profile':profile}) + self.memory.addServerIdentity(category, type, entity, profile) + + defer_list = [] + for item in disco_result._items: + defer_list.append(disco_client.requestInfo(item.entity).addCallback(_check_entity_cb, item.entity, profile)) + defer.DeferredList(defer_list).chainDeferred(initialized) + ## Generic HMI ##