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

Commit

Permalink
hacks to work around #6605
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Dec 30, 2019
1 parent f03c877 commit b3d344c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions synapse/state/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,16 @@ def _get_power_level_for_sender(room_id, event_id, event_map, state_res_store):

pl = None
for aid in event.auth_event_ids():
aev = yield _get_event(room_id, aid, event_map, state_res_store)
if (aev.type, aev.state_key) == (EventTypes.PowerLevels, ""):
aev = yield _get_event(room_id, aid, event_map, state_res_store, allow_none=True)
if aev and (aev.type, aev.state_key) == (EventTypes.PowerLevels, ""):
pl = aev
break

if pl is None:
# Couldn't find power level. Check if they're the creator of the room
for aid in event.auth_event_ids():
aev = yield _get_event(room_id, aid, event_map, state_res_store)
if (aev.type, aev.state_key) == (EventTypes.Create, ""):
aev = yield _get_event(room_id, aid, event_map, state_res_store, allow_none=True)
if aev and (aev.type, aev.state_key) == (EventTypes.Create, ""):
if aev.content.get("creator") == event.sender:
return 100
break
Expand Down Expand Up @@ -403,9 +403,9 @@ def _iterative_auth_checks(

auth_events = {}
for aid in event.auth_event_ids():
ev = yield _get_event(room_id, aid, event_map, state_res_store)
ev = yield _get_event(room_id, aid, event_map, state_res_store, allow_none=True)

if ev.rejected_reason is None:
if ev and ev.rejected_reason is None:
auth_events[(ev.type, ev.state_key)] = ev

for key in event_auth.auth_types_for_event(event):
Expand Down Expand Up @@ -516,7 +516,7 @@ def _get_mainline_depth_for_event(event, mainline_map, event_map, state_res_stor


@defer.inlineCallbacks
def _get_event(room_id, event_id, event_map, state_res_store):
def _get_event(room_id, event_id, event_map, state_res_store, allow_none=False):
"""Helper function to look up event in event_map, falling back to looking
it up in the store
Expand All @@ -532,7 +532,9 @@ def _get_event(room_id, event_id, event_map, state_res_store):
if event_id not in event_map:
events = yield state_res_store.get_events([event_id], allow_rejected=True)
event_map.update(events)
event = event_map[event_id]
event = event_map.get(event_id)
if allow_none and event is None:
return None
assert event is not None
if event.room_id != room_id:
raise Exception(
Expand Down

0 comments on commit b3d344c

Please sign in to comment.