Struct matrix_sdk_ui::timeline::Timeline
source · pub struct Timeline { /* private fields */ }
Expand description
A high-level view into a regular¹ room’s contents.
¹ This type is meant to be used in the context of rooms without a
room_type
, that is rooms that are primarily used to exchange text
messages.
Implementations§
source§impl Timeline
impl Timeline
sourcepub async fn paginate_backwards(&self, num_events: u16) -> Result<bool, Error>
pub async fn paginate_backwards(&self, num_events: u16) -> Result<bool, Error>
Add more events to the start of the timeline.
Returns whether we hit the start of the timeline.
sourcepub async fn focused_paginate_forwards(
&self,
num_events: u16,
) -> Result<bool, Error>
pub async fn focused_paginate_forwards( &self, num_events: u16, ) -> Result<bool, Error>
Assuming the timeline is focused on an event, starts a forwards pagination.
Returns whether we hit the end of the timeline.
sourcepub async fn focused_paginate_backwards(
&self,
num_events: u16,
) -> Result<bool, Error>
pub async fn focused_paginate_backwards( &self, num_events: u16, ) -> Result<bool, Error>
Assuming the timeline is focused on an event, starts a backwards pagination.
Returns whether we hit the start of the timeline.
sourcepub async fn live_paginate_backwards(&self, batch_size: u16) -> Result<bool>
pub async fn live_paginate_backwards(&self, batch_size: u16) -> Result<bool>
Paginate backwards in live mode.
This can only be called when the timeline is in live mode, not focused on a specific event.
Returns whether we hit the start of the timeline.
sourcepub async fn live_back_pagination_status(
&self,
) -> Option<(LiveBackPaginationStatus, impl Stream<Item = LiveBackPaginationStatus>)>
pub async fn live_back_pagination_status( &self, ) -> Option<(LiveBackPaginationStatus, impl Stream<Item = LiveBackPaginationStatus>)>
Subscribe to the back-pagination status of a live timeline.
This will return None
if the timeline is in the focused mode.
Note: this may send multiple Paginating/Idle sequences during a single
call to Self::paginate_backwards()
.
source§impl Timeline
impl Timeline
sourcepub fn builder(room: &Room) -> TimelineBuilder
pub fn builder(room: &Room) -> TimelineBuilder
Create a new TimelineBuilder
for the given room.
sourcepub async fn retry_decryption<S: Into<String>>(
&self,
session_ids: impl IntoIterator<Item = S>,
)
pub async fn retry_decryption<S: Into<String>>( &self, session_ids: impl IntoIterator<Item = S>, )
Retry decryption of previously un-decryptable events given a list of session IDs whose keys have been imported.
§Examples
let path = PathBuf::from("/home/example/e2e-keys.txt");
let result =
client.encryption().import_room_keys(path, "secret-passphrase").await?;
// Given a timeline for a specific room_id
if let Some(keys_for_users) = result.keys.get(room_id) {
let session_ids = keys_for_users.values().flatten();
timeline.retry_decryption(session_ids).await;
}
sourcepub async fn item_by_event_id(
&self,
event_id: &EventId,
) -> Option<EventTimelineItem>
pub async fn item_by_event_id( &self, event_id: &EventId, ) -> Option<EventTimelineItem>
Get the current timeline item for the given event ID, if any.
Will return a remote event, or a local echo that has been sent but not yet replaced by a remote echo.
It’s preferable to store the timeline items in the model for your UI, if possible, instead of just storing IDs and coming back to the timeline object to look up items.
sourcepub async fn local_item_by_transaction_id(
&self,
target: &TransactionId,
) -> Option<EventTimelineItem>
pub async fn local_item_by_transaction_id( &self, target: &TransactionId, ) -> Option<EventTimelineItem>
Get the current local echo timeline item for the given transaction ID, if any.
This will always return a local echo, if found.
It’s preferable to store the timeline items in the model for your UI, if possible, instead of just storing IDs and coming back to the timeline object to look up items.
sourcepub async fn latest_event(&self) -> Option<EventTimelineItem>
pub async fn latest_event(&self) -> Option<EventTimelineItem>
Get the latest of the timeline’s event items.
sourcepub async fn subscribe(
&self,
) -> (Vector<Arc<TimelineItem>>, impl Stream<Item = VectorDiff<Arc<TimelineItem>>>)
pub async fn subscribe( &self, ) -> (Vector<Arc<TimelineItem>>, impl Stream<Item = VectorDiff<Arc<TimelineItem>>>)
Get the current timeline items, and a stream of changes.
You can poll this stream to receive updates. See
futures_util::StreamExt
for a high-level API on top of Stream
.
sourcepub async fn subscribe_batched(
&self,
) -> (Vector<Arc<TimelineItem>>, impl Stream<Item = Vec<VectorDiff<Arc<TimelineItem>>>>)
pub async fn subscribe_batched( &self, ) -> (Vector<Arc<TimelineItem>>, impl Stream<Item = Vec<VectorDiff<Arc<TimelineItem>>>>)
Get the current timeline items, and a batched stream of changes.
In contrast to subscribe
, this stream can yield
multiple diffs at once. The batching is done such that no arbitrary
delays are added.
sourcepub async fn send(
&self,
content: AnyMessageLikeEventContent,
) -> Result<SendHandle, RoomSendQueueError>
pub async fn send( &self, content: AnyMessageLikeEventContent, ) -> Result<SendHandle, RoomSendQueueError>
Send a message to the room, and add it to the timeline as a local echo.
For simplicity, this method doesn’t currently allow custom message types.
If the encryption feature is enabled, this method will transparently encrypt the room message if the room is encrypted.
If sending the message fails, the local echo item will change its
send_state
to EventSendState::SendingFailed
.
§Arguments
content
- The content of the message event.
sourcepub async fn send_reply(
&self,
content: RoomMessageEventContentWithoutRelation,
replied_to_info: RepliedToInfo,
forward_thread: ForwardThread,
) -> Result<(), RoomSendQueueError>
pub async fn send_reply( &self, content: RoomMessageEventContentWithoutRelation, replied_to_info: RepliedToInfo, forward_thread: ForwardThread, ) -> Result<(), RoomSendQueueError>
Send a reply to the given event.
Currently it only supports events with an event ID and JSON being
available (which can be removed by local redactions). This is subject to
change. Please check EventTimelineItem::can_be_replied_to
to decide
whether to render a reply button.
The sender will be added to the mentions of the reply if and only if the event has not been written by the sender.
§Arguments
-
content
- The content of the reply -
replied_to_info
- A wrapper that contains the event ID, sender, content and timestamp of the event to reply to -
forward_thread
- UsuallyYes
, unless you explicitly want to the reply to show up in the main timeline even though thereply_item
is part of a thread
sourcepub async fn replied_to_info_from_event_id(
&self,
event_id: &EventId,
) -> Result<RepliedToInfo, UnsupportedReplyItem>
pub async fn replied_to_info_from_event_id( &self, event_id: &EventId, ) -> Result<RepliedToInfo, UnsupportedReplyItem>
Get the information needed to reply to the event with the given ID.
sourcepub async fn edit(
&self,
item: &EventTimelineItem,
new_content: RoomMessageEventContentWithoutRelation,
) -> Result<bool, Error>
pub async fn edit( &self, item: &EventTimelineItem, new_content: RoomMessageEventContentWithoutRelation, ) -> Result<bool, Error>
Edit an event.
Only supports events for which EventTimelineItem::is_editable()
returns true
.
§Returns
- Returns
Ok(true)
if the edit was added to the send queue. - Returns
Ok(false)
if the edit targets an item that has no local nor matching remote item. - Returns an error if there was an issue sending the redaction event, or interacting with the sending queue.
pub async fn edit_poll( &self, fallback_text: impl Into<String>, poll: UnstablePollStartContentBlock, edit_item: &EventTimelineItem, ) -> Result<(), SendEventError>
sourcepub async fn toggle_reaction(
&self,
unique_id: &str,
reaction_key: &str,
) -> Result<(), Error>
pub async fn toggle_reaction( &self, unique_id: &str, reaction_key: &str, ) -> Result<(), Error>
Toggle a reaction on an event.
The unique_id
parameter is a string returned by
TimelineItem::unique_id()
.
Adds or redacts a reaction based on the state of the reaction at the time it is called.
When redacting a previous reaction, the redaction reason is not set.
Ensures that only one reaction is sent at a time to avoid race conditions and spamming the homeserver with requests.
sourcepub fn send_attachment(
&self,
path: impl Into<PathBuf>,
mime_type: Mime,
config: AttachmentConfig,
) -> SendAttachment<'_>
pub fn send_attachment( &self, path: impl Into<PathBuf>, mime_type: Mime, config: AttachmentConfig, ) -> SendAttachment<'_>
Sends an attachment to the room. It does not currently support local echoes
If the encryption feature is enabled, this method will transparently encrypt the room message if the room is encrypted.
§Arguments
-
path
- The path of the file to be sent -
mime_type
- The attachment’s mime type -
config
- An attachment configuration object containing details about the attachment
like a thumbnail, its size, duration etc.
sourcepub async fn redact(
&self,
event: &EventTimelineItem,
reason: Option<&str>,
) -> Result<bool, Error>
pub async fn redact( &self, event: &EventTimelineItem, reason: Option<&str>, ) -> Result<bool, Error>
Redact an event.
§Returns
- Returns
Ok(true)
if the redact happened. - Returns
Ok(false)
if the redact targets an item that has no local nor matching remote item. - Returns an error if there was an issue sending the redaction event, or interacting with the sending queue.
sourcepub async fn fetch_details_for_event(
&self,
event_id: &EventId,
) -> Result<(), Error>
pub async fn fetch_details_for_event( &self, event_id: &EventId, ) -> Result<(), Error>
Fetch unavailable details about the event with the given ID.
This method only works for IDs of remote EventTimelineItem
s,
to prevent losing details when a local echo is replaced by its
remote echo.
This method tries to make all the requests it can. If an error is
encountered for a given request, it is forwarded with the
TimelineDetails::Error
variant.
§Arguments
event_id
- The event ID of the event to fetch details for.
§Errors
Returns an error if the identifier doesn’t match any event with a remote echo in the timeline, or if the event is removed from the timeline before all requests are handled.
sourcepub async fn fetch_members(&self)
pub async fn fetch_members(&self)
Fetch all member events for the room this timeline is displaying.
If the full member list is not known, sender profiles are currently likely not going to be available. This will be fixed in the future.
If fetching the members fails, any affected timeline items will have
the sender_profile
set to TimelineDetails::Error
.
sourcepub async fn latest_user_read_receipt(
&self,
user_id: &UserId,
) -> Option<(OwnedEventId, Receipt)>
pub async fn latest_user_read_receipt( &self, user_id: &UserId, ) -> Option<(OwnedEventId, Receipt)>
Get the latest read receipt for the given user.
Contrary to Room::load_user_receipt()
that only keeps track of read
receipts received from the homeserver, this keeps also track of implicit
read receipts in this timeline, i.e. when a room member sends an event.
sourcepub async fn latest_user_read_receipt_timeline_event_id(
&self,
user_id: &UserId,
) -> Option<OwnedEventId>
pub async fn latest_user_read_receipt_timeline_event_id( &self, user_id: &UserId, ) -> Option<OwnedEventId>
Get the ID of the timeline event with the latest read receipt for the given user.
In contrary to Self::latest_user_read_receipt()
, this allows to know
the position of the read receipt in the timeline even if the event it
applies to is not visible in the timeline, unless the event is unknown
by this timeline.
sourcepub async fn send_single_receipt(
&self,
receipt_type: ReceiptType,
thread: ReceiptThread,
event_id: OwnedEventId,
) -> Result<bool>
pub async fn send_single_receipt( &self, receipt_type: ReceiptType, thread: ReceiptThread, event_id: OwnedEventId, ) -> Result<bool>
Send the given receipt.
This uses Room::send_single_receipt
internally, but checks
first if the receipt points to an event in this timeline that is more
recent than the current ones, to avoid unnecessary requests.
Returns a boolean indicating if it sent the request or not.
sourcepub async fn send_multiple_receipts(&self, receipts: Receipts) -> Result<()>
pub async fn send_multiple_receipts(&self, receipts: Receipts) -> Result<()>
Send the given receipts.
This uses Room::send_multiple_receipts
internally, but
checks first if the receipts point to events in this timeline that
are more recent than the current ones, to avoid unnecessary
requests.
sourcepub async fn mark_as_read(&self, receipt_type: ReceiptType) -> Result<bool>
pub async fn mark_as_read(&self, receipt_type: ReceiptType) -> Result<bool>
Mark the room as read by sending an unthreaded read receipt on the latest event, be it visible or not.
This works even if the latest event belongs to a thread, as a threaded reply also belongs to the unthreaded timeline. No threaded receipt will be sent here (see also #3123).
Returns a boolean indicating if we sent the request or not.
sourcepub async fn pin_event(&self, event_id: &EventId) -> Result<bool>
pub async fn pin_event(&self, event_id: &EventId) -> Result<bool>
Adds a new pinned event by sending an updated m.room.pinned_events
event containing the new event id.
Returns true
if we sent the request, false
if the event was already
pinned.
sourcepub async fn unpin_event(&self, event_id: &EventId) -> Result<bool>
pub async fn unpin_event(&self, event_id: &EventId) -> Result<bool>
Adds a new pinned event by sending an updated m.room.pinned_events
event without the event id we want to remove.
Returns true
if we sent the request, false
if the event wasn’t
pinned.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Timeline
impl !RefUnwindSafe for Timeline
impl Send for Timeline
impl Sync for Timeline
impl Unpin for Timeline
impl !UnwindSafe for Timeline
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
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,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§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