changeset 348:d1f63ae1eaf4

privilege: added isSubscribedFrom method to check if an entity has presence subscription from an other entity.
author Goffi <goffi@goffi.org>
date Sun, 27 Aug 2017 20:26:38 +0200
parents f33406fcab5c
children 20b82fb8de02
files sat_pubsub/privilege.py
diffstat 1 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sat_pubsub/privilege.py	Thu Aug 24 01:35:43 2017 +0200
+++ b/sat_pubsub/privilege.py	Sun Aug 27 20:26:38 2017 +0200
@@ -143,10 +143,27 @@
         d.addCallback(processRoster)
         return d
 
+    def _isSubscribedFrom(self, roster, entity, roster_owner_jid):
+        try:
+            return roster[entity.userhostJID()].subscriptionFrom
+        except KeyError:
+            return False
+
+    def isSubscribedFrom(self, entity, roster_owner_jid):
+        """Check if entity has presence subscription from roster_owner_jid
+
+        @param entity(jid.JID): entity to check subscription to
+        @param roster_owner_jid(jid.JID): owner of the roster to check
+        @return D(bool): True if entity has a subscription from roster_owner_jid
+        """
+        d = self.getRoster(roster_owner_jid)
+        d.addCallback(self._isSubscribedFrom, entity, roster_owner_jid)
+        return d
+
     ## message ##
 
     def sendMessage(self, priv_message, to_jid=None):
-        """ Send privileged message (in the name of the server)
+        """Send privileged message (in the name of the server)
 
         @param priv_message(domish.Element): privileged message
         @param to_jid(jid.JID, None): main message destinee