Fix media timeline to load in encrypted rooms

When loading the timeline, the messages retrieved were always filtered by the event type `RoomMessage` and by those with URLs. However, when encryption is used, the event type for all messages are 'RoomEncrypted' and the contents cannot be filtered by URL. The fix changed to filter for events of type `RoomEncrypted` and `RoomMessage` when the room has encryption enabled, and leaving the filter unchanged otherwise.

Fixes #1322.
This commit is contained in:
Jonathan Lin 2023-12-11 21:15:20 -06:00 committed by Kévin Commaille
parent 77459b05da
commit a6d10c65e5
1 changed files with 20 additions and 6 deletions

View File

@ -133,15 +133,29 @@ impl Timeline {
self.set_state(TimelineState::Loading);
let matrix_room = self.room().matrix_room();
let room = self.room();
let matrix_room = room.matrix_room();
let last_token = imp.last_token.clone();
let is_encrypted = room.is_encrypted();
let handle: tokio::task::JoinHandle<matrix_sdk::Result<_>> = spawn_tokio!(async move {
let last_token = last_token.lock().await;
let filter_types = vec![MessageLikeEventType::RoomMessage.to_string()];
let filter = assign!(RoomEventFilter::default(), {
types: Some(filter_types),
url_filter: Some(UrlFilter::EventsWithUrl),
});
// If the room is encrypted, the messages content cannot be filtered with URLs
let filter = if is_encrypted {
let filter_types = vec![
MessageLikeEventType::RoomEncrypted.to_string(),
MessageLikeEventType::RoomMessage.to_string(),
];
assign!(RoomEventFilter::default(), {
types: Some(filter_types),
})
} else {
let filter_types = vec![MessageLikeEventType::RoomMessage.to_string()];
assign!(RoomEventFilter::default(), {
types: Some(filter_types),
url_filter: Some(UrlFilter::EventsWithUrl),
})
};
let options = assign!(MessagesOptions::backward().from(&**last_token), {
limit: uint!(20),
filter,