# HG changeset patch # User souliane # Date 1413815929 -7200 # Node ID 51a85e8f599addcfd03f6fb5b1dab9c4d63bc362 # Parent 1f0ae61536aae8d2d74361f4722abe3894aaec7f memory: add method isContactConnected diff -r 1f0ae61536aa -r 51a85e8f599a src/memory/memory.py --- a/src/memory/memory.py Mon Oct 20 15:09:37 2014 +0200 +++ b/src/memory/memory.py Mon Oct 20 16:38:49 2014 +0200 @@ -420,6 +420,22 @@ 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