Skip to content

Commit 2ab9b05

Browse files
committed
refactor(ui): Move TimelineStream into the new subscriber module.
This patch moves the `TimelineStream` type into the new `subscriber` module. The idea is to add more code related to subscribers in the next patches.
1 parent a8bbca1 commit 2ab9b05

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed

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

+4-28
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//!
1717
//! See [`Timeline`] for details.
1818
19-
use std::{fs, path::PathBuf, pin::Pin, sync::Arc, task::Poll};
19+
use std::{fs, path::PathBuf, sync::Arc};
2020

2121
use algorithms::rfind_event_by_item_id;
2222
use event_item::{extract_room_msg_edit_content, TimelineItemHandle};
@@ -33,7 +33,7 @@ use matrix_sdk::{
3333
Client, Result,
3434
};
3535
use mime::Mime;
36-
use pin_project_lite::pin_project;
36+
use pinned_events_loader::PinnedEventsRoom;
3737
use ruma::{
3838
api::client::receipt::create_receipt::v3::ReceiptType,
3939
events::{
@@ -52,13 +52,13 @@ use ruma::{
5252
serde::Raw,
5353
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, RoomVersionId, UserId,
5454
};
55+
use subscriber::TimelineStream;
5556
use thiserror::Error;
5657
use tracing::{error, instrument, trace, warn};
5758

5859
use self::{
5960
algorithms::rfind_event_by_id, controller::TimelineController, futures::SendAttachment,
6061
};
61-
use crate::timeline::pinned_events_loader::PinnedEventsRoom;
6262

6363
mod algorithms;
6464
mod builder;
@@ -73,6 +73,7 @@ mod item;
7373
mod pagination;
7474
mod pinned_events_loader;
7575
mod reactions;
76+
mod subscriber;
7677
#[cfg(test)]
7778
mod tests;
7879
mod to_device;
@@ -848,31 +849,6 @@ impl Drop for TimelineDropHandle {
848849
}
849850
}
850851

851-
pin_project! {
852-
struct TimelineStream<S> {
853-
#[pin]
854-
inner: S,
855-
drop_handle: Arc<TimelineDropHandle>,
856-
}
857-
}
858-
859-
impl<S> TimelineStream<S> {
860-
fn new(inner: S, drop_handle: Arc<TimelineDropHandle>) -> Self {
861-
Self { inner, drop_handle }
862-
}
863-
}
864-
865-
impl<S: Stream> Stream for TimelineStream<S> {
866-
type Item = S::Item;
867-
868-
fn poll_next(
869-
self: Pin<&mut Self>,
870-
cx: &mut std::task::Context<'_>,
871-
) -> Poll<Option<Self::Item>> {
872-
self.project().inner.poll_next(cx)
873-
}
874-
}
875-
876852
pub type TimelineEventFilterFn =
877853
dyn Fn(&AnySyncTimelineEvent, &RoomVersionId) -> bool + Send + Sync;
878854

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2022 The Matrix.org Foundation C.I.C.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::{
16+
pin::Pin,
17+
sync::Arc,
18+
task::{Context, Poll},
19+
};
20+
21+
use futures_core::Stream;
22+
use pin_project_lite::pin_project;
23+
24+
use super::TimelineDropHandle;
25+
26+
pin_project! {
27+
pub(super) struct TimelineStream<S> {
28+
#[pin]
29+
inner: S,
30+
drop_handle: Arc<TimelineDropHandle>,
31+
}
32+
}
33+
34+
impl<S> TimelineStream<S> {
35+
pub fn new(inner: S, drop_handle: Arc<TimelineDropHandle>) -> Self {
36+
Self { inner, drop_handle }
37+
}
38+
}
39+
40+
impl<S> Stream for TimelineStream<S>
41+
where
42+
S: Stream,
43+
{
44+
type Item = S::Item;
45+
46+
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
47+
self.project().inner.poll_next(cx)
48+
}
49+
}

0 commit comments

Comments
 (0)