Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2451 from matrix-org/erikj/add_state_to_timeline
Browse files Browse the repository at this point in the history
Don't filter out current state events from timeline
  • Loading branch information
erikjohnston authored Sep 18, 2017
2 parents 862c8da + 2d1b795 commit 77c81ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 7 additions & 0 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ def _load_filtered_recents(self, room_id, sync_config, now_token,
timeline_limit = sync_config.filter_collection.timeline_limit()
block_all_timeline = sync_config.filter_collection.blocks_all_room_timeline()

# Pull out the current state, as we always want to include those events
# in the timeline if they're there.
current_state_ids = yield self.state.get_current_state_ids(room_id)
current_state_ids = frozenset(current_state_ids.itervalues())

if recents is None or newly_joined_room or timeline_limit < len(recents):
limited = True
else:
Expand All @@ -304,6 +309,7 @@ def _load_filtered_recents(self, room_id, sync_config, now_token,
self.store,
sync_config.user.to_string(),
recents,
always_include_ids=current_state_ids,
)
else:
recents = []
Expand Down Expand Up @@ -339,6 +345,7 @@ def _load_filtered_recents(self, room_id, sync_config, now_token,
self.store,
sync_config.user.to_string(),
loaded_recents,
always_include_ids=current_state_ids,
)
loaded_recents.extend(recents)
recents = loaded_recents
Expand Down
14 changes: 11 additions & 3 deletions synapse/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@


@defer.inlineCallbacks
def filter_events_for_clients(store, user_tuples, events, event_id_to_state):
def filter_events_for_clients(store, user_tuples, events, event_id_to_state,
always_include_ids=frozenset()):
""" Returns dict of user_id -> list of events that user is allowed to
see.
Expand All @@ -54,6 +55,8 @@ def filter_events_for_clients(store, user_tuples, events, event_id_to_state):
* the user has not been a member of the room since the
given events
events ([synapse.events.EventBase]): list of events to filter
always_include_ids (set(event_id)): set of event ids to specifically
include (unless sender is ignored)
"""
forgotten = yield preserve_context_over_deferred(defer.gatherResults([
defer.maybeDeferred(
Expand Down Expand Up @@ -91,6 +94,9 @@ def allowed(event, user_id, is_peeking, ignore_list):
if not event.is_state() and event.sender in ignore_list:
return False

if event.event_id in always_include_ids:
return True

state = event_id_to_state[event.event_id]

# get the room_visibility at the time of the event.
Expand Down Expand Up @@ -189,7 +195,8 @@ def allowed(event, user_id, is_peeking, ignore_list):


@defer.inlineCallbacks
def filter_events_for_client(store, user_id, events, is_peeking=False):
def filter_events_for_client(store, user_id, events, is_peeking=False,
always_include_ids=frozenset()):
"""
Check which events a user is allowed to see
Expand All @@ -213,6 +220,7 @@ def filter_events_for_client(store, user_id, events, is_peeking=False):
types=types
)
res = yield filter_events_for_clients(
store, [(user_id, is_peeking)], events, event_id_to_state
store, [(user_id, is_peeking)], events, event_id_to_state,
always_include_ids=always_include_ids,
)
defer.returnValue(res.get(user_id, []))

0 comments on commit 77c81ca

Please sign in to comment.