Handle empty/invalid state event content in _get_initial_state()

Fixes #171
This commit is contained in:
Tulir Asokan
2018-07-10 14:24:08 +03:00
parent 7a4d29e1e4
commit 0a171d242f
+12 -8
View File
@@ -307,14 +307,18 @@ async def _get_initial_state(evt: CommandEvent):
about = None
levels = None
for event in state:
if event["type"] == "m.room.name":
title = event["content"]["name"]
elif event["type"] == "m.room.topic":
about = event["content"]["topic"]
elif event["type"] == "m.room.power_levels":
levels = event["content"]
elif event["type"] == "m.room.canonical_alias":
title = title or event["content"]["alias"]
try:
if event["type"] == "m.room.name":
title = event["content"]["name"]
elif event["type"] == "m.room.topic":
about = event["content"]["topic"]
elif event["type"] == "m.room.power_levels":
levels = event["content"]
elif event["type"] == "m.room.canonical_alias":
title = title or event["content"]["alias"]
except KeyError:
# Some state event probably has empty content
pass
return title, about, levels