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

Commit

Permalink
Make v1 initial syncs respect room history ACL
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jul 2, 2015
1 parent 1a60545 commit 41938af
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,41 +120,50 @@ def get_messages(self, user_id=None, room_id=None, pagin_config=None,
"end": next_token.to_string(),
})

events = yield self._filter_events_for_client(user_id, room_id, events)

time_now = self.clock.time_msec()

chunk = {
"chunk": [
serialize_event(e, time_now, as_client_event)
for e in events
],
"start": pagin_config.from_token.to_string(),
"end": next_token.to_string(),
}

defer.returnValue(chunk)

@defer.inlineCallbacks
def _filter_events_for_client(self, user_id, room_id, events):
states = yield self.store.get_state_for_events(
room_id, [e.event_id for e in events],
)

events_and_states = zip(events, states)

def allowed(event_and_state):
_, state = event_and_state
event, state = event_and_state

if event.type == EventTypes.RoomHistoryVisibility:
return True

membership = state.get((EventTypes.Member, user_id), None)
if membership and membership.membership == Membership.JOIN:
return True

history = state.get((EventTypes.RoomHistoryVisibility, ''), None)
if history and history.content["visibility"] == "after_join":
if history and history.content.get("visibility", None) == "after_join":
return False

return True

events_and_states = filter(allowed, events_and_states)
events = [
defer.returnValue([
ev
for ev, _ in events_and_states
]

time_now = self.clock.time_msec()

chunk = {
"chunk": [
serialize_event(e, time_now, as_client_event)
for e in events
],
"start": pagin_config.from_token.to_string(),
"end": next_token.to_string(),
}

defer.returnValue(chunk)
])

@defer.inlineCallbacks
def create_and_send_event(self, event_dict, ratelimit=True,
Expand Down Expand Up @@ -347,6 +356,10 @@ def handle_room(event):
]
).addErrback(unwrapFirstError)

messages = yield self._filter_events_for_client(
user_id, event.room_id, messages
)

start_token = now_token.copy_and_replace("room_key", token[0])
end_token = now_token.copy_and_replace("room_key", token[1])
time_now = self.clock.time_msec()
Expand Down Expand Up @@ -448,6 +461,10 @@ def get_presence():
consumeErrors=True,
).addErrback(unwrapFirstError)

messages = yield self._filter_events_for_client(
user_id, room_id, messages
)

start_token = now_token.copy_and_replace("room_key", token[0])
end_token = now_token.copy_and_replace("room_key", token[1])

Expand Down

0 comments on commit 41938af

Please sign in to comment.