sdk: Add EventTimelineItem::origin

This commit is contained in:
Jonas Platte
2023-07-03 17:49:18 +02:00
committed by Jonas Platte
parent f4929fd064
commit f344aa7669
2 changed files with 28 additions and 3 deletions

View File

@@ -259,6 +259,20 @@ impl EventTimelineItem {
}
}
/// Get the origin of the event, i.e. where it came from.
///
/// May return `None` in some edge cases that are subject to change.
pub fn origin(&self) -> Option<EventItemOrigin> {
match &self.kind {
EventTimelineItemKind::Local(_) => Some(EventItemOrigin::Local),
EventTimelineItemKind::Remote(remote_event) => match remote_event.origin {
RemoteEventOrigin::Sync => Some(EventItemOrigin::Sync),
RemoteEventOrigin::Pagination => Some(EventItemOrigin::Pagination),
_ => None,
},
}
}
pub(super) fn set_content(&mut self, content: TimelineItemContent) {
self.content = content;
}
@@ -357,3 +371,14 @@ impl<T> TimelineDetails<T> {
matches!(self, Self::Ready(v) if v == value)
}
}
/// Where this event came.
#[derive(Clone, Copy, Debug)]
pub enum EventItemOrigin {
/// The event was created locally.
Local,
/// The event came from a sync response.
Sync,
/// The event came from pagination.
Pagination,
}

View File

@@ -70,9 +70,9 @@ pub(crate) use self::builder::TimelineBuilder;
pub use self::sliding_sync_ext::SlidingSyncRoomExt;
pub use self::{
event_item::{
AnyOtherFullStateEventContent, BundledReactions, EncryptedMessage, EventSendState,
EventTimelineItem, InReplyToDetails, MemberProfileChange, MembershipChange, Message,
OtherState, Profile, ReactionGroup, RepliedToEvent, RoomMembershipChange, Sticker,
AnyOtherFullStateEventContent, BundledReactions, EncryptedMessage, EventItemOrigin,
EventSendState, EventTimelineItem, InReplyToDetails, MemberProfileChange, MembershipChange,
Message, OtherState, Profile, ReactionGroup, RepliedToEvent, RoomMembershipChange, Sticker,
TimelineDetails, TimelineItemContent,
},
futures::SendAttachment,