From fd4821c3ec58af35ec0ea4c16aedfcf7e2bfba43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 19 Nov 2025 13:40:44 +0100 Subject: [PATCH] refactor(redecryptor): Make the filter closure a function --- .../matrix-sdk/src/event_cache/redecryptor.rs | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/matrix-sdk/src/event_cache/redecryptor.rs b/crates/matrix-sdk/src/event_cache/redecryptor.rs index 52055bb12..2c21f40a8 100644 --- a/crates/matrix-sdk/src/event_cache/redecryptor.rs +++ b/crates/matrix-sdk/src/event_cache/redecryptor.rs @@ -198,6 +198,23 @@ impl RedecryptorChannels { } } +/// A function that can be used to filter and map [`TimelineEvent`]s into a +/// tuple of event ID and raw [`AnySyncTimelineEvent`]. +/// +/// The tuple can be used to attempt to redecrypt events. +fn filter_timeline_event_to_utd( + event: TimelineEvent, +) -> Option<(OwnedEventId, Raw)> { + let event_id = event.event_id(); + + // Only pick out events that are UTDs, get just the Raw event as this is what + // the OlmMachine needs. + let event = as_variant!(event.kind, TimelineEventKind::UnableToDecrypt { event, .. } => event); + // Zip the event ID and event together so we don't have to pick out the event ID + // again. We need the event ID to replace the event in the cache. + event_id.zip(event) +} + impl EventCache { /// Retrieve a set of events that we weren't able to decrypt. /// @@ -211,24 +228,12 @@ impl EventCache { room_id: &RoomId, session_id: SessionId<'_>, ) -> Result, EventCacheError> { - let filter = |event: TimelineEvent| { - let event_id = event.event_id(); - - // Only pick out events that are UTDs, get just the Raw event as this is what - // the OlmMachine needs. - let event = - as_variant!(event.kind, TimelineEventKind::UnableToDecrypt { event, .. } => event); - // Zip the event ID and event together so we don't have to pick out the event ID - // again. We need the event ID to replace the event in the cache. - event_id.zip(event) - }; - let events = { let store = self.inner.store.lock().await?; store.get_room_events(room_id, Some("m.room.encrypted"), Some(session_id)).await? }; - Ok(events.into_iter().filter_map(filter).collect()) + Ok(events.into_iter().filter_map(filter_timeline_event_to_utd).collect()) } async fn get_decrypted_events(