Skip to content

Commit 4c7575b

Browse files
committed
refactor(sdk): Rename RoomEventCache::event_with_relations to find_event_with_relations.
This patch renames the `RoomEventCache::event_with_relations` method to `find_event_with_relations` for the sake of clarity, also to match the other method names, and to match the Rust standard library namings.
1 parent 5e927f8 commit 4c7575b

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

crates/matrix-sdk-ui/src/timeline/pinned_events_loader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ impl PinnedEventsRoom for Room {
172172
) -> BoxFuture<'a, Result<(TimelineEvent, Vec<TimelineEvent>), matrix_sdk::Error>> {
173173
Box::pin(async move {
174174
if let Ok((cache, _handles)) = self.event_cache().await {
175-
if let Some(ret) = cache.event_with_relations(event_id, related_event_filters).await
175+
if let Some(ret) =
176+
cache.find_event_with_relations(event_id, related_event_filters).await
176177
{
177178
debug!("Loaded pinned event {event_id} and related events from cache");
178179
return Ok(ret);

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,18 @@ impl RoomEventCache {
230230
.map(|(_loc, event)| event)
231231
}
232232

233-
/// Try to find an event by id in this room, along with its related events.
233+
/// Try to find an event by ID in this room, along with its related events.
234234
///
235235
/// You can filter which types of related events to retrieve using
236236
/// `filter`. `None` will retrieve related events of any type.
237237
///
238238
/// The related events are sorted like this:
239-
/// - events saved out-of-band with `super::RoomEventCache::save_events`
240-
/// will be located at the beginning of the array.
241-
/// - events present in the linked chunk (be it in memory or in the
242-
/// database) will be sorted according to their ordering in the linked
243-
/// chunk.
244-
pub async fn event_with_relations(
239+
///
240+
/// - events saved out-of-band (with `RoomEventCache::save_events`) will be
241+
/// located at the beginning of the array.
242+
/// - events present in the linked chunk (be it in memory or in the storage)
243+
/// will be sorted according to their ordering in the linked chunk.
244+
pub async fn find_event_with_relations(
245245
&self,
246246
event_id: &EventId,
247247
filter: Option<Vec<RelationType>>,
@@ -1819,7 +1819,7 @@ mod tests {
18191819

18201820
let filter = Some(vec![RelationType::Replacement]);
18211821
let (event, related_events) =
1822-
room_event_cache.event_with_relations(original_id, filter).await.unwrap();
1822+
room_event_cache.find_event_with_relations(original_id, filter).await.unwrap();
18231823
// Fetched event is the right one.
18241824
let cached_event_id = event.event_id().unwrap();
18251825
assert_eq!(cached_event_id, original_id);
@@ -1833,7 +1833,7 @@ mod tests {
18331833
// Now we'll filter threads instead, there should be no related events
18341834
let filter = Some(vec![RelationType::Thread]);
18351835
let (event, related_events) =
1836-
room_event_cache.event_with_relations(original_id, filter).await.unwrap();
1836+
room_event_cache.find_event_with_relations(original_id, filter).await.unwrap();
18371837
// Fetched event is the right one.
18381838
let cached_event_id = event.event_id().unwrap();
18391839
assert_eq!(cached_event_id, original_id);
@@ -1878,7 +1878,7 @@ mod tests {
18781878
room_event_cache.save_events([associated_related_event]).await;
18791879

18801880
let (event, related_events) =
1881-
room_event_cache.event_with_relations(original_id, None).await.unwrap();
1881+
room_event_cache.find_event_with_relations(original_id, None).await.unwrap();
18821882
// Fetched event is the right one.
18831883
let cached_event_id = event.event_id().unwrap();
18841884
assert_eq!(cached_event_id, original_id);
@@ -1926,7 +1926,7 @@ mod tests {
19261926
room_event_cache.save_events([related_event]).await;
19271927

19281928
let (event, related_events) =
1929-
room_event_cache.event_with_relations(&original_event_id, None).await.unwrap();
1929+
room_event_cache.find_event_with_relations(&original_event_id, None).await.unwrap();
19301930
// Fetched event is the right one.
19311931
let cached_event_id = event.event_id().unwrap();
19321932
assert_eq!(cached_event_id, original_event_id);

crates/matrix-sdk/tests/integration/event_cache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,7 +2573,7 @@ async fn test_relations_ordering() {
25732573

25742574
// Sanity check: there are no relations for the target event yet.
25752575
let (_, relations) =
2576-
room_event_cache.event_with_relations(target_event_id, None).await.unwrap();
2576+
room_event_cache.find_event_with_relations(target_event_id, None).await.unwrap();
25772577
assert!(relations.is_empty());
25782578

25792579
let edit2 = event_id!("$edit2");
@@ -2623,7 +2623,7 @@ async fn test_relations_ordering() {
26232623

26242624
// At this point, relations are known for the target event.
26252625
let (_, relations) =
2626-
room_event_cache.event_with_relations(target_event_id, None).await.unwrap();
2626+
room_event_cache.find_event_with_relations(target_event_id, None).await.unwrap();
26272627
assert_eq!(relations.len(), 2);
26282628
// And the edit events are correctly ordered according to their position in the
26292629
// linked chunk.
@@ -2654,7 +2654,7 @@ async fn test_relations_ordering() {
26542654

26552655
// Relations are returned accordingly.
26562656
let (_, relations) =
2657-
room_event_cache.event_with_relations(target_event_id, None).await.unwrap();
2657+
room_event_cache.find_event_with_relations(target_event_id, None).await.unwrap();
26582658
assert_eq!(relations.len(), 3);
26592659
assert_eq!(relations[0].event_id().unwrap(), edit2);
26602660
assert_eq!(relations[1].event_id().unwrap(), edit3);
@@ -2675,7 +2675,7 @@ async fn test_relations_ordering() {
26752675
room.event(edit5, None).await.unwrap();
26762676

26772677
let (_, relations) =
2678-
room_event_cache.event_with_relations(target_event_id, None).await.unwrap();
2678+
room_event_cache.find_event_with_relations(target_event_id, None).await.unwrap();
26792679
assert_eq!(relations.len(), 4);
26802680
assert_eq!(relations[0].event_id().unwrap(), edit5);
26812681
assert_eq!(relations[1].event_id().unwrap(), edit2);

0 commit comments

Comments
 (0)