summary refs log tree commit diff
path: root/synapse/storage/roommember.py
diff options
context:
space:
mode:
authorDaniel Wagner-Hall <dawagner@gmail.com>2015-11-17 17:17:30 -0500
committerDaniel Wagner-Hall <dawagner@gmail.com>2015-11-17 17:17:30 -0500
commitba26eb3d5d487edb90c21db7efec631b80adf24b (patch)
tree443ada28bdf0a40c2ea24a60b02e6b27ff1d5f79 /synapse/storage/roommember.py
parentMerge pull request #384 from matrix-org/erikj/shorter_retries (diff)
downloadsynapse-ba26eb3d5d487edb90c21db7efec631b80adf24b.tar.xz
Allow users to forget rooms
Diffstat (limited to 'synapse/storage/roommember.py')
-rw-r--r--synapse/storage/roommember.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index ae1ad56d9a..183855ba40 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -269,3 +269,39 @@ class RoomMemberStore(SQLBaseStore):
         ret = len(room_id_lists.pop(0).intersection(*room_id_lists)) > 0
 
         defer.returnValue(ret)
+
+    def forget(self, user_id, room_id):
+        def f(txn):
+            sql = (
+                "UPDATE"
+                "  room_memberships"
+                " SET"
+                "  forgotten = 1"
+                " WHERE"
+                "  user_id = ?"
+                " AND"
+                "  room_id = ?"
+            )
+            txn.execute(sql, (user_id, room_id))
+        self.runInteraction("forget_membership", f)
+
+    @defer.inlineCallbacks
+    def did_forget(self, user_id, room_id):
+        def f(txn):
+            sql = (
+                "SELECT"
+                "  COUNT(*)"
+                "FROM"
+                "  room_memberships"
+                " WHERE"
+                "  user_id = ?"
+                " AND"
+                "  room_id = ?"
+                " AND"
+                "  forgotten = 1"
+            )
+            txn.execute(sql, (user_id, room_id))
+            rows = txn.fetchall()
+            return rows[0][0]
+        count = yield self.runInteraction("did_forget_membership", f)
+        defer.returnValue(count > 0)