summary refs log tree commit diff
path: root/synapse/storage/_base.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-09-23 15:28:32 +0100
committerErik Johnston <erik@matrix.org>2014-09-23 15:28:32 +0100
commit78af6bbb981c41e5509c99454deb7205c31bf964 (patch)
tree50dcd73e748b2807e22752f59bb940dd420078cb /synapse/storage/_base.py
parentAdd a deletions table (diff)
downloadsynapse-78af6bbb981c41e5509c99454deb7205c31bf964.tar.xz
Add m.room.deletion. If an event is deleted it will be returned to clients 'pruned', i.e. all client specified keys will be removed.
Diffstat (limited to 'synapse/storage/_base.py')
-rw-r--r--synapse/storage/_base.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 76ed7d06fb..3aa610c85c 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -17,6 +17,7 @@ import logging
 from twisted.internet import defer
 
 from synapse.api.errors import StoreError
+from synapse.api.events.utils import prune_event
 from synapse.util.logutils import log_function
 
 import collections
@@ -345,7 +346,7 @@ class SQLBaseStore(object):
         return self.runInteraction(func)
 
     def _parse_event_from_row(self, row_dict):
-        d = copy.deepcopy({k: v for k, v in row_dict.items() if v})
+        d = copy.deepcopy({k: v for k, v in row_dict.items()})
 
         d.pop("stream_ordering", None)
         d.pop("topological_ordering", None)
@@ -373,8 +374,8 @@ class SQLBaseStore(object):
         sql = "SELECT * FROM events WHERE event_id = ?"
 
         for ev in events:
-           if hasattr(ev, "prev_state"):
-                # Load previous state_content. 
+            if hasattr(ev, "prev_state"):
+                # Load previous state_content.
                 # TODO: Should we be pulling this out above?
                 cursor = txn.execute(sql, (ev.prev_state,))
                 prevs = self.cursor_to_dict(cursor)
@@ -382,8 +383,31 @@ class SQLBaseStore(object):
                     prev = self._parse_event_from_row(prevs[0])
                     ev.prev_content = prev.content
 
+            if not hasattr(ev, "deleted"):
+                logger.debug("Doesn't have deleted key: %s", ev)
+                ev.deleted = self._has_been_deleted_txn(txn, ev)
+
+            if ev.deleted:
+                # Get the deletion event.
+                sql = "SELECT * FROM events WHERE event_id = ?"
+                txn.execute(sql, (ev.deleted,))
+
+                del_evs = self._parse_events_txn(
+                    txn, self.cursor_to_dict(txn)
+                )
+
+                if del_evs:
+                    prune_event(ev)
+                    ev.pruned = del_evs[0]
+
         return events
 
+    def _has_been_deleted_txn(self, txn, event):
+        sql = "SELECT * FROM deletions WHERE deletes = ?"
+        txn.execute(sql, (event.event_id,))
+        return len(txn.fetchall()) > 0
+
+
 class Table(object):
     """ A base class used to store information about a particular table.
     """