core: server identities are now save in memory
This commit is contained in:
parent
9361e8fdcc
commit
c665864404
2 changed files with 40 additions and 1 deletions
27
src/sat.tac
27
src/sat.tac
|
|
@ -29,7 +29,7 @@ import gettext
|
|||
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 @@ class SatXMPPClient(client.XMPPClient):
|
|||
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 @@ class SatXMPPClient(client.XMPPClient):
|
|||
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 @@ class SatRosterProtocol(xmppim.RosterClientProtocol):
|
|||
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 @@ class SatRosterProtocol(xmppim.RosterClientProtocol):
|
|||
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 @@ class SatRosterProtocol(xmppim.RosterClientProtocol):
|
|||
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 @@ class SAT(service.Service):
|
|||
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 ##
|
||||
|
||||
|
|
|
|||
|
|
@ -398,6 +398,7 @@ class Memory:
|
|||
self.history={} #used to store chat history (key: short jid)
|
||||
self.private={} #used to store private value
|
||||
self.server_features={} #used to store discovery's informations
|
||||
self.server_identities={}
|
||||
host.set_const('savefile_history', SAVEFILE_HISTORY)
|
||||
host.set_const('savefile_private', SAVEFILE_PRIVATE)
|
||||
self.load()
|
||||
|
|
@ -545,6 +546,19 @@ class Memory:
|
|||
if not self.server_features.has_key(profile):
|
||||
self.server_features[profile] = []
|
||||
self.server_features[profile].append(feature)
|
||||
|
||||
def addServerIdentity(self, category, type, entity, profile):
|
||||
"""Add an identity discovered from server
|
||||
@param feature: string of the feature
|
||||
@param profile: which profile is using this server ?"""
|
||||
if not self.server_identities.has_key(profile):
|
||||
self.server_identities[profile] = {}
|
||||
self.server_identities[profile][(category, type)] = entity
|
||||
|
||||
def getServerServiceEntity(self, category, type, profile):
|
||||
if self.server_identities.has_key(profile):
|
||||
return self.server_identities[profile].get((category, type))
|
||||
return None
|
||||
|
||||
def hasServerFeature(self, feature, profile_key='@DEFAULT@'):
|
||||
"""Tell if the server of the profile has the required feature"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue