Skip to content

Commit 40df8dc

Browse files
committed
refactor(timeline): Make RoomDataProvider provide Decryptor to simplify redecryption
1 parent 6c944a9 commit 40df8dc

File tree

5 files changed

+185
-142
lines changed

5 files changed

+185
-142
lines changed

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

Lines changed: 15 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,15 @@ 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+
/// In the real world, this is just a [`Room`].
165164
pub(crate) room_data_provider: P,
166165

167166
/// Settings applied to this timeline.
168167
pub(super) settings: TimelineSettings,
169168

170169
/// Long-running task used to retry decryption of timeline items without
171170
/// blocking main processing.
172-
decryption_retry_task: DecryptionRetryTask<P, D>,
171+
decryption_retry_task: DecryptionRetryTask<P, P>,
173172
}
174173

175174
#[derive(Clone)]
@@ -290,7 +289,7 @@ pub fn default_event_filter(event: &AnySyncTimelineEvent, rules: &RoomVersionRul
290289
}
291290
}
292291

293-
impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
292+
impl<P: RoomDataProvider> TimelineController<P> {
294293
pub(super) fn new(
295294
room_data_provider: P,
296295
focus: TimelineFocus,
@@ -1099,12 +1098,10 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
10991098
true
11001099
}
11011100

1102-
async fn retry_event_decryption_inner(
1103-
&self,
1104-
decryptor: D,
1105-
session_ids: Option<BTreeSet<String>>,
1106-
) {
1107-
self.decryption_retry_task.decrypt(decryptor, session_ids, self.settings.clone()).await;
1101+
pub(crate) async fn retry_event_decryption_inner(&self, session_ids: Option<BTreeSet<String>>) {
1102+
self.decryption_retry_task
1103+
.decrypt(self.room_data_provider.clone(), session_ids, self.settings.clone())
1104+
.await;
11081105
}
11091106

11101107
pub(super) async fn set_sender_profiles_pending(&self) {
@@ -1246,7 +1243,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
12461243
/// Subscribe to changes in the read receipts of our own user.
12471244
pub async fn subscribe_own_user_read_receipts_changed(
12481245
&self,
1249-
) -> impl Stream<Item = ()> + use<P, D> {
1246+
) -> impl Stream<Item = ()> + use<P> {
12501247
self.state.read().await.meta.read_receipts.subscribe_own_user_read_receipts_changed()
12511248
}
12521249

@@ -1591,7 +1588,7 @@ impl TimelineController {
15911588

15921589
#[instrument(skip(self), fields(room_id = ?self.room().room_id()))]
15931590
pub(super) async fn retry_event_decryption(&self, session_ids: Option<BTreeSet<String>>) {
1594-
self.retry_event_decryption_inner(self.room().clone(), session_ids).await
1591+
self.retry_event_decryption_inner(session_ids).await
15951592
}
15961593

15971594
/// Combine the global (event cache) pagination status with the local state
@@ -1625,18 +1622,6 @@ impl TimelineController {
16251622
}
16261623
}
16271624

1628-
#[cfg(test)]
1629-
impl<P: RoomDataProvider> TimelineController<P, (OlmMachine, OwnedRoomId)> {
1630-
pub(super) async fn retry_event_decryption_test(
1631-
&self,
1632-
room_id: &RoomId,
1633-
olm_machine: OlmMachine,
1634-
session_ids: Option<BTreeSet<String>>,
1635-
) {
1636-
self.retry_event_decryption_inner((olm_machine, room_id.to_owned()), session_ids).await
1637-
}
1638-
}
1639-
16401625
#[allow(clippy::too_many_arguments)]
16411626
async fn fetch_replied_to_event<P: RoomDataProvider>(
16421627
mut state_guard: RwLockWriteGuard<'_, TimelineState<P>>,

0 commit comments

Comments
 (0)