refactored presence tracking and fixed jidInRoom

This commit is contained in:
Nathan Fritz 2010-05-11 15:12:13 -07:00
parent 9d76e7353a
commit 8515cef117
2 changed files with 17 additions and 21 deletions

View file

@ -261,27 +261,23 @@ class basexmpp(object):
if not presence['from'].bare in self.roster: if not presence['from'].bare in self.roster:
self.roster[jid] = {'groups': [], 'name': '', 'subscription': 'none', 'presence': {}, 'in_roster': False} self.roster[jid] = {'groups': [], 'name': '', 'subscription': 'none', 'presence': {}, 'in_roster': False}
if not resource in self.roster[jid]['presence']: if not resource in self.roster[jid]['presence']:
if (show == 'available' or show in presence.showtypes):
self.event("got_online", presence)
wasoffline = True wasoffline = True
self.roster[jid]['presence'][resource] = {'show': show, 'status': status, 'priority': priority} self.roster[jid]['presence'][resource] = {}
else:
if self.roster[jid]['presence'][resource].get('show', 'unavailable') == 'unavailable': if self.roster[jid]['presence'][resource].get('show', 'unavailable') == 'unavailable':
wasoffline = True wasoffline = True
self.roster[jid]['presence'][resource] = {'show': show, 'status': status} self.roster[jid]['presence'][resource] = {'show': show, 'status': status, 'priority': priority}
self.roster[jid]['presence'][resource]['priority'] = priority
name = self.roster[jid].get('name', '') name = self.roster[jid].get('name', '')
if wasoffline and (show == 'available' or show in presence.showtypes): if show == 'unavailable':
self.event("got_online", presence)
self.event("changed_status", presence)
elif show == 'unavailable':
logging.debug("%s %s got offline" % (jid, resource)) logging.debug("%s %s got offline" % (jid, resource))
if len(self.roster[jid]['presence']) > 1: if len(self.roster[jid]['presence']):
del self.roster[jid]['presence'][resource] del self.roster[jid]['presence'][resource]
else: else:
del self.roster[jid] del self.roster[jid]
if not wasoffline:
self.event("got_offline", presence) self.event("got_offline", presence)
self.event("changed_status", presence) self.event("changed_status", presence)
elif oldroster != self.roster.get(jid, {'presence': {}})['presence'].get(resource, {}):
self.event("changed_status", presence)
name = '' name = ''
if name: if name:
name = "(%s) " % name name = "(%s) " % name