events: Add type accessors to Any{Sync}TimelineEvent

This commit is contained in:
Kévin Commaille 2022-12-26 14:13:48 +01:00 committed by Kévin Commaille
parent ca78825e94
commit 2934325486

View File

@ -180,6 +180,14 @@ impl AnyTimelineEvent {
/// Returns this event's `relations` from inside `unsigned`. /// Returns this event's `relations` from inside `unsigned`.
pub fn relations(&self) -> &BundledRelations; pub fn relations(&self) -> &BundledRelations;
} }
/// Returns this event's `type`.
pub fn event_type(&self) -> TimelineEventType {
match self {
Self::MessageLike(e) => e.event_type().into(),
Self::State(e) => e.event_type().into(),
}
}
} }
/// Any sync room event. /// Any sync room event.
@ -213,6 +221,14 @@ impl AnySyncTimelineEvent {
pub fn relations(&self) -> &BundledRelations; pub fn relations(&self) -> &BundledRelations;
} }
/// Returns this event's `type`.
pub fn event_type(&self) -> TimelineEventType {
match self {
Self::MessageLike(e) => e.event_type().into(),
Self::State(e) => e.event_type().into(),
}
}
/// Converts `self` to an `AnyTimelineEvent` by adding the given a room ID. /// Converts `self` to an `AnyTimelineEvent` by adding the given a room ID.
pub fn into_full_event(self, room_id: OwnedRoomId) -> AnyTimelineEvent { pub fn into_full_event(self, room_id: OwnedRoomId) -> AnyTimelineEvent {
match self { match self {