From 770a67678ccfe988d30d2b2c88fda0cb9dab0da6 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 1 Mar 2023 14:18:35 +0100 Subject: [PATCH] Move RemoteEventTimelineItem into its own module --- .../src/room/timeline/event_item/mod.rs | 82 +---------------- .../src/room/timeline/event_item/remote.rs | 87 +++++++++++++++++++ 2 files changed, 90 insertions(+), 79 deletions(-) create mode 100644 crates/matrix-sdk/src/room/timeline/event_item/remote.rs diff --git a/crates/matrix-sdk/src/room/timeline/event_item/mod.rs b/crates/matrix-sdk/src/room/timeline/event_item/mod.rs index 773af1550..9a85cd2a6 100644 --- a/crates/matrix-sdk/src/room/timeline/event_item/mod.rs +++ b/crates/matrix-sdk/src/room/timeline/event_item/mod.rs @@ -15,14 +15,13 @@ use std::{fmt, ops::Deref, sync::Arc}; use indexmap::IndexMap; -use matrix_sdk_base::deserialized_responses::{EncryptionInfo, TimelineEvent}; +use matrix_sdk_base::deserialized_responses::TimelineEvent; use ruma::{ events::{ policy::rule::{ room::PolicyRuleRoomEventContent, server::PolicyRuleServerEventContent, user::PolicyRuleUserEventContent, }, - receipt::Receipt, room::{ aliases::RoomAliasesEventContent, avatar::RoomAvatarEventContent, @@ -57,8 +56,9 @@ use super::inner::RoomDataProvider; use crate::{Error, Result}; mod local; +mod remote; -pub use self::local::LocalEventTimelineItem; +pub use self::{local::LocalEventTimelineItem, remote::RemoteEventTimelineItem}; /// An item in the timeline that represents at least one event. /// @@ -252,88 +252,12 @@ impl From for EventTimelineItem { } } -/// An item for an event that was received from the homeserver. -#[derive(Clone)] -pub struct RemoteEventTimelineItem { - /// The event ID. - pub event_id: OwnedEventId, - /// The sender of the event. - pub sender: OwnedUserId, - /// The sender's profile of the event. - pub sender_profile: TimelineDetails, - /// The timestamp of the event. - pub timestamp: MilliSecondsSinceUnixEpoch, - /// The content of the event. - pub content: TimelineItemContent, - /// All bundled reactions about the event. - pub reactions: BundledReactions, - /// All read receipts for the event. - /// - /// The key is the ID of a room member and the value are details about the - /// read receipt. - /// - /// Note that currently this ignores threads. - pub read_receipts: IndexMap, - /// Whether the event has been sent by the the logged-in user themselves. - pub is_own: bool, - /// Encryption information. - pub encryption_info: Option, - // FIXME: Expose the raw JSON of aggregated events somehow - pub raw: Raw, -} - -impl RemoteEventTimelineItem { - /// Clone the current event item, and update its `reactions`. - pub(super) fn with_reactions(&self, reactions: BundledReactions) -> Self { - Self { reactions, ..self.clone() } - } - - /// Clone the current event item, and update its `content`. - pub(super) fn with_content(&self, content: TimelineItemContent) -> Self { - Self { content, ..self.clone() } - } - - /// Clone the current event item, change its `content` to - /// [`TimelineItemContent::RedactedMessage`], and reset its `reactions`. - pub(super) fn to_redacted(&self) -> Self { - Self { - // FIXME: Change when we support state events - content: TimelineItemContent::RedactedMessage, - reactions: BundledReactions::default(), - ..self.clone() - } - } - - /// Get the reactions of this item. - pub fn reactions(&self) -> &BundledReactions { - // FIXME: Find out the state of incomplete bundled reactions, adjust - // Ruma if necessary, return the whole BundledReactions field - &self.reactions - } -} - impl From for EventTimelineItem { fn from(value: RemoteEventTimelineItem) -> Self { Self::Remote(value) } } -#[cfg(not(tarpaulin_include))] -impl fmt::Debug for RemoteEventTimelineItem { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("RemoteEventTimelineItem") - .field("event_id", &self.event_id) - .field("sender", &self.sender) - .field("timestamp", &self.timestamp) - .field("content", &self.content) - .field("reactions", &self.reactions) - .field("is_own", &self.is_own) - .field("encryption_info", &self.encryption_info) - // skip raw, too noisy - .finish_non_exhaustive() - } -} - /// The display name and avatar URL of a room member. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Profile { diff --git a/crates/matrix-sdk/src/room/timeline/event_item/remote.rs b/crates/matrix-sdk/src/room/timeline/event_item/remote.rs new file mode 100644 index 000000000..99d8424dc --- /dev/null +++ b/crates/matrix-sdk/src/room/timeline/event_item/remote.rs @@ -0,0 +1,87 @@ +use std::fmt; + +use indexmap::IndexMap; +use matrix_sdk_base::deserialized_responses::EncryptionInfo; +use ruma::{ + events::{receipt::Receipt, AnySyncTimelineEvent}, + serde::Raw, + MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, +}; + +use super::{BundledReactions, Profile, TimelineDetails, TimelineItemContent}; + +/// An item for an event that was received from the homeserver. +#[derive(Clone)] +pub struct RemoteEventTimelineItem { + /// The event ID. + pub event_id: OwnedEventId, + /// The sender of the event. + pub sender: OwnedUserId, + /// The sender's profile of the event. + pub sender_profile: TimelineDetails, + /// The timestamp of the event. + pub timestamp: MilliSecondsSinceUnixEpoch, + /// The content of the event. + pub content: TimelineItemContent, + /// All bundled reactions about the event. + pub reactions: BundledReactions, + /// All read receipts for the event. + /// + /// The key is the ID of a room member and the value are details about the + /// read receipt. + /// + /// Note that currently this ignores threads. + pub read_receipts: IndexMap, + /// Whether the event has been sent by the the logged-in user themselves. + pub is_own: bool, + /// Encryption information. + pub encryption_info: Option, + // FIXME: Expose the raw JSON of aggregated events somehow + pub raw: Raw, +} + +impl RemoteEventTimelineItem { + /// Clone the current event item, and update its `reactions`. + pub(in crate::room::timeline) fn with_reactions(&self, reactions: BundledReactions) -> Self { + Self { reactions, ..self.clone() } + } + + /// Clone the current event item, and update its `content`. + pub(in crate::room::timeline) fn with_content(&self, content: TimelineItemContent) -> Self { + Self { content, ..self.clone() } + } + + /// Clone the current event item, change its `content` to + /// [`TimelineItemContent::RedactedMessage`], and reset its `reactions`. + pub(in crate::room::timeline) fn to_redacted(&self) -> Self { + Self { + // FIXME: Change when we support state events + content: TimelineItemContent::RedactedMessage, + reactions: BundledReactions::default(), + ..self.clone() + } + } + + /// Get the reactions of this item. + pub fn reactions(&self) -> &BundledReactions { + // FIXME: Find out the state of incomplete bundled reactions, adjust + // Ruma if necessary, return the whole BundledReactions field + &self.reactions + } +} + +#[cfg(not(tarpaulin_include))] +impl fmt::Debug for RemoteEventTimelineItem { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("RemoteEventTimelineItem") + .field("event_id", &self.event_id) + .field("sender", &self.sender) + .field("timestamp", &self.timestamp) + .field("content", &self.content) + .field("reactions", &self.reactions) + .field("is_own", &self.is_own) + .field("encryption_info", &self.encryption_info) + // skip raw, too noisy + .finish_non_exhaustive() + } +}