pub struct ThreadListService { /* private fields */ }Expand description
A paginated list of threads for a given room.
ThreadListService provides an observable, paginated list of
ThreadListItems. It exposes methods to paginate forward through the
thread list as well as subscribe to state changes.
When created, the service automatically starts a background task that
listens to room event cache updates (from /sync and other sources).
Whenever a new event belonging to a known thread arrives, the service
updates that thread’s latest_event and num_replies fields in real time,
emitting observable diffs to all subscribers.
§Example
use matrix_sdk::Room;
use matrix_sdk_ui::timeline::thread_list_service::{
ThreadListPaginationState, ThreadListService,
};
let service = ThreadListService::new(room);
assert_eq!(
service.pagination_state(),
ThreadListPaginationState::Idle { end_reached: false }
);
service.paginate().await.unwrap();
let items = service.items();Implementations§
Source§impl ThreadListService
impl ThreadListService
Sourcepub fn new(room: Room) -> Self
pub fn new(room: Room) -> Self
Creates a new ThreadListService for the given room.
This immediately spawns a background task that listens to the room’s event cache for live updates. The task self-bootstraps by performing the async event cache subscription internally.
Sourcepub fn pagination_state(&self) -> ThreadListPaginationState
pub fn pagination_state(&self) -> ThreadListPaginationState
Returns the current pagination state.
Sourcepub fn subscribe_to_pagination_state_updates(
&self,
) -> Subscriber<ThreadListPaginationState>
pub fn subscribe_to_pagination_state_updates( &self, ) -> Subscriber<ThreadListPaginationState>
Subscribes to pagination state updates.
The returned Subscriber will emit a new value every time the
pagination state changes.
Sourcepub fn items(&self) -> Vec<ThreadListItem>
pub fn items(&self) -> Vec<ThreadListItem>
Returns the current list of thread items as a snapshot.
Sourcepub fn subscribe_to_items_updates(
&self,
) -> (Vector<ThreadListItem>, VectorSubscriberBatchedStream<ThreadListItem>)
pub fn subscribe_to_items_updates( &self, ) -> (Vector<ThreadListItem>, VectorSubscriberBatchedStream<ThreadListItem>)
Subscribes to updates of the thread item list.
Returns a snapshot of the current items alongside a batched stream of
eyeball_im::VectorDiffs that describe subsequent changes.
Sourcepub async fn paginate(&self) -> Result<(), ThreadListServiceError>
pub async fn paginate(&self) -> Result<(), ThreadListServiceError>
Fetches the next page of threads, appending the results to the item list.
- If the list is already loading or the end has been reached, this
method returns immediately with
Ok(()). - On a network/SDK error the pagination state is reset to
Idle { end_reached: false }and the error is propagated.
Sourcepub async fn reset(&self)
pub async fn reset(&self)
Resets the service back to its initial state.
Clears all loaded items, discards the current pagination token, and
sets the pagination state to Idle { end_reached: false }. The next
call to Self::paginate will therefore start from the beginning of
the thread list.
Auto Trait Implementations§
impl !Freeze for ThreadListService
impl !RefUnwindSafe for ThreadListService
impl Send for ThreadListService
impl Sync for ThreadListService
impl Unpin for ThreadListService
impl UnsafeUnpin for ThreadListService
impl !UnwindSafe for ThreadListService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more