summary refs log tree commit diff
path: root/synapse/visibility.py
diff options
context:
space:
mode:
authorBrendan Abolivier <babolivier@matrix.org>2019-11-04 17:09:22 +0000
committerBrendan Abolivier <babolivier@matrix.org>2019-11-04 17:09:22 +0000
commit09957ce0e4dcfd84c2de4039653059faae03065b (patch)
treefc31ab750a3c485a0cfb9d23b0ab52114a91d954 /synapse/visibility.py
parentMerge pull request #6301 from matrix-org/babolivier/msc2326 (diff)
downloadsynapse-09957ce0e4dcfd84c2de4039653059faae03065b.tar.xz
Implement per-room message retention policies
Diffstat (limited to 'synapse/visibility.py')
-rw-r--r--synapse/visibility.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/synapse/visibility.py b/synapse/visibility.py
index 8c843febd8..4498c156bc 100644
--- a/synapse/visibility.py
+++ b/synapse/visibility.py
@@ -86,6 +86,14 @@ def filter_events_for_client(
 
     erased_senders = yield storage.main.are_users_erased((e.sender for e in events))
 
+    room_ids = set(e.room_id for e in events)
+    retention_policies = {}
+
+    for room_id in room_ids:
+        retention_policies[room_id] = yield storage.main.get_retention_policy_for_room(
+            room_id
+        )
+
     def allowed(event):
         """
         Args:
@@ -103,6 +111,15 @@ def filter_events_for_client(
         if not event.is_state() and event.sender in ignore_list:
             return None
 
+        retention_policy = retention_policies[event.room_id]
+        max_lifetime = retention_policy.get("max_lifetime")
+
+        if max_lifetime is not None:
+            oldest_allowed_ts = storage.main.clock.time_msec() - max_lifetime
+
+            if event.origin_server_ts < oldest_allowed_ts:
+                return None
+
         if event.event_id in always_include_ids:
             return event