matrix-org / matrix-rust-sdk

Matrix Client-Server SDK for Rust
Apache License 2.0
1.19k stars 235 forks source link

Historical messages decrypt on cache reloading, but not before #3768

Closed richvdh closed 3 days ago

richvdh commented 1 month ago

Steps to reproduce

Sign into a new instance of Element X Verify your device Open some chats with historic E2EE message, those messages can appear as UTDs Clear EX cache in developer settings All historic messages are now decrypted properly

Outcome

What did you expect?

Historic messages decrypt successfully, and are displayed as such, without having to cache reload.

What happened instead?

Historic messages that are shown as UTDs in the timeline seem stuck that way indefinitely. It could be that the keys are being downloaded or processed at the same time as a user trying to open the message, EX is unable to show the message and presents it as a UTD, and subsequently doesn't attempt to decrypt the message again in future.

richvdh commented 1 month ago

This is tracked on the EXA and EXI repos as https://github.com/element-hq/element-x-android/issues/3234 and https://github.com/element-hq/element-x-ios/issues/3055 respectively

manuroe commented 1 month ago

If the user paginates in the room, the received paginated messages get decrypted in the timeline. The 20-30 last messages on the room stay UTDs but previous messages are decrypted.

Since client side sorting, we have a mechanism to prefill the room timeline from the room list by subscribing to each displayed rooms. The decryption retries may fail in this condition or they succeed but we fail to notify the UI of the timeline.

poljar commented 1 month ago

I think it's rather that events are received before the backup becomes active, and the timeline doesn't listen for the backup becoming active.

It should listen to the backup becoming active and retry the decryption of all events, since we download room keys on demand, i.e. when we fail to decrypt a event.

Relevant code should be here:

https://github.com/matrix-org/matrix-rust-sdk/blob/68c612f2b92f8c5621b340da101cd44bceec4435/crates/matrix-sdk-ui/src/timeline/builder.rs#L322-L349