Skip to content

Commit 42ee967

Browse files
committed
feat(sdk): Add RoomEventCache::rfind_event_in_memory_by.
This patch introduces a new method named `RoomEventCache::rfind_event_in_memory_by` to look for an in-memory event, starting from the most recent event, by applying a predicate closure on each event.
1 parent 4c7575b commit 42ee967

File tree

1 file changed

+26
-0
lines changed
  • crates/matrix-sdk/src/event_cache/room

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ impl RoomEventCache {
214214
RoomPagination { inner: self.inner.clone() }
215215
}
216216

217+
/// Try to find a single event in this room, starting from the most recent
218+
/// event.
219+
///
220+
/// **Warning**! It looks into the loaded events from the in-memory linked
221+
/// chunk **only**. It doesn't look inside the storage.
222+
pub async fn rfind_event_in_memory_by<P>(&self, predicate: P) -> Option<Event>
223+
where
224+
P: FnMut(&Event) -> bool,
225+
{
226+
self.inner.state.read().await.rfind_event_in_memory_by(predicate)
227+
}
228+
217229
/// Try to find an event by ID in this room.
218230
///
219231
/// It starts by looking into loaded events before looking inside the
@@ -1146,6 +1158,20 @@ mod private {
11461158
&self.room_linked_chunk
11471159
}
11481160

1161+
//// Find a single event in this room, starting from the most recent event.
1162+
///
1163+
/// **Warning**! It looks into the loaded events from the in-memory
1164+
/// linked chunk **only**. It doesn't look inside the storage,
1165+
/// contrary to [`Self::find_event`].
1166+
pub fn rfind_event_in_memory_by<P>(&self, mut predicate: P) -> Option<Event>
1167+
where
1168+
P: FnMut(&Event) -> bool,
1169+
{
1170+
self.room_linked_chunk
1171+
.revents()
1172+
.find_map(|(_position, event)| predicate(event).then(|| event.clone()))
1173+
}
1174+
11491175
/// Find a single event in this room.
11501176
///
11511177
/// It starts by looking into loaded events in `EventLinkedChunk` before

0 commit comments

Comments
 (0)