comparison src/memory/memory.py @ 1251:51a85e8f599a

memory: add method isContactConnected
author souliane <souliane@mailoo.org>
date Mon, 20 Oct 2014 16:38:49 +0200
parents c6cf44e6330b
children c585df65828a
comparison
equal deleted inserted replaced
1250:1f0ae61536aa 1251:51a85e8f599a
418 entities_presence[entity] = self._entities_cache[profile][entity]["presence"] 418 entities_presence[entity] = self._entities_cache[profile][entity]["presence"]
419 419
420 log.debug("Memory getPresenceStatus (%s)" % entities_presence) 420 log.debug("Memory getPresenceStatus (%s)" % entities_presence)
421 return entities_presence 421 return entities_presence
422 422
423 def isContactConnected(self, entity_jid, profile_key):
424 """Tell from the presence information if the given contact is connected.
425
426 @param entity_jid (JID): the entity to check
427 @param profile_key: %(doc_profile_key)s
428 @return: boolean
429 """
430 profile = self.getProfileName(profile_key)
431 if not profile:
432 raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile'))
433 try:
434 presence = self._entities_cache[profile][entity_jid]['presence']
435 return len([True for status in presence.values() if status[0] != 'unavailable']) > 0
436 except KeyError:
437 return False
438
423 def setPresenceStatus(self, entity_jid, show, priority, statuses, profile_key): 439 def setPresenceStatus(self, entity_jid, show, priority, statuses, profile_key):
424 """Change the presence status of an entity 440 """Change the presence status of an entity
425 @param entity_jid: jid.JID of the entity 441 @param entity_jid: jid.JID of the entity
426 @param show: show status 442 @param show: show status
427 @param priotity: priotity 443 @param priotity: priotity