memory: add method isContactConnected

This commit is contained in:
souliane 2014-10-20 16:38:49 +02:00
commit 92cb3c0503

View file

@ -420,6 +420,22 @@ class Memory(object):
log.debug("Memory getPresenceStatus (%s)" % entities_presence)
return entities_presence
def isContactConnected(self, entity_jid, profile_key):
"""Tell from the presence information if the given contact is connected.
@param entity_jid (JID): the entity to check
@param profile_key: %(doc_profile_key)s
@return: boolean
"""
profile = self.getProfileName(profile_key)
if not profile:
raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile'))
try:
presence = self._entities_cache[profile][entity_jid]['presence']
return len([True for status in presence.values() if status[0] != 'unavailable']) > 0
except KeyError:
return False
def setPresenceStatus(self, entity_jid, show, priority, statuses, profile_key):
"""Change the presence status of an entity
@param entity_jid: jid.JID of the entity