we get the roster asynchronously now

This commit is contained in:
Yann Leboulanger 2005-05-08 17:00:41 +00:00
parent 2f977d1b1a
commit 2171def073
4 changed files with 21 additions and 10 deletions

View File

@ -490,6 +490,16 @@ class Connection:
errcode = iq_obj.getErrorCode() errcode = iq_obj.getErrorCode()
self.dispatch('MSGERROR', (jid, errcode, errmsg)) self.dispatch('MSGERROR', (jid, errcode, errmsg))
def _getRosterCB(self, con, iq_obj):
roster = self.connection.getRoster().getRaw()
if not roster :
roster = {}
name = gajim.config.get_per('accounts', self.name, 'name')
hostname = gajim.config.get_per('accounts', self.name, 'hostname')
if roster.has_key(name + '@' + hostname):
del roster[name + '@' + hostname]
self.dispatch('ROSTER', roster)
def connect(self): def connect(self):
"""Connect and authentificate to the Jabber server""" """Connect and authentificate to the Jabber server"""
name = gajim.config.get_per('accounts', self.name, 'name') name = gajim.config.get_per('accounts', self.name, 'name')
@ -508,7 +518,7 @@ class Connection:
else: else:
proxy = None proxy = None
if gajim.config.get('verbose'): if gajim.config.get('verbose'):
con = common.xmpp.Client(hostname)#, debug = []) con = common.xmpp.Client(hostname)
else: else:
con = common.xmpp.Client(hostname, debug = []) con = common.xmpp.Client(hostname, debug = [])
#debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, \ #debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, \
@ -544,16 +554,13 @@ class Connection:
common.xmpp.NS_VERSION) common.xmpp.NS_VERSION)
con.RegisterHandler('iq', self._MucOwnerCB, 'result',\ con.RegisterHandler('iq', self._MucOwnerCB, 'result',\
common.xmpp.NS_MUC_OWNER) common.xmpp.NS_MUC_OWNER)
con.RegisterHandler('iq', self._getRosterCB, 'result',\
common.xmpp.NS_ROSTER)
gajim.log.debug('Connected to server') gajim.log.debug('Connected to server')
if con.auth(name, self.password, resource): #FIXME: blocking if con.auth(name, self.password, resource): #FIXME: blocking
roster = con.getRoster().getRaw() #FIXME: blocking con.initRoster()
if not roster :
roster = {}
if roster.has_key(name + '@' + hostname):
del roster[name + '@' + hostname]
self.dispatch('ROSTER', roster)
self.connected = 2 self.connected = 2
return con return con
else: else:

View File

@ -205,10 +205,14 @@ class Client(CommonClient):
self.connected+='+sasl' self.connected+='+sasl'
return 'sasl' return 'sasl'
def initRoster(self):
""" Plug in the roster. """
if not self.__dict__.has_key('Roster'): roster.Roster().PlugIn(self)
def getRoster(self): def getRoster(self):
""" Return the Roster instance, previously plugging it in and """ Return the Roster instance, previously plugging it in and
requesting roster from server if needed. """ requesting roster from server if needed. """
if not self.__dict__.has_key('Roster'): roster.Roster().PlugIn(self) self.initRoster()
return self.Roster.getRoster() return self.Roster.getRoster()
def sendInitPresence(self,requestRoster=1): def sendInitPresence(self,requestRoster=1):

View File

@ -170,7 +170,7 @@ class Dispatcher(PlugIn):
if not self.handlers.has_key(xmlns): self.RegisterNamespace(xmlns,'warn') if not self.handlers.has_key(xmlns): self.RegisterNamespace(xmlns,'warn')
if not self.handlers[xmlns].has_key(name): self.RegisterProtocol(name,Protocol,xmlns,'warn') if not self.handlers[xmlns].has_key(name): self.RegisterProtocol(name,Protocol,xmlns,'warn')
if not self.handlers[xmlns][name].has_key(typ+ns): self.handlers[xmlns][name][typ+ns]=[] if not self.handlers[xmlns][name].has_key(typ+ns): self.handlers[xmlns][name][typ+ns]=[]
if makefirst: self.handlers[xmlns][name][typ+ns].insert({'func':handler,'system':system}) if makefirst: self.handlers[xmlns][name][typ+ns].insert(0,{'func':handler,'system':system})
else: self.handlers[xmlns][name][typ+ns].append({'func':handler,'system':system}) else: self.handlers[xmlns][name][typ+ns].append({'func':handler,'system':system})
def RegisterHandlerOnce(self,name,handler,typ='',ns='',xmlns=None,makefirst=0, system=0): def RegisterHandlerOnce(self,name,handler,typ='',ns='',xmlns=None,makefirst=0, system=0):

View File

@ -42,7 +42,7 @@ class Roster(PlugIn):
""" Register presence and subscription trackers in the owner's dispatcher. """ Register presence and subscription trackers in the owner's dispatcher.
Also request roster from server if the 'request' argument is set. Also request roster from server if the 'request' argument is set.
Used internally.""" Used internally."""
self._owner.RegisterHandler('iq',self.RosterIqHandler,'result',NS_ROSTER) self._owner.RegisterHandler('iq',self.RosterIqHandler,'result',NS_ROSTER,makefirst=1)
self._owner.RegisterHandler('iq',self.RosterIqHandler,'set',NS_ROSTER) self._owner.RegisterHandler('iq',self.RosterIqHandler,'set',NS_ROSTER)
self._owner.RegisterHandler('presence',self.PresenceHandler) self._owner.RegisterHandler('presence',self.PresenceHandler)
if request: self.Request() if request: self.Request()