Skip to content

Commit

Permalink
Fix deserializing encrypted edits. Fixes mautrix/telegram#623
Browse files Browse the repository at this point in the history
Replacing the top-level content with the new content happens in the
deserialization stage, but inserting `m.relates_to` was only happening
after deserializing. This commit moves copying `m.relates_to` to before
the deserialization so that edit fallbacks are removed appropriately.
  • Loading branch information
tulir committed Jun 22, 2021
1 parent b00bb2f commit 41a9327
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions mautrix/crypto/decrypt_megolm.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ async def decrypt_megolm_event(self, evt: EncryptedEvent) -> Event:
if room_id != evt.room_id:
raise MismatchingRoomError()

if evt.content.relates_to and "m.relates_to" not in content:
content["m.relates_to"] = evt.content.relates_to.serialize()
result = Event.deserialize({
"room_id": evt.room_id,
"event_id": evt.event_id,
Expand All @@ -83,12 +85,6 @@ async def decrypt_megolm_event(self, evt: EncryptedEvent) -> Event:
"content": content,
})
result.unsigned = evt.unsigned
if evt.content.relates_to:
if hasattr(result.content, "relates_to"):
if not result.content.relates_to:
result.content.relates_to = evt.content.relates_to
elif "m.relates_to" not in result.content:
result.content["m.relates_to"] = evt.content.relates_to.serialize()
result.type = result.type.with_class(evt.type.t_class)
result["mautrix"] = {
"verified": verified,
Expand Down

0 comments on commit 41a9327

Please sign in to comment.