From d85d6cfbcae1dd1208bd1fdc44966d90b3698705 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 29 Jan 2025 08:47:26 +0100 Subject: [PATCH] refactor(ui): Rename `TimelineStream` to `TimelineWithDropHandle`. This patch renames `TimelineStream` to `TimelineWithDropHandle`, as the former name was too vague and was not clarify what the type was doing. The new name makes it clear that it attaches a `TimelineDropHandle` to a subscriber (since it is part of the `subscriber` module!). --- crates/matrix-sdk-ui/src/timeline/mod.rs | 6 +++--- crates/matrix-sdk-ui/src/timeline/subscriber.rs | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index 50719bf72..e4c10c13a 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -52,7 +52,7 @@ use ruma::{ serde::Raw, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, RoomVersionId, UserId, }; -use subscriber::TimelineStream; +use subscriber::TimelineWithDropHandle; use thiserror::Error; use tracing::{error, instrument, trace, warn}; @@ -277,7 +277,7 @@ impl Timeline { &self, ) -> (Vector>, impl Stream>>>) { let (items, stream) = self.controller.subscribe_batched().await; - let stream = TimelineStream::new(stream, self.drop_handle.clone()); + let stream = TimelineWithDropHandle::new(stream, self.drop_handle.clone()); (items, stream) } @@ -811,7 +811,7 @@ impl Timeline { f: impl Fn(Arc) -> Option, ) -> (Vector, impl Stream>) { let (items, stream) = self.controller.subscribe_filter_map(f).await; - let stream = TimelineStream::new(stream, self.drop_handle.clone()); + let stream = TimelineWithDropHandle::new(stream, self.drop_handle.clone()); (items, stream) } } diff --git a/crates/matrix-sdk-ui/src/timeline/subscriber.rs b/crates/matrix-sdk-ui/src/timeline/subscriber.rs index 6673a4b1b..e23c90b0e 100644 --- a/crates/matrix-sdk-ui/src/timeline/subscriber.rs +++ b/crates/matrix-sdk-ui/src/timeline/subscriber.rs @@ -24,20 +24,23 @@ use pin_project_lite::pin_project; use super::TimelineDropHandle; pin_project! { - pub(super) struct TimelineStream { + /// A stream that wraps a [`TimelineDropHandle`] so that the `Timeline` + /// isn't dropped until the `Stream` is dropped. + pub(super) struct TimelineWithDropHandle { #[pin] inner: S, drop_handle: Arc, } } -impl TimelineStream { - pub fn new(inner: S, drop_handle: Arc) -> Self { +impl TimelineWithDropHandle { + /// Create a new [`WithTimelineDropHandle`]. + pub(super) fn new(inner: S, drop_handle: Arc) -> Self { Self { inner, drop_handle } } } -impl Stream for TimelineStream +impl Stream for TimelineWithDropHandle where S: Stream, {