summary refs log tree commit diff
path: root/synapse/visibility.py
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-03-16 19:21:18 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2020-03-16 19:21:18 +0000
commit6d29b5342449316944ffd26a5d61f5a7600298b7 (patch)
tree49d72fbfb565287ab59b45ad7b35fb85f417377b /synapse/visibility.py
parentExpose some homeserver functionality to spam checkers (#6259) (diff)
parentMerge pull request #6294 from matrix-org/erikj/add_state_storage (diff)
downloadsynapse-6d29b5342449316944ffd26a5d61f5a7600298b7.tar.xz
Merge pull request #6294 from matrix-org/erikj/add_state_storage
Diffstat (limited to 'synapse/visibility.py')
-rw-r--r--synapse/visibility.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/synapse/visibility.py b/synapse/visibility.py
index a19011b793..c0e39f5be6 100644
--- a/synapse/visibility.py
+++ b/synapse/visibility.py
@@ -23,6 +23,7 @@ from twisted.internet import defer
 
 from synapse.api.constants import EventTypes, Membership
 from synapse.events.utils import prune_event
+from synapse.storage import Storage
 from synapse.storage.state import StateFilter
 from synapse.types import get_domain_from_id
 
@@ -43,7 +44,7 @@ MEMBERSHIP_PRIORITY = (
 
 @defer.inlineCallbacks
 def filter_events_for_client(
-    store,
+    storage: Storage,
     user_id,
     events,
     is_peeking=False,
@@ -54,8 +55,7 @@ def filter_events_for_client(
     Check which events a user is allowed to see
 
     Args:
-        store (synapse.storage.DataStore): our datastore (can also be a worker
-            store)
+        storage
         user_id(str): user id to be checked
         events(list[synapse.events.EventBase]): sequence of events to be checked
         is_peeking(bool): should be True if:
@@ -77,12 +77,12 @@ def filter_events_for_client(
     events = list(e for e in events if not e.internal_metadata.is_soft_failed())
 
     types = ((EventTypes.RoomHistoryVisibility, ""), (EventTypes.Member, user_id))
-    event_id_to_state = yield store.get_state_for_events(
+    event_id_to_state = yield storage.state.get_state_for_events(
         frozenset(e.event_id for e in events),
         state_filter=StateFilter.from_types(types),
     )
 
-    ignore_dict_content = yield store.get_global_account_data_by_type_for_user(
+    ignore_dict_content = yield storage.main.get_global_account_data_by_type_for_user(
         "m.ignored_user_list", user_id
     )
 
@@ -93,7 +93,7 @@ def filter_events_for_client(
         else []
     )
 
-    erased_senders = yield store.are_users_erased((e.sender for e in events))
+    erased_senders = yield storage.main.are_users_erased((e.sender for e in events))
 
     if apply_retention_policies:
         room_ids = set(e.room_id for e in events)
@@ -101,7 +101,7 @@ def filter_events_for_client(
 
         for room_id in room_ids:
             retention_policies[room_id] = (
-                yield store.get_retention_policy_for_room(room_id)
+                yield storage.main.get_retention_policy_for_room(room_id)
             )
 
     def allowed(event):
@@ -128,7 +128,7 @@ def filter_events_for_client(
             max_lifetime = retention_policy.get("max_lifetime")
 
             if max_lifetime is not None:
-                oldest_allowed_ts = store.clock.time_msec() - max_lifetime
+                oldest_allowed_ts = storage.main.clock.time_msec() - max_lifetime
 
                 if event.origin_server_ts < oldest_allowed_ts:
                     return None
@@ -243,13 +243,17 @@ def filter_events_for_client(
 
 @defer.inlineCallbacks
 def filter_events_for_server(
-    store, server_name, events, redact=True, check_history_visibility_only=False
+    storage: Storage,
+    server_name,
+    events,
+    redact=True,
+    check_history_visibility_only=False,
 ):
     """Filter a list of events based on whether given server is allowed to
     see them.
 
     Args:
-        store (DataStore)
+        storage
         server_name (str)
         events (iterable[FrozenEvent])
         redact (bool): Whether to return a redacted version of the event, or
@@ -304,7 +308,7 @@ def filter_events_for_server(
     # Lets check to see if all the events have a history visibility
     # of "shared" or "world_readable". If thats the case then we don't
     # need to check membership (as we know the server is in the room).
-    event_to_state_ids = yield store.get_state_ids_for_events(
+    event_to_state_ids = yield storage.state.get_state_ids_for_events(
         frozenset(e.event_id for e in events),
         state_filter=StateFilter.from_types(
             types=((EventTypes.RoomHistoryVisibility, ""),)
@@ -322,14 +326,14 @@ def filter_events_for_server(
     if not visibility_ids:
         all_open = True
     else:
-        event_map = yield store.get_events(visibility_ids)
+        event_map = yield storage.main.get_events(visibility_ids)
         all_open = all(
             e.content.get("history_visibility") in (None, "shared", "world_readable")
             for e in itervalues(event_map)
         )
 
     if not check_history_visibility_only:
-        erased_senders = yield store.are_users_erased((e.sender for e in events))
+        erased_senders = yield storage.main.are_users_erased((e.sender for e in events))
     else:
         # We don't want to check whether users are erased, which is equivalent
         # to no users having been erased.
@@ -358,7 +362,7 @@ def filter_events_for_server(
 
     # first, for each event we're wanting to return, get the event_ids
     # of the history vis and membership state at those events.
-    event_to_state_ids = yield store.get_state_ids_for_events(
+    event_to_state_ids = yield storage.state.get_state_ids_for_events(
         frozenset(e.event_id for e in events),
         state_filter=StateFilter.from_types(
             types=((EventTypes.RoomHistoryVisibility, ""), (EventTypes.Member, None))
@@ -388,7 +392,7 @@ def filter_events_for_server(
             return False
         return state_key[idx + 1 :] == server_name
 
-    event_map = yield store.get_events(
+    event_map = yield storage.main.get_events(
         [
             e_id
             for e_id, key in iteritems(event_id_to_state_key)