diff idavoll/pgsql_storage.py @ 146:b4490bdc77e5

Change semantics of Node.is_subscribed() to match all subscriptions for an entity (all resources).
author Ralph Meijer <ralphm@ik.nu>
date Fri, 29 Jul 2005 15:33:43 +0000
parents f393bccec4bc
children b03e5ad81173
line wrap: on
line diff
--- a/idavoll/pgsql_storage.py	Thu Jul 14 20:51:48 2005 +0000
+++ b/idavoll/pgsql_storage.py	Fri Jul 29 15:33:43 2005 +0000
@@ -258,24 +258,20 @@
     def _convert_to_jids(self, list):
         return [jid.JID("%s/%s" % (l[0], l[1])) for l in list]
 
-    def is_subscribed(self, subscriber):
-        return self._dbpool.runInteraction(self._is_subscribed, subscriber)
+    def is_subscribed(self, entity):
+        return self._dbpool.runInteraction(self._is_subscribed, entity)
 
-    def _is_subscribed(self, cursor, subscriber):
+    def _is_subscribed(self, cursor, entity):
         self._check_node_exists(cursor)
 
-        userhost = subscriber.userhost()
-        resource = subscriber.resource or ''
-
         cursor.execute("""SELECT 1 FROM entities
                           JOIN subscriptions ON
                           (entities.id=subscriptions.entity_id)
                           JOIN nodes ON
                           (nodes.id=subscriptions.node_id)
-                          WHERE entities.jid=%s AND resource=%s
+                          WHERE entities.jid=%s
                           AND node=%s AND subscription='subscribed'""",
-                       (userhost,
-                       resource,
+                       (entity.userhost(),
                        self.id))
 
         return cursor.fetchone() is not None
@@ -297,9 +293,7 @@
         
         return [(jid.JID(r[0]), r[1]) for r in result]
 
-class LeafNode(Node):
-
-    implements(storage.ILeafNode)
+class LeafNodeMixin:
 
     type = 'leaf'
 
@@ -395,3 +389,7 @@
         cursor.execute("""DELETE FROM items WHERE
                           node_id=(SELECT id FROM nodes WHERE node=%s)""",
                        (self.id,))
+
+class LeafNode(Node, LeafNodeMixin):
+
+    implements(storage.ILeafNode)