Skip to content

Commit 4fbc83a

Browse files
authored
Merge pull request #5746 from matrix-org/poljar/event-cache/redecryptor
2 parents f702364 + 9508675 commit 4fbc83a

File tree

4 files changed

+1195
-2
lines changed

4 files changed

+1195
-2
lines changed

crates/matrix-sdk-ui/src/timeline/tests/encryption.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,17 @@ async fn test_retry_edit_decryption() {
424424
assert!(msg.is_edited());
425425
assert_eq!(msg.body(), "This is Error");
426426

427+
let item =
428+
assert_next_matches_with_timeout!(stream, VectorDiff::Set { index: 0, value } => value);
429+
430+
// TODO: We receive this update twice, since the event cache decrypts things as
431+
// well as the timeline.
432+
assert_matches!(item.encryption_info(), Some(_));
433+
assert_matches!(item.latest_edit_json(), Some(_));
434+
assert_let!(Some(msg) = item.content().as_message());
435+
assert!(msg.is_edited());
436+
assert_eq!(msg.body(), "This is Error");
437+
427438
// (There are no more items)
428439
assert_pending!(stream);
429440
}

crates/matrix-sdk/src/event_cache/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,13 @@ use crate::{
7474

7575
mod deduplicator;
7676
mod pagination;
77+
#[cfg(feature = "e2e-encryption")]
78+
mod redecryptor;
7779
mod room;
7880

7981
pub use pagination::{RoomPagination, RoomPaginationStatus};
82+
#[cfg(feature = "e2e-encryption")]
83+
pub use redecryptor::{DecryptionRetryRequest, RedecryptorReport};
8084
pub use room::{RoomEventCache, RoomEventCacheSubscriber, ThreadEventCacheUpdate};
8185

8286
/// An error observed in the [`EventCache`].
@@ -148,6 +152,10 @@ pub struct EventCacheDropHandles {
148152

149153
/// The task used to automatically shrink the linked chunks.
150154
auto_shrink_linked_chunk_task: JoinHandle<()>,
155+
156+
/// The task used to automatically redecrypt UTDs.
157+
#[cfg(feature = "e2e-encryption")]
158+
_redecryptor: redecryptor::Redecryptor,
151159
}
152160

153161
impl fmt::Debug for EventCacheDropHandles {
@@ -200,6 +208,9 @@ impl EventCache {
200208
linked_chunk_update_sender.clone(),
201209
)));
202210

211+
#[cfg(feature = "e2e-encryption")]
212+
let redecryption_channels = redecryptor::RedecryptorChannels::new();
213+
203214
Self {
204215
inner: Arc::new(EventCacheInner {
205216
client,
@@ -213,6 +224,8 @@ impl EventCache {
213224
_thread_subscriber_task: thread_subscriber_task,
214225
#[cfg(feature = "experimental-search")]
215226
_search_indexing_task: search_indexing_task,
227+
#[cfg(feature = "e2e-encryption")]
228+
redecryption_channels,
216229
thread_subscriber_receiver,
217230
}),
218231
}
@@ -257,10 +270,26 @@ impl EventCache {
257270
auto_shrink_receiver,
258271
));
259272

273+
#[cfg(feature = "e2e-encryption")]
274+
let redecryptor = {
275+
let receiver = self
276+
.inner
277+
.redecryption_channels
278+
.decryption_request_receiver
279+
.lock()
280+
.take()
281+
.expect("We should have initialized the channel an subscribing should happen only once");
282+
283+
redecryptor::Redecryptor::new(Arc::downgrade(&self.inner), receiver)
284+
};
285+
286+
260287
Arc::new(EventCacheDropHandles {
261288
listen_updates_task,
262289
ignore_user_list_update_task,
263290
auto_shrink_linked_chunk_task,
291+
#[cfg(feature = "e2e-encryption")]
292+
_redecryptor: redecryptor,
264293
})
265294
});
266295

@@ -840,6 +869,9 @@ struct EventCacheInner {
840869
/// This is helpful for tests to coordinate that a new thread subscription
841870
/// has been sent or not.
842871
thread_subscriber_receiver: Receiver<()>,
872+
873+
#[cfg(feature = "e2e-encryption")]
874+
redecryption_channels: redecryptor::RedecryptorChannels,
843875
}
844876

845877
type AutoShrinkChannelPayload = OwnedRoomId;

0 commit comments

Comments
 (0)