summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorDaniel Wagner-Hall <dawagner@gmail.com>2015-11-18 18:08:22 -0500
committerDaniel Wagner-Hall <dawagner@gmail.com>2015-11-18 18:11:12 -0500
commitbed7889703371dca893893d33f67e59e99cda111 (patch)
treeb7ba39987e76da347d02f08262b9fe80ad2b8ac8 /synapse/storage
parentAllow users to forget rooms (diff)
downloadsynapse-bed7889703371dca893893d33f67e59e99cda111.tar.xz
Apply forgetting properly to historical events
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/roommember.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index 183855ba40..5e92cdc811 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -271,6 +271,7 @@ class RoomMemberStore(SQLBaseStore):
         defer.returnValue(ret)
 
     def forget(self, user_id, room_id):
+        """Indicate that user_id wishes to discard history for room_id."""
         def f(txn):
             sql = (
                 "UPDATE"
@@ -287,6 +288,9 @@ class RoomMemberStore(SQLBaseStore):
 
     @defer.inlineCallbacks
     def did_forget(self, user_id, room_id):
+        """Returns whether user_id has elected to discard history for room_id.
+
+        Returns False if they have since re-joined."""
         def f(txn):
             sql = (
                 "SELECT"
@@ -298,10 +302,36 @@ class RoomMemberStore(SQLBaseStore):
                 " AND"
                 "  room_id = ?"
                 " AND"
-                "  forgotten = 1"
+                "  forgotten = 0"
             )
             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)
+        defer.returnValue(count == 0)
+
+    @defer.inlineCallbacks
+    def was_forgotten_at(self, user_id, room_id, event_id):
+        """Returns whether user_id has elected to discard history for room_id at event_id.
+
+        event_id must be a membership event."""
+        def f(txn):
+            sql = (
+                "SELECT"
+                "  COUNT(*)"
+                "FROM"
+                "  room_memberships"
+                " WHERE"
+                "  user_id = ?"
+                " AND"
+                "  room_id = ?"
+                " AND"
+                "  event_id = ?"
+                " AND"
+                "  forgotten = 1"
+            )
+            txn.execute(sql, (user_id, room_id, event_id))
+            rows = txn.fetchall()
+            return rows[0][0]
+        count = yield self.runInteraction("did_forget_membership_at", f)
+        defer.returnValue(count == 1)