Skip to content

Commit 01059ef

Browse files
committed
refactor(timeline): Make RoomDataProvider provide Decryptor to simplify redecryption
1 parent 7724271 commit 01059ef

File tree

5 files changed

+186
-142
lines changed

5 files changed

+186
-142
lines changed

crates/matrix-sdk-ui/src/timeline/controller/mod.rs

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ use eyeball_im_util::vector::{FilterMap, VectorObserverExt};
2121
use futures_core::Stream;
2222
use imbl::Vector;
2323
#[cfg(test)]
24-
use matrix_sdk::crypto::OlmMachine;
24+
use matrix_sdk::Result;
2525
use matrix_sdk::{
26-
Result, Room,
2726
deserialized_responses::TimelineEvent,
2827
event_cache::{RoomEventCache, RoomPaginationStatus},
2928
paginators::{PaginationResult, Paginator},
3029
send_queue::{
3130
LocalEcho, LocalEchoContent, RoomSendQueueUpdate, SendHandle, SendReactionHandle,
3231
},
3332
};
33+
#[cfg(test)]
34+
use ruma::events::receipt::ReceiptEventContent;
3435
use ruma::{
3536
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedTransactionId, TransactionId, UserId,
3637
api::client::receipt::create_receipt::v3::ReceiptType as SendReceiptType,
@@ -46,8 +47,6 @@ use ruma::{
4647
room_version_rules::RoomVersionRules,
4748
serde::Raw,
4849
};
49-
#[cfg(test)]
50-
use ruma::{OwnedRoomId, RoomId, events::receipt::ReceiptEventContent};
5150
use tokio::sync::{RwLock, RwLockWriteGuard};
5251
use tracing::{debug, error, field::debug, info, instrument, trace, warn};
5352

@@ -68,11 +67,11 @@ use super::{
6867
event_item::{ReactionStatus, RemoteEventOrigin},
6968
item::TimelineUniqueId,
7069
subscriber::TimelineSubscriber,
71-
traits::{Decryptor, RoomDataProvider},
70+
traits::RoomDataProvider,
7271
};
7372
use crate::{
7473
timeline::{
75-
MsgLikeContent, MsgLikeKind, TimelineEventFilterFn,
74+
MsgLikeContent, MsgLikeKind, Room, TimelineEventFilterFn,
7675
algorithms::rfind_event_by_item_id,
7776
date_dividers::DateDividerAdjuster,
7877
event_item::TimelineItemHandle,
@@ -152,7 +151,7 @@ impl<P: RoomDataProvider> TimelineFocusKind<P> {
152151
}
153152

154153
#[derive(Clone, Debug)]
155-
pub(super) struct TimelineController<P: RoomDataProvider = Room, D: Decryptor = Room> {
154+
pub(super) struct TimelineController<P: RoomDataProvider = Room> {
156155
/// Inner mutable state.
157156
state: Arc<RwLock<TimelineState<P>>>,
158157

@@ -161,15 +160,16 @@ pub(super) struct TimelineController<P: RoomDataProvider = Room, D: Decryptor =
161160

162161
/// A [`RoomDataProvider`] implementation, providing data.
163162
///
164-
/// Useful for testing only; in the real world, it's just a [`Room`].
163+
/// The type is a `RoomDataProvider` to allow testing. In the real world,
164+
/// this would normally be a [`Room`].
165165
pub(crate) room_data_provider: P,
166166

167167
/// Settings applied to this timeline.
168168
pub(super) settings: TimelineSettings,
169169

170170
/// Long-running task used to retry decryption of timeline items without
171171
/// blocking main processing.
172-
decryption_retry_task: DecryptionRetryTask<P, D>,
172+
decryption_retry_task: DecryptionRetryTask<P, P>,
173173
}
174174

175175
#[derive(Clone)]
@@ -290,7 +290,7 @@ pub fn default_event_filter(event: &AnySyncTimelineEvent, rules: &RoomVersionRul
290290
}
291291
}
292292

293-
impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
293+
impl<P: RoomDataProvider> TimelineController<P> {
294294
pub(super) fn new(
295295
room_data_provider: P,
296296
focus: TimelineFocus,
@@ -1103,12 +1103,10 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
11031103
true
11041104
}
11051105

1106-
async fn retry_event_decryption_inner(
1107-
&self,
1108-
decryptor: D,
1109-
session_ids: Option<BTreeSet<String>>,
1110-
) {
1111-
self.decryption_retry_task.decrypt(decryptor, session_ids, self.settings.clone()).await;
1106+
pub(crate) async fn retry_event_decryption_inner(&self, session_ids: Option<BTreeSet<String>>) {
1107+
self.decryption_retry_task
1108+
.decrypt(self.room_data_provider.clone(), session_ids, self.settings.clone())
1109+
.await;
11121110
}
11131111

11141112
pub(super) async fn set_sender_profiles_pending(&self) {
@@ -1250,7 +1248,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
12501248
/// Subscribe to changes in the read receipts of our own user.
12511249
pub async fn subscribe_own_user_read_receipts_changed(
12521250
&self,
1253-
) -> impl Stream<Item = ()> + use<P, D> {
1251+
) -> impl Stream<Item = ()> + use<P> {
12541252
self.state.read().await.meta.read_receipts.subscribe_own_user_read_receipts_changed()
12551253
}
12561254

@@ -1604,7 +1602,7 @@ impl TimelineController {
16041602

16051603
#[instrument(skip(self), fields(room_id = ?self.room().room_id()))]
16061604
pub(super) async fn retry_event_decryption(&self, session_ids: Option<BTreeSet<String>>) {
1607-
self.retry_event_decryption_inner(self.room().clone(), session_ids).await
1605+
self.retry_event_decryption_inner(session_ids).await
16081606
}
16091607

16101608
/// Combine the global (event cache) pagination status with the local state
@@ -1638,18 +1636,6 @@ impl TimelineController {
16381636
}
16391637
}
16401638

1641-
#[cfg(test)]
1642-
impl<P: RoomDataProvider> TimelineController<P, (OlmMachine, OwnedRoomId)> {
1643-
pub(super) async fn retry_event_decryption_test(
1644-
&self,
1645-
room_id: &RoomId,
1646-
olm_machine: OlmMachine,
1647-
session_ids: Option<BTreeSet<String>>,
1648-
) {
1649-
self.retry_event_decryption_inner((olm_machine, room_id.to_owned()), session_ids).await
1650-
}
1651-
}
1652-
16531639
#[allow(clippy::too_many_arguments)]
16541640
async fn fetch_replied_to_event<P: RoomDataProvider>(
16551641
mut state_guard: RwLockWriteGuard<'_, TimelineState<P>>,

0 commit comments

Comments
 (0)