From 92cb3c0503ceb9d83585dc9eed6d40ab934916ac Mon Sep 17 00:00:00 2001 From: souliane Date: Mon, 20 Oct 2014 16:38:49 +0200 Subject: [PATCH] memory: add method isContactConnected --- src/memory/memory.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/memory/memory.py b/src/memory/memory.py index 4c44b91e..516452c1 100644 --- a/src/memory/memory.py +++ b/src/memory/memory.py @@ -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