Skip to content

Commit 0f8a821

Browse files
committed
fixup! apply review comments
1 parent 50173d4 commit 0f8a821

File tree

2 files changed

+25
-91
lines changed

2 files changed

+25
-91
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ impl PinnedEventsLoader {
7272
}
7373

7474
let request_config = Some(RequestConfig::default().retry_limit(3));
75-
let max_concurrent_requests = self.max_concurrent_requests;
7675

7776
let mut loaded_events: Vec<SyncTimelineEvent> =
7877
stream::iter(pinned_event_ids.into_iter().map(|event_id| {
@@ -91,7 +90,7 @@ impl PinnedEventsLoader {
9190
}
9291
}
9392
}))
94-
.buffer_unordered(max_concurrent_requests)
93+
.buffer_unordered(self.max_concurrent_requests)
9594
// Get only the `Some<Vec<_>>` results
9695
.flat_map(stream::iter)
9796
// Flatten the `Vec`s into a single one containing all their items

crates/matrix-sdk-ui/tests/integration/timeline/pinned_event.rs

Lines changed: 24 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,8 @@ async fn test_new_pinned_events_are_added_on_sync() {
5050
let _ = test_helper.setup_sync_response(vec![(event_1, false)], Some(vec!["$1", "$2"])).await;
5151

5252
let room = test_helper.client.get_room(&room_id).unwrap();
53-
let timeline = Timeline::builder(&room)
54-
.with_focus(TimelineFocus::PinnedEvents {
55-
max_events_to_load: 100,
56-
max_concurrent_requests: 10,
57-
})
58-
.build()
59-
.await
60-
.unwrap();
53+
let timeline =
54+
Timeline::builder(&room).with_focus(pinned_events_focus(100)).build().await.unwrap();
6155
test_helper.server.reset().await;
6256

6357
assert!(
@@ -138,14 +132,8 @@ async fn test_new_pinned_event_ids_reload_the_timeline() {
138132
.await;
139133

140134
let room = test_helper.client.get_room(&room_id).unwrap();
141-
let timeline = Timeline::builder(&room)
142-
.with_focus(TimelineFocus::PinnedEvents {
143-
max_events_to_load: 100,
144-
max_concurrent_requests: 10,
145-
})
146-
.build()
147-
.await
148-
.unwrap();
135+
let timeline =
136+
Timeline::builder(&room).with_focus(pinned_events_focus(100)).build().await.unwrap();
149137

150138
assert!(
151139
timeline.live_back_pagination_status().await.is_none(),
@@ -213,13 +201,7 @@ async fn test_max_events_to_load_is_honored() {
213201
test_helper.setup_sync_response(vec![(pinned_event, false)], Some(vec!["$1", "$2"])).await;
214202

215203
let room = test_helper.client.get_room(&room_id).unwrap();
216-
let ret = Timeline::builder(&room)
217-
.with_focus(TimelineFocus::PinnedEvents {
218-
max_events_to_load: 1,
219-
max_concurrent_requests: 10,
220-
})
221-
.build()
222-
.await;
204+
let ret = Timeline::builder(&room).with_focus(pinned_events_focus(1)).build().await;
223205

224206
// We're only taking the last event id, `$2`, and it's not available so the
225207
// timeline fails to initialise.
@@ -255,14 +237,8 @@ async fn test_cached_events_are_kept_for_different_room_instances() {
255237

256238
let room = test_helper.client.get_room(&room_id).unwrap();
257239
let (room_cache, _drop_handles) = room.event_cache().await.unwrap();
258-
let timeline = Timeline::builder(&room)
259-
.with_focus(TimelineFocus::PinnedEvents {
260-
max_events_to_load: 2,
261-
max_concurrent_requests: 10,
262-
})
263-
.build()
264-
.await
265-
.unwrap();
240+
let timeline =
241+
Timeline::builder(&room).with_focus(pinned_events_focus(2)).build().await.unwrap();
266242

267243
assert!(
268244
timeline.live_back_pagination_status().await.is_none(),
@@ -290,14 +266,8 @@ async fn test_cached_events_are_kept_for_different_room_instances() {
290266
let room = test_helper.client.get_room(&room_id).unwrap();
291267

292268
// And a new timeline one
293-
let timeline = Timeline::builder(&room)
294-
.with_focus(TimelineFocus::PinnedEvents {
295-
max_events_to_load: 2,
296-
max_concurrent_requests: 10,
297-
})
298-
.build()
299-
.await
300-
.unwrap();
269+
let timeline =
270+
Timeline::builder(&room).with_focus(pinned_events_focus(2)).build().await.unwrap();
301271

302272
let (items, _) = timeline.subscribe().await;
303273
assert!(!items.is_empty()); // These events came from the cache
@@ -317,13 +287,7 @@ async fn test_cached_events_are_kept_for_different_room_instances() {
317287
let room = test_helper.client.get_room(&room_id).unwrap();
318288

319289
// And a new timeline one
320-
let ret = Timeline::builder(&room)
321-
.with_focus(TimelineFocus::PinnedEvents {
322-
max_events_to_load: 2,
323-
max_concurrent_requests: 10,
324-
})
325-
.build()
326-
.await;
290+
let ret = Timeline::builder(&room).with_focus(pinned_events_focus(2)).build().await;
327291

328292
// Since the events are no longer in the cache the timeline couldn't load them
329293
// and can't be initialised.
@@ -346,13 +310,7 @@ async fn test_pinned_timeline_with_pinned_event_ids_and_empty_result_fails() {
346310
let _ = test_helper.setup_sync_response(Vec::new(), Some(vec!["$1", "$2"])).await;
347311

348312
let room = test_helper.client.get_room(&room_id).unwrap();
349-
let ret = Timeline::builder(&room)
350-
.with_focus(TimelineFocus::PinnedEvents {
351-
max_events_to_load: 1,
352-
max_concurrent_requests: 10,
353-
})
354-
.build()
355-
.await;
313+
let ret = Timeline::builder(&room).with_focus(pinned_events_focus(1)).build().await;
356314

357315
// The timeline couldn't load any events so it fails to initialise
358316
assert!(ret.is_err());
@@ -373,14 +331,8 @@ async fn test_pinned_timeline_with_no_pinned_event_ids_is_just_empty() {
373331
let _ = test_helper.setup_sync_response(Vec::new(), Some(Vec::new())).await;
374332

375333
let room = test_helper.client.get_room(&room_id).unwrap();
376-
let timeline = Timeline::builder(&room)
377-
.with_focus(TimelineFocus::PinnedEvents {
378-
max_events_to_load: 1,
379-
max_concurrent_requests: 10,
380-
})
381-
.build()
382-
.await
383-
.unwrap();
334+
let timeline =
335+
Timeline::builder(&room).with_focus(pinned_events_focus(1)).build().await.unwrap();
384336

385337
// The timeline couldn't load any events, but it expected none, so it just
386338
// returns an empty list
@@ -411,14 +363,8 @@ async fn test_edited_events_are_reflected_in_sync() {
411363
let _ = test_helper.setup_sync_response(vec![(pinned_event, false)], Some(vec!["$1"])).await;
412364

413365
let room = test_helper.client.get_room(&room_id).unwrap();
414-
let timeline = Timeline::builder(&room)
415-
.with_focus(TimelineFocus::PinnedEvents {
416-
max_events_to_load: 100,
417-
max_concurrent_requests: 10,
418-
})
419-
.build()
420-
.await
421-
.unwrap();
366+
let timeline =
367+
Timeline::builder(&room).with_focus(pinned_events_focus(100)).build().await.unwrap();
422368
test_helper.server.reset().await;
423369

424370
assert!(
@@ -493,14 +439,8 @@ async fn test_redacted_events_are_reflected_in_sync() {
493439
let _ = test_helper.setup_sync_response(vec![(pinned_event, false)], Some(vec!["$1"])).await;
494440

495441
let room = test_helper.client.get_room(&room_id).unwrap();
496-
let timeline = Timeline::builder(&room)
497-
.with_focus(TimelineFocus::PinnedEvents {
498-
max_events_to_load: 100,
499-
max_concurrent_requests: 10,
500-
})
501-
.build()
502-
.await
503-
.unwrap();
442+
let timeline =
443+
Timeline::builder(&room).with_focus(pinned_events_focus(100)).build().await.unwrap();
504444
test_helper.server.reset().await;
505445

506446
assert!(
@@ -566,14 +506,8 @@ async fn test_edited_events_survive_pinned_event_ids_change() {
566506
let _ = test_helper.setup_sync_response(vec![(pinned_event, false)], Some(vec!["$1"])).await;
567507

568508
let room = test_helper.client.get_room(&room_id).unwrap();
569-
let timeline = Timeline::builder(&room)
570-
.with_focus(TimelineFocus::PinnedEvents {
571-
max_events_to_load: 100,
572-
max_concurrent_requests: 10,
573-
})
574-
.build()
575-
.await
576-
.unwrap();
509+
let timeline =
510+
Timeline::builder(&room).with_focus(pinned_events_focus(100)).build().await.unwrap();
577511
test_helper.server.reset().await;
578512

579513
assert!(
@@ -729,10 +663,7 @@ async fn test_ensure_max_concurrency_is_observed() {
729663

730664
// Start loading the pinned event timeline asynchronously.
731665
let handle = tokio::spawn({
732-
let timeline_builder = room.timeline_builder().with_focus(TimelineFocus::PinnedEvents {
733-
max_events_to_load: 100,
734-
max_concurrent_requests: 10,
735-
});
666+
let timeline_builder = room.timeline_builder().with_focus(pinned_events_focus(100));
736667
async {
737668
let _ = timeline_builder.build().await;
738669
}
@@ -833,3 +764,7 @@ impl TestHelper {
833764
self.client.sync_once(self.sync_settings.clone()).await
834765
}
835766
}
767+
768+
fn pinned_events_focus(max_events_to_load: u16) -> TimelineFocus {
769+
TimelineFocus::PinnedEvents { max_events_to_load, max_concurrent_requests: 10 }
770+
}

0 commit comments

Comments
 (0)