summary refs log tree commit diff
diff options
context:
space:
mode:
authorLuke Barnard <luke@matrix.org>2017-11-06 15:45:20 +0000
committerLuke Barnard <luke@matrix.org>2017-11-06 15:45:20 +0000
commit4e241fad7899e8f12adea80054ded28db5ae9ecc (patch)
treea70c3ca722577c8d7109af2955ce76e5425a06ec
parentMerge pull request #2630 from matrix-org/luke/fix-rooms-in-group (diff)
downloadsynapse-4e241fad7899e8f12adea80054ded28db5ae9ecc.tar.xz
WIP: Return admins of a group first in the list of group users
This introduces a ORDER BY that can be optionally added to _simple_select_list transactions'
-rw-r--r--synapse/groups/groups_server.py5
-rw-r--r--synapse/storage/_base.py20
-rw-r--r--synapse/storage/group_server.py4
3 files changed, 21 insertions, 8 deletions
diff --git a/synapse/groups/groups_server.py b/synapse/groups/groups_server.py
index addc70ce94..a9769e3737 100644
--- a/synapse/groups/groups_server.py
+++ b/synapse/groups/groups_server.py
@@ -426,14 +426,15 @@ class GroupsServerHandler(object):
         for user_result in user_results:
             g_user_id = user_result["user_id"]
             is_public = user_result["is_public"]
+            is_admin = user_result["is_admin"]
 
             entry = {"user_id": g_user_id}
 
             profile = yield self.profile_handler.get_profile_from_cache(g_user_id)
             entry.update(profile)
 
-            if not is_public:
-                entry["is_public"] = False
+            entry["is_public"] = bool(is_public)
+            entry["is_admin"] = bool(is_admin)
 
             if not self.is_mine_id(g_user_id):
                 attestation = yield self.store.get_remote_attestation(group_id, g_user_id)
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 6caf7b3356..35ded73f25 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -619,7 +619,7 @@ class SQLBaseStore(object):
         )
 
     def _simple_select_list(self, table, keyvalues, retcols,
-                            desc="_simple_select_list"):
+                            desc="_simple_select_list", order=None, order_asc=True):
         """Executes a SELECT query on the named table, which may return zero or
         more rows, returning the result as a list of dicts.
 
@@ -629,17 +629,19 @@ class SQLBaseStore(object):
                 column names and values to select the rows with, or None to not
                 apply a WHERE clause.
             retcols (iterable[str]): the names of the columns to return
+            order (str): order the select by this column
+            order_asc (bool): order ascending (if order specified). Default True.
         Returns:
             defer.Deferred: resolves to list[dict[str, Any]]
         """
         return self.runInteraction(
             desc,
             self._simple_select_list_txn,
-            table, keyvalues, retcols
+            table, keyvalues, retcols, order, order_asc
         )
 
     @classmethod
-    def _simple_select_list_txn(cls, txn, table, keyvalues, retcols):
+    def _simple_select_list_txn(cls, txn, table, keyvalues, retcols, order=None, order_asc=True):
         """Executes a SELECT query on the named table, which may return zero or
         more rows, returning the result as a list of dicts.
 
@@ -650,20 +652,28 @@ class SQLBaseStore(object):
                 column names and values to select the rows with, or None to not
                 apply a WHERE clause.
             retcols (iterable[str]): the names of the columns to return
+            order (str): order the select by this column
+            order_asc (bool): order ascending (if order specified). Default True.
         """
+        query_values = []
         if keyvalues:
             sql = "SELECT %s FROM %s WHERE %s" % (
                 ", ".join(retcols),
                 table,
                 " AND ".join("%s = ?" % (k, ) for k in keyvalues)
             )
-            txn.execute(sql, keyvalues.values())
+            query_values.extend(keyvalues.values())
         else:
             sql = "SELECT %s FROM %s" % (
                 ", ".join(retcols),
                 table
             )
-            txn.execute(sql)
+
+        if order:
+            sql = sql + " ORDER BY ? %s" % ("ASC" if order_asc else "DESC")
+            query_values.append(order)
+
+        txn.execute(sql, query_values)
 
         return cls.cursor_to_dict(txn)
 
diff --git a/synapse/storage/group_server.py b/synapse/storage/group_server.py
index f6924e1a32..3a30de5490 100644
--- a/synapse/storage/group_server.py
+++ b/synapse/storage/group_server.py
@@ -54,8 +54,10 @@ class GroupServerStore(SQLBaseStore):
         return self._simple_select_list(
             table="group_users",
             keyvalues=keyvalues,
-            retcols=("user_id", "is_public",),
+            retcols=("user_id", "is_public", "is_admin",),
             desc="get_users_in_group",
+            order="is_admin",
+            order_asc=False, # Order descending: admins first
         )
 
     def get_invited_users_in_group(self, group_id):