summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-08-09 13:36:22 +0100
committerErik Johnston <erik@matrix.org>2017-08-09 13:36:22 +0100
commitef8e5786770ff285ebdf1fce420b5aa86437673c (patch)
tree61cad1a476d1d43cda40162ec4303dc625feb0e8 /synapse/handlers
parentAllow update group publicity (diff)
downloadsynapse-ef8e5786770ff285ebdf1fce420b5aa86437673c.tar.xz
Add bulk group publicised lookup API
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/groups_local.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/synapse/handlers/groups_local.py b/synapse/handlers/groups_local.py
index 3a738ef36f..c980623bbc 100644
--- a/synapse/handlers/groups_local.py
+++ b/synapse/handlers/groups_local.py
@@ -313,3 +313,45 @@ class GroupsLocalHandler(object):
     def get_joined_groups(self, user_id):
         group_ids = yield self.store.get_joined_groups(user_id)
         defer.returnValue({"groups": group_ids})
+
+    @defer.inlineCallbacks
+    def get_publicised_groups_for_user(self, user_id):
+        if self.hs.is_mine_id(user_id):
+            result = yield self.store.get_publicised_groups_for_user(user_id)
+            defer.returnValue({"groups": result})
+        else:
+            result = yield self.transport_client.get_publicised_groups_for_user(
+                get_domain_from_id(user_id), user_id
+            )
+            # TODO: Verify attestations
+            defer.returnValue(result)
+
+    @defer.inlineCallbacks
+    def bulk_get_publicised_groups(self, user_ids, proxy=True):
+        destinations = {}
+        locals = []
+
+        for user_id in user_ids:
+            if self.hs.is_mine_id(user_id):
+                locals.append(user_id)
+            else:
+                destinations.setdefault(
+                    get_domain_from_id(user_id), []
+                ).append(user_id)
+
+        if not proxy and destinations:
+            raise SynapseError(400, "Some user_ids are not local")
+
+        results = {}
+        for destination, dest_user_ids in destinations.iteritems():
+            r = yield self.transport_client.bulk_get_publicised_groups(
+                destination, dest_user_ids,
+            )
+            results.update(r)
+
+        for uid in locals:
+            results[uid] = yield self.store.get_publicised_groups_for_user(
+                uid
+            )
+
+        defer.returnValue({"users": results})