diff --git a/bindings/matrix-sdk-ffi/src/timeline/content.rs b/bindings/matrix-sdk-ffi/src/timeline/content.rs index a6d321d95..43714a6f4 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/content.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/content.rs @@ -16,8 +16,7 @@ use std::{collections::HashMap, sync::Arc}; use matrix_sdk::{crypto::types::events::UtdCause, room::power_levels::power_level_user_changes}; use matrix_sdk_ui::timeline::{ - AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, PollResult, - RoomPinnedEventsChange, TimelineDetails, + MsgLikeContent, MsgLikeKind, PollResult, RoomPinnedEventsChange, TimelineDetails, }; use ruma::events::{room::MediaSource as RumaMediaSource, EventContent, FullStateEventContent}; @@ -32,8 +31,8 @@ impl From for TimelineItemContent use matrix_sdk_ui::timeline::TimelineItemContent as Content; match value { - Content::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(message), + Content::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(message), thread_root, in_reply_to, .. @@ -60,10 +59,7 @@ impl From for TimelineItemContent Content::RedactedMessage => TimelineItemContent::RedactedMessage, - Content::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Sticker(sticker), - .. - }) => { + Content::MsgLike(MsgLikeContent { kind: MsgLikeKind::Sticker(sticker), .. }) => { let content = sticker.content(); let media_source = RumaMediaSource::from(content.source.clone()); @@ -88,10 +84,9 @@ impl From for TimelineItemContent } } - Content::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Poll(poll_state), - .. - }) => TimelineItemContent::from(poll_state.results()), + Content::MsgLike(MsgLikeContent { kind: MsgLikeKind::Poll(poll_state), .. }) => { + TimelineItemContent::from(poll_state.results()) + } Content::CallInvite => TimelineItemContent::CallInvite, diff --git a/crates/matrix-sdk-ui/src/timeline/controller/aggregations.rs b/crates/matrix-sdk-ui/src/timeline/controller/aggregations.rs index 2d491e126..808abf8fd 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/aggregations.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/aggregations.rs @@ -44,8 +44,8 @@ use tracing::{trace, warn}; use super::{rfind_event_by_item_id, ObservableItemsTransaction}; use crate::timeline::{ - AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, PollState, ReactionInfo, - ReactionStatus, TimelineEventItemId, TimelineItem, TimelineItemContent, + MsgLikeContent, MsgLikeKind, PollState, ReactionInfo, ReactionStatus, TimelineEventItemId, + TimelineItem, TimelineItemContent, }; /// Which kind of aggregation (related event) is this? @@ -106,8 +106,8 @@ fn poll_state_from_item( content: &mut TimelineItemContent, ) -> Result<&mut PollState, AggregationError> { match content { - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Poll(poll_state), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Poll(poll_state), .. }) => Ok(poll_state), _ => Err(AggregationError::InvalidType { diff --git a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs index f17c7d003..9ea635dca 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs @@ -79,7 +79,7 @@ use crate::{ date_dividers::DateDividerAdjuster, event_item::EventTimelineItemKind, pinned_events_loader::{PinnedEventsLoader, PinnedEventsLoaderError}, - AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, TimelineEventFilterFn, + MsgLikeContent, MsgLikeKind, TimelineEventFilterFn, }, unable_to_decrypt_hook::UtdHookManager, }; @@ -1343,11 +1343,11 @@ impl TimelineController { .ok_or(Error::EventNotInTimeline(TimelineEventItemId::EventId(event_id.to_owned())))? .clone(); - let TimelineItemContent::Aggregated(aggregated) = item.content().clone() else { + let TimelineItemContent::MsgLike(msglike) = item.content().clone() else { debug!("Event is not a message"); return Ok(()); }; - let Some(in_reply_to) = aggregated.in_reply_to.clone() else { + let Some(in_reply_to) = msglike.in_reply_to.clone() else { debug!("Event is not a reply"); return Ok(()); }; @@ -1367,7 +1367,7 @@ impl TimelineController { index, &item, internal_id, - &aggregated, + &msglike, &in_reply_to.event_id, self.room(), ) @@ -1381,8 +1381,8 @@ impl TimelineController { // Check the state of the event again, it might have been redacted while // the request was in-flight. - let TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(message), + let TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(message), reactions, thread_root, in_reply_to, @@ -1401,8 +1401,8 @@ impl TimelineController { trace!("Updating in-reply-to details"); let internal_id = item.internal_id.to_owned(); let mut item = item.clone(); - item.set_content(TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(message), + item.set_content(TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(message), reactions, thread_root, in_reply_to: Some(InReplyToDetails { event_id: in_reply_to.event_id, event }), @@ -1519,7 +1519,7 @@ async fn fetch_replied_to_event( index: usize, item: &EventTimelineItem, internal_id: TimelineUniqueId, - aggregated: &AggregatedTimelineItemContent, + msglike: &MsgLikeContent, in_reply_to: &EventId, room: &Room, ) -> Result>, Error> { @@ -1535,9 +1535,8 @@ async fn fetch_replied_to_event( let in_reply_to_details = InReplyToDetails { event_id: in_reply_to.to_owned(), event: TimelineDetails::Pending }; - let event_item = item.with_content(TimelineItemContent::Aggregated( - aggregated.with_in_reply_to(in_reply_to_details), - )); + let event_item = item + .with_content(TimelineItemContent::MsgLike(msglike.with_in_reply_to(in_reply_to_details))); let new_timeline_item = TimelineItem::new(event_item, internal_id); state.items.replace(index, new_timeline_item); diff --git a/crates/matrix-sdk-ui/src/timeline/controller/observable_items.rs b/crates/matrix-sdk-ui/src/timeline/controller/observable_items.rs index c55a90644..68bb353ae 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/observable_items.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/observable_items.rs @@ -389,8 +389,8 @@ mod observable_items_tests { use crate::timeline::{ controller::{EventTimelineItemKind, RemoteEventOrigin}, event_item::RemoteEventTimelineItem, - AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, EventTimelineItem, - Message, TimelineDetails, TimelineItemContent, TimelineUniqueId, + EventTimelineItem, Message, MsgLikeContent, MsgLikeKind, TimelineDetails, + TimelineItemContent, TimelineUniqueId, }; fn item(event_id: &str) -> Arc { @@ -399,8 +399,8 @@ mod observable_items_tests { owned_user_id!("@ivan:mnt.io"), TimelineDetails::Unavailable, MilliSecondsSinceUnixEpoch(0u32.into()), - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(Message { + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(Message { msgtype: MessageType::Text(TextMessageEventContent::plain("hello")), edited: false, mentions: None, diff --git a/crates/matrix-sdk-ui/src/timeline/event_handler.rs b/crates/matrix-sdk-ui/src/timeline/event_handler.rs index 993d701dc..8f1040bfb 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_handler.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_handler.rs @@ -65,9 +65,8 @@ use super::{ TimelineEventItemId, }, traits::RoomDataProvider, - AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, EventTimelineItem, - InReplyToDetails, OtherState, ReactionStatus, RepliedToEvent, Sticker, TimelineDetails, - TimelineItem, TimelineItemContent, + EventTimelineItem, InReplyToDetails, MsgLikeContent, MsgLikeKind, OtherState, ReactionStatus, + RepliedToEvent, Sticker, TimelineDetails, TimelineItem, TimelineItemContent, }; use crate::events::SyncTimelineEventWithoutContent; @@ -414,10 +413,8 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { AnyMessageLikeEventContent::Sticker(content) => { if should_add { self.add_item( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Sticker(Sticker { - content, - }), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Sticker(Sticker { content }), reactions: Default::default(), thread_root: None, in_reply_to: None, @@ -737,8 +734,8 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { return None; } - let TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(msg), + let TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(msg), reactions, thread_root, in_reply_to, @@ -755,8 +752,8 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { new_msg.apply_edit(new_content); let mut new_item = item.with_content_and_latest_edit( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(new_msg), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(new_msg), reactions: reactions.clone(), thread_root: thread_root.clone(), in_reply_to: in_reply_to.clone(), @@ -850,8 +847,8 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { return None; } - let TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Poll(poll_state), + let TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Poll(poll_state), reactions, thread_root, in_reply_to, @@ -862,14 +859,12 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { }; let new_content = match poll_state.edit(replacement.new_content) { - Some(edited_poll_state) => { - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Poll(edited_poll_state), - reactions: reactions.clone(), - thread_root: thread_root.clone(), - in_reply_to: in_reply_to.clone(), - }) - } + Some(edited_poll_state) => TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Poll(edited_poll_state), + reactions: reactions.clone(), + thread_root: thread_root.clone(), + in_reply_to: in_reply_to.clone(), + }), None => { info!("Not applying edit to a poll that's already ended"); return None; @@ -916,8 +911,8 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { let edit_json = edit_json.flatten(); self.add_item( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Poll(poll_state), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Poll(poll_state), reactions: Default::default(), thread_root: None, in_reply_to: None, @@ -1386,9 +1381,9 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { }; let Some(event_item) = item.as_event() else { continue }; - let Some(aggregated) = event_item.content.as_aggregated() else { continue }; + let Some(msglike) = event_item.content.as_msglike() else { continue }; let Some(message) = event_item.content.as_message() else { continue }; - let Some(in_reply_to) = aggregated.in_reply_to.as_ref() else { continue }; + let Some(in_reply_to) = msglike.in_reply_to.as_ref() else { continue }; trace!(reply_event_id = ?event_item.identifier(), "Updating response to updated event"); let in_reply_to = Some(InReplyToDetails { @@ -1398,13 +1393,12 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { ))), }); - let new_reply_content = - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(message.clone()), - reactions: aggregated.reactions.clone(), - thread_root: aggregated.thread_root.clone(), - in_reply_to, - }); + let new_reply_content = TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(message.clone()), + reactions: msglike.reactions.clone(), + thread_root: msglike.thread_root.clone(), + in_reply_to, + }); let new_reply_item = item.with_kind(event_item.with_content(new_reply_content)); items.replace(timeline_item_index, new_reply_item); } @@ -1419,15 +1413,15 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { /// `old_item` *should* always be a local timeline item usually, but it /// can be a remote timeline item. fn transfer_details(new_item: &mut EventTimelineItem, old_item: &EventTimelineItem) { - let TimelineItemContent::Aggregated(new_aggregated) = &mut new_item.content else { + let TimelineItemContent::MsgLike(new_msglike) = &mut new_item.content else { return; }; - let TimelineItemContent::Aggregated(old_aggregated) = &old_item.content else { + let TimelineItemContent::MsgLike(old_msglike) = &old_item.content else { return; }; - let Some(in_reply_to) = &mut new_aggregated.in_reply_to else { return }; - let Some(old_in_reply_to) = &old_aggregated.in_reply_to else { return }; + let Some(in_reply_to) = &mut new_msglike.in_reply_to else { return }; + let Some(old_in_reply_to) = &old_msglike.in_reply_to else { return }; if matches!(&in_reply_to.event, TimelineDetails::Unavailable) { in_reply_to.event = old_in_reply_to.event.clone(); diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs index 61c1c4836..ad49ba97e 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs @@ -61,8 +61,8 @@ use ruma::{ }; use tracing::warn; -mod aggregated; mod message; +mod msg_like; pub(crate) mod pinned_events; mod polls; mod reply; @@ -73,8 +73,8 @@ pub(in crate::timeline) use self::message::{ extract_bundled_edit_event_json, extract_poll_edit_content, extract_room_msg_edit_content, }; pub use self::{ - aggregated::{AggregatedTimelineItemContent, AggregatedTimelineItemContentKind}, message::Message, + msg_like::{MsgLikeContent, MsgLikeKind}, polls::{PollResult, PollState}, reply::{InReplyToDetails, RepliedToEvent}, }; @@ -83,7 +83,7 @@ use super::ReactionsByKeyBySender; /// The content of an [`EventTimelineItem`][super::EventTimelineItem]. #[derive(Clone, Debug)] pub enum TimelineItemContent { - Aggregated(AggregatedTimelineItemContent), + MsgLike(MsgLikeContent), /// A redacted message. RedactedMessage, @@ -205,8 +205,8 @@ impl TimelineItemContent { let thread_root = None; let in_reply_to = None; - let aggregated = AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(Message::from_event( + let msglike = MsgLikeContent { + kind: MsgLikeKind::Message(Message::from_event( event_content, edit, RemoveReplyFallback::Yes, @@ -216,7 +216,7 @@ impl TimelineItemContent { in_reply_to, }; - TimelineItemContent::Aggregated(aggregated) + TimelineItemContent::MsgLike(msglike) } SyncRoomMessageEvent::Redacted(_) => TimelineItemContent::RedactedMessage, @@ -254,16 +254,14 @@ impl TimelineItemContent { let thread_root = None; let in_reply_to = None; - let aggregated = AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Sticker(Sticker { - content: event_content, - }), + let msglike = MsgLikeContent { + kind: MsgLikeKind::Sticker(Sticker { content: event_content }), reactions, thread_root, in_reply_to, }; - TimelineItemContent::Aggregated(aggregated) + TimelineItemContent::MsgLike(msglike) } SyncStickerEvent::Redacted(_) => TimelineItemContent::RedactedMessage, } @@ -295,8 +293,8 @@ impl TimelineItemContent { let thread_root = None; let in_reply_to = None; - let aggregated = AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Poll(PollState::new( + let msglike = MsgLikeContent { + kind: MsgLikeKind::Poll(PollState::new( NewUnstablePollStartEventContent::new(event.content.poll_start().clone()), edit, )), @@ -305,7 +303,7 @@ impl TimelineItemContent { in_reply_to, }; - TimelineItemContent::Aggregated(aggregated) + TimelineItemContent::MsgLike(msglike) } fn from_suitable_latest_call_invite_content( @@ -326,24 +324,24 @@ impl TimelineItemContent { } } - pub fn as_aggregated(&self) -> Option<&AggregatedTimelineItemContent> { - as_variant!(self, TimelineItemContent::Aggregated) + pub fn as_msglike(&self) -> Option<&MsgLikeContent> { + as_variant!(self, TimelineItemContent::MsgLike) } - /// If `self` is of the [`Aggregated`][Self::Aggregated] variant, return the + /// If `self` is of the [`MsgLike`][Self::MsgLike] variant, return the /// inner [`Message`]. pub fn as_message(&self) -> Option<&Message> { - as_variant!(self, Self::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(message), + as_variant!(self, Self::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(message), .. }) => message) } - /// If `self` is of the [`Aggregated`][Self::Aggregated] variant, return the + /// If `self` is of the [`MsgLike`][Self::MsgLike] variant, return the /// inner [`PollState`]. pub fn as_poll(&self) -> Option<&PollState> { - as_variant!(self, Self::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Poll(poll_state), + as_variant!(self, Self::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Poll(poll_state), .. }) => poll_state) } @@ -351,8 +349,8 @@ impl TimelineItemContent { pub fn as_sticker(&self) -> Option<&Sticker> { as_variant!( self, - Self::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Sticker(sticker), + Self::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Sticker(sticker), .. }) => sticker ) @@ -371,39 +369,21 @@ impl TimelineItemContent { } /// Check whether this item's content is a - /// [`Message`][AggregatedTimelineItemContentKind::Message]. + /// [`Message`][MsgLikeKind::Message]. pub fn is_message(&self) -> bool { - matches!( - self, - Self::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), - .. - }) - ) + matches!(self, Self::MsgLike(MsgLikeContent { kind: MsgLikeKind::Message(_), .. })) } /// Check whether this item's content is a - /// [`Poll`][AggregatedTimelineItemContentKind::Poll]. + /// [`Poll`][MsgLikeKind::Poll]. pub fn is_poll(&self) -> bool { - matches!( - self, - Self::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Poll(_), - .. - }) - ) + matches!(self, Self::MsgLike(MsgLikeContent { kind: MsgLikeKind::Poll(_), .. })) } /// Check whether this item's content is a - /// [`Sticker`][AggregatedTimelineItemContentKind::Sticker]. + /// [`Sticker`][MsgLikeKind::Sticker]. pub fn is_sticker(&self) -> bool { - matches!( - self, - Self::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Sticker(_), - .. - }) - ) + matches!(self, Self::MsgLike(MsgLikeContent { kind: MsgLikeKind::Sticker(_), .. })) } // These constructors could also be `From` implementations, but that would @@ -418,12 +398,8 @@ impl TimelineItemContent { let remove_reply_fallback = if in_reply_to.is_some() { RemoveReplyFallback::Yes } else { RemoveReplyFallback::No }; - Self::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(Message::from_event( - c, - edit, - remove_reply_fallback, - )), + Self::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(Message::from_event(c, edit, remove_reply_fallback)), reactions, thread_root, in_reply_to, @@ -433,7 +409,7 @@ impl TimelineItemContent { #[cfg(not(tarpaulin_include))] // debug-logging functionality pub(crate) fn debug_string(&self) -> &'static str { match self { - TimelineItemContent::Aggregated(aggregated) => aggregated.debug_string(), + TimelineItemContent::MsgLike(msglike) => msglike.debug_string(), TimelineItemContent::RedactedMessage => "a redacted messages", TimelineItemContent::UnableToDecrypt(_) => "an encrypted message we couldn't decrypt", TimelineItemContent::MembershipChange(_) => "a membership change", @@ -517,7 +493,7 @@ impl TimelineItemContent { pub(in crate::timeline) fn redact(&self, room_version: &RoomVersionId) -> Self { match self { - Self::Aggregated(_) + Self::MsgLike(_) | Self::RedactedMessage | Self::CallInvite | Self::CallNotify @@ -531,19 +507,19 @@ impl TimelineItemContent { /// Event ID of the thread root, if this is a threaded message. pub fn thread_root(&self) -> Option { - as_variant!(self, Self::Aggregated)?.thread_root.clone() + as_variant!(self, Self::MsgLike)?.thread_root.clone() } /// Get the event this message is replying to, if any. pub fn in_reply_to(&self) -> Option { - as_variant!(self, Self::Aggregated)?.in_reply_to.clone() + as_variant!(self, Self::MsgLike)?.in_reply_to.clone() } /// Return the reactions, grouped by key and then by sender, for a given /// content. pub fn reactions(&self) -> ReactionsByKeyBySender { match self { - TimelineItemContent::Aggregated(aggregated) => aggregated.reactions.clone(), + TimelineItemContent::MsgLike(msglike) => msglike.reactions.clone(), TimelineItemContent::UnableToDecrypt(..) | TimelineItemContent::RedactedMessage => { // No reactions for redacted messages or UTDs. Default::default() @@ -567,7 +543,7 @@ impl TimelineItemContent { /// See also [`Self::reactions()`] to explain the optional return type. pub(crate) fn reactions_mut(&mut self) -> Option<&mut ReactionsByKeyBySender> { match self { - TimelineItemContent::Aggregated(aggregated) => Some(&mut aggregated.reactions), + TimelineItemContent::MsgLike(msglike) => Some(&mut msglike.reactions), TimelineItemContent::UnableToDecrypt(..) | TimelineItemContent::RedactedMessage => { // No reactions for redacted messages or UTDs. diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content/aggregated.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content/msg_like.rs similarity index 82% rename from crates/matrix-sdk-ui/src/timeline/event_item/content/aggregated.rs rename to crates/matrix-sdk-ui/src/timeline/event_item/content/msg_like.rs index b2d933f44..4d40ee1a2 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content/aggregated.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content/msg_like.rs @@ -18,7 +18,7 @@ use super::{InReplyToDetails, Message, PollState, Sticker}; use crate::timeline::ReactionsByKeyBySender; #[derive(Clone, Debug)] -pub enum AggregatedTimelineItemContentKind { +pub enum MsgLikeKind { /// An `m.room.message` event or extensible event, including edits. Message(Message), @@ -33,8 +33,8 @@ pub enum AggregatedTimelineItemContentKind { /// different room message types with their respective reactions and thread /// information. #[derive(Clone, Debug)] -pub struct AggregatedTimelineItemContent { - pub kind: AggregatedTimelineItemContentKind, +pub struct MsgLikeContent { + pub kind: MsgLikeKind, pub reactions: ReactionsByKeyBySender, /// Event ID of the thread root, if this is a threaded message. pub thread_root: Option, @@ -42,13 +42,13 @@ pub struct AggregatedTimelineItemContent { pub in_reply_to: Option, } -impl AggregatedTimelineItemContent { +impl MsgLikeContent { #[cfg(not(tarpaulin_include))] // debug-logging functionality pub(crate) fn debug_string(&self) -> &'static str { match self.kind { - AggregatedTimelineItemContentKind::Message(_) => "a message", - AggregatedTimelineItemContentKind::Sticker(_) => "a sticker", - AggregatedTimelineItemContentKind::Poll(_) => "a poll", + MsgLikeKind::Message(_) => "a message", + MsgLikeKind::Sticker(_) => "a sticker", + MsgLikeKind::Poll(_) => "a poll", } } diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs index ece675b0c..57f8db99c 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs @@ -33,7 +33,7 @@ use tracing::{debug, instrument, warn}; use super::TimelineItemContent; use crate::timeline::{ event_item::{ - content::{AggregatedTimelineItemContent, AggregatedTimelineItemContentKind}, + content::{MsgLikeContent, MsgLikeKind}, extract_room_msg_edit_content, EventTimelineItem, Profile, TimelineDetails, }, traits::RoomDataProvider, @@ -141,8 +141,8 @@ impl RepliedToEvent { let reactions = ReactionsByKeyBySender::default(); let thread_root = None; - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(Message::from_event( + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(Message::from_event( c, extract_room_msg_edit_content(event.relations()), RemoveReplyFallback::Yes, @@ -159,8 +159,8 @@ impl RepliedToEvent { let reactions = ReactionsByKeyBySender::default(); let thread_root = None; - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Sticker(Sticker { content }), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Sticker(Sticker { content }), reactions, thread_root, in_reply_to: None, @@ -192,8 +192,8 @@ impl RepliedToEvent { // TODO: could we provide the bundled edit here? let poll_state = PollState::new(content, None); - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Poll(poll_state), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Poll(poll_state), reactions, thread_root, in_reply_to: None, diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs b/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs index 443061026..026b453d3 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs @@ -51,10 +51,9 @@ pub(super) use self::{ }; pub use self::{ content::{ - AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, AnyOtherFullStateEventContent, EncryptedMessage, InReplyToDetails, MemberProfileChange, - MembershipChange, Message, OtherState, PollResult, PollState, RepliedToEvent, - RoomMembershipChange, RoomPinnedEventsChange, Sticker, TimelineItemContent, + MembershipChange, Message, MsgLikeContent, MsgLikeKind, OtherState, PollResult, PollState, + RepliedToEvent, RoomMembershipChange, RoomPinnedEventsChange, Sticker, TimelineItemContent, }, local::EventSendState, }; @@ -356,8 +355,8 @@ impl EventTimelineItem { } match self.content() { - TimelineItemContent::Aggregated(aggregated) => match &aggregated.kind { - AggregatedTimelineItemContentKind::Message(message) => { + TimelineItemContent::MsgLike(msglike) => match &msglike.kind { + MsgLikeKind::Message(message) => { matches!( message.msgtype(), MessageType::Text(_) @@ -368,10 +367,10 @@ impl EventTimelineItem { | MessageType::Video(_) ) } - AggregatedTimelineItemContentKind::Poll(poll) => { + MsgLikeKind::Poll(poll) => { poll.response_data.is_empty() && poll.end_event_timestamp.is_none() } - // Other aggregated timeline items can't be edited at the moment. + // Other MsgLike timeline items can't be edited at the moment. _ => false, }, _ => { @@ -587,8 +586,8 @@ impl EventTimelineItem { /// See `test_emoji_detection` for more examples. pub fn contains_only_emojis(&self) -> bool { let body = match self.content() { - TimelineItemContent::Aggregated(aggregated) => match &aggregated.kind { - AggregatedTimelineItemContentKind::Message(message) => match &message.msgtype { + TimelineItemContent::MsgLike(msglike) => match &msglike.kind { + MsgLikeKind::Message(message) => match &message.msgtype { MessageType::Text(text) => Some(text.body.as_str()), MessageType::Audio(audio) => audio.caption(), MessageType::File(file) => file.caption(), @@ -596,8 +595,7 @@ impl EventTimelineItem { MessageType::Video(video) => video.caption(), _ => None, }, - AggregatedTimelineItemContentKind::Sticker(_) - | AggregatedTimelineItemContentKind::Poll(_) => None, + MsgLikeKind::Sticker(_) | MsgLikeKind::Poll(_) => None, }, TimelineItemContent::RedactedMessage | TimelineItemContent::UnableToDecrypt(_) diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index 4e2821ce0..a2c0b1077 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -79,12 +79,11 @@ pub use self::{ controller::default_event_filter, error::*, event_item::{ - AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, AnyOtherFullStateEventContent, EncryptedMessage, EventItemOrigin, EventSendState, EventTimelineItem, InReplyToDetails, MemberProfileChange, MembershipChange, Message, - OtherState, PollResult, PollState, Profile, ReactionInfo, ReactionStatus, - ReactionsByKeyBySender, RepliedToEvent, RoomMembershipChange, RoomPinnedEventsChange, - Sticker, TimelineDetails, TimelineEventItemId, TimelineItemContent, + MsgLikeContent, MsgLikeKind, OtherState, PollResult, PollState, Profile, ReactionInfo, + ReactionStatus, ReactionsByKeyBySender, RepliedToEvent, RoomMembershipChange, + RoomPinnedEventsChange, Sticker, TimelineDetails, TimelineEventItemId, TimelineItemContent, }, event_type_filter::TimelineEventTypeFilter, item::{TimelineItem, TimelineItemKind, TimelineUniqueId}, diff --git a/crates/matrix-sdk-ui/src/timeline/tests/basic.rs b/crates/matrix-sdk-ui/src/timeline/tests/basic.rs index dd83545a1..2b4078f84 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/basic.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/basic.rs @@ -40,8 +40,8 @@ use crate::timeline::{ controller::TimelineSettings, event_item::{AnyOtherFullStateEventContent, RemoteEventOrigin}, tests::{ReadReceiptMap, TestRoomDataProvider, TestTimelineBuilder}, - AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, MembershipChange, - TimelineDetails, TimelineItemContent, TimelineItemKind, VirtualTimelineItem, + MembershipChange, MsgLikeContent, MsgLikeKind, TimelineDetails, TimelineItemContent, + TimelineItemKind, VirtualTimelineItem, }; #[async_test] @@ -401,8 +401,8 @@ async fn test_reply() { let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(message), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(message), in_reply_to, .. }) = item.as_event().unwrap().content() @@ -443,8 +443,8 @@ async fn test_thread() { let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(message), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(message), in_reply_to, .. }) = item.as_event().unwrap().content() diff --git a/crates/matrix-sdk-ui/src/timeline/tests/encryption.rs b/crates/matrix-sdk-ui/src/timeline/tests/encryption.rs index 2136db9ea..60619cae8 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/encryption.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/encryption.rs @@ -839,11 +839,11 @@ async fn test_retry_decryption_updates_response() { // We receive the text response. { let event = assert_next_matches!(stream, VectorDiff::PushBack { value } => value); - let aggregated = event.content().as_aggregated().unwrap(); + let msglike = event.content().as_msglike().unwrap(); let msg = event.content().as_message().unwrap(); assert_eq!(msg.body(), "well said!"); - let reply_details = aggregated.in_reply_to.clone().unwrap(); + let reply_details = msglike.in_reply_to.clone().unwrap(); assert_eq!(reply_details.event_id, original_event_id); let replied_to = as_variant!(&reply_details.event, TimelineDetails::Ready).unwrap(); @@ -874,11 +874,11 @@ async fn test_retry_decryption_updates_response() { VectorDiff::Set { index: 1, value } => value ); - let aggregated = event.content().as_aggregated().unwrap(); + let msglike = event.content().as_msglike().unwrap(); let msg = event.content().as_message().unwrap(); assert_eq!(msg.body(), "well said!"); - let reply_details = aggregated.in_reply_to.clone().unwrap(); + let reply_details = msglike.in_reply_to.clone().unwrap(); assert_eq!(reply_details.event_id, original_event_id); let replied_to = as_variant!(&reply_details.event, TimelineDetails::Ready).unwrap(); diff --git a/crates/matrix-sdk-ui/src/timeline/tests/event_filter.rs b/crates/matrix-sdk-ui/src/timeline/tests/event_filter.rs index a4d3e4aba..0444f926d 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/event_filter.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/event_filter.rs @@ -30,9 +30,9 @@ use stream_assert::assert_next_matches; use super::TestTimeline; use crate::timeline::{ - controller::TimelineSettings, tests::TestTimelineBuilder, AggregatedTimelineItemContent, - AggregatedTimelineItemContentKind, AnyOtherFullStateEventContent, TimelineEventTypeFilter, - TimelineItem, TimelineItemContent, TimelineItemKind, + controller::TimelineSettings, tests::TestTimelineBuilder, AnyOtherFullStateEventContent, + MsgLikeContent, MsgLikeKind, TimelineEventTypeFilter, TimelineItem, TimelineItemContent, + TimelineItemKind, }; #[async_test] @@ -247,8 +247,8 @@ impl TestTimeline { fn is_text_message_item(item: &&Arc) -> bool { match item.kind() { TimelineItemKind::Event(event) => match &event.content { - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(message), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(message), .. }) => { matches!(message.msgtype, MessageType::Text(_)) diff --git a/crates/matrix-sdk-ui/src/timeline/tests/redaction.rs b/crates/matrix-sdk-ui/src/timeline/tests/redaction.rs index c12fcabe7..f6ba47bfa 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/redaction.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/redaction.rs @@ -74,8 +74,8 @@ async fn test_redact_replied_to_event() { .await; let second_item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value); - let aggregated = second_item.content().as_aggregated().unwrap(); - let in_reply_to = aggregated.in_reply_to.clone().unwrap(); + let msglike = second_item.content().as_msglike().unwrap(); + let in_reply_to = msglike.in_reply_to.clone().unwrap(); assert_let!(TimelineDetails::Ready(replied_to_event) = &in_reply_to.event); assert!(replied_to_event.content().is_message()); @@ -83,8 +83,8 @@ async fn test_redact_replied_to_event() { let second_item_again = assert_next_matches!(stream, VectorDiff::Set { index: 1, value } => value); - let aggregated = second_item_again.content().as_aggregated().unwrap(); - let in_reply_to = aggregated.in_reply_to.clone().unwrap(); + let msglike = second_item_again.content().as_msglike().unwrap(); + let in_reply_to = msglike.in_reply_to.clone().unwrap(); assert_let!(TimelineDetails::Ready(replied_to_event) = &in_reply_to.event); assert_matches!(replied_to_event.content(), TimelineItemContent::RedactedMessage); diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs b/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs index 457a38c24..ac6a40759 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs @@ -27,8 +27,8 @@ use matrix_sdk::{ use matrix_sdk_test::{async_test, event_factory::EventFactory, JoinedRoomBuilder, ALICE, BOB}; use matrix_sdk_ui::{ timeline::{ - AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, EditError, Error, - EventSendState, RoomExt, TimelineDetails, TimelineEventItemId, TimelineItemContent, + EditError, Error, EventSendState, MsgLikeContent, MsgLikeKind, RoomExt, TimelineDetails, + TimelineEventItemId, TimelineItemContent, }, Timeline, }; @@ -85,8 +85,8 @@ async fn test_edit() { assert_eq!(item.read_receipts().len(), 1, "implicit read receipt"); assert_matches!(item.latest_edit_json(), None); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(msg), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(msg), in_reply_to, .. }) = item.content() @@ -134,8 +134,8 @@ async fn test_edit() { let item = item.as_event().unwrap(); assert_matches!(item.latest_edit_json(), None); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(msg), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(msg), in_reply_to, .. }) = item.content() @@ -159,8 +159,8 @@ async fn test_edit() { let item = edit.as_event().unwrap(); assert_matches!(item.latest_edit_json(), Some(_)); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(edited), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(edited), in_reply_to, .. }) = item.content() @@ -371,11 +371,11 @@ async fn test_send_reply_edit() { // Reply message. let reply_item = assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => value); - let aggregated = reply_item.content().as_aggregated().unwrap(); + let msglike = reply_item.content().as_msglike().unwrap(); let reply_message = reply_item.content().as_message().unwrap(); assert!(!reply_message.is_edited()); assert!(reply_item.is_editable()); - let in_reply_to = aggregated.in_reply_to.clone().unwrap(); + let in_reply_to = msglike.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id); assert_matches!(in_reply_to.event, TimelineDetails::Ready(_)); @@ -403,7 +403,7 @@ async fn test_send_reply_edit() { let edit_message = edit_item.content().as_message().unwrap(); assert_eq!(edit_message.body(), "Hello, Room!"); assert!(edit_message.is_edited()); - let in_reply_to = aggregated.in_reply_to.clone().unwrap(); + let in_reply_to = msglike.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id); assert_matches!(in_reply_to.event, TimelineDetails::Ready(_)); @@ -454,11 +454,11 @@ async fn test_edit_to_replied_updates_reply() { }); assert_next_matches!(timeline_stream, VectorDiff::PushBack { value: reply_item } => { - let aggregated = reply_item.content().as_aggregated().unwrap(); + let msglike = reply_item.content().as_msglike().unwrap(); let reply_message = reply_item.content().as_message().unwrap(); assert_eq!(reply_message.body(), "hi back"); - let in_reply_to = aggregated.in_reply_to.clone().unwrap(); + let in_reply_to = msglike.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, eid1); assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event); @@ -466,11 +466,11 @@ async fn test_edit_to_replied_updates_reply() { }); assert_next_matches!(timeline_stream, VectorDiff::PushBack { value: reply_item } => { - let aggregated = reply_item.content().as_aggregated().unwrap(); + let msglike = reply_item.content().as_msglike().unwrap(); let reply_message = reply_item.content().as_message().unwrap(); assert_eq!(reply_message.body(), "yo"); - let in_reply_to = aggregated.in_reply_to.clone().unwrap(); + let in_reply_to = msglike.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, eid1); assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event); @@ -494,24 +494,24 @@ async fn test_edit_to_replied_updates_reply() { // The reply events are updated with the edited replied-to content. assert_next_matches!(timeline_stream, VectorDiff::Set { index: 1, value } => { - let aggregated = value.content().as_aggregated().unwrap(); + let msglike = value.content().as_msglike().unwrap(); let reply_message = value.content().as_message().unwrap(); assert_eq!(reply_message.body(), "hi back"); assert!(!reply_message.is_edited()); - let in_reply_to = aggregated.in_reply_to.clone().unwrap(); + let in_reply_to = msglike.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, eid1); assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event); assert_eq!(replied_to.content().as_message().unwrap().body(), "hello world"); }); assert_next_matches!(timeline_stream, VectorDiff::Set { index: 2, value } => { - let aggregated = value.content().as_aggregated().unwrap(); + let msglike = value.content().as_msglike().unwrap(); let reply_message = value.content().as_message().unwrap(); assert_eq!(reply_message.body(), "yo"); assert!(!reply_message.is_edited()); - let in_reply_to = aggregated.in_reply_to.clone().unwrap(); + let in_reply_to = msglike.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, eid1); assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event); assert_eq!(replied_to.content().as_message().unwrap().body(), "hello world"); @@ -1105,9 +1105,9 @@ async fn test_pending_poll_edit() { // Then I get the edited content immediately. assert_let!(VectorDiff::PushBack { value } = &timeline_updates[0]); - let aggregated = - as_variant!(value.as_event().unwrap().content(), TimelineItemContent::Aggregated).unwrap(); - let poll = as_variant!(&aggregated.kind, AggregatedTimelineItemContentKind::Poll).unwrap(); + let msglike = + as_variant!(value.as_event().unwrap().content(), TimelineItemContent::MsgLike).unwrap(); + let poll = as_variant!(&msglike.kind, MsgLikeKind::Poll).unwrap(); assert!(poll.is_edit()); let results = poll.results(); diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs b/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs index c8e1e8e72..071f97bdf 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs @@ -10,8 +10,8 @@ use matrix_sdk_test::{ async_test, event_factory::EventFactory, JoinedRoomBuilder, ALICE, BOB, CAROL, }; use matrix_sdk_ui::timeline::{ - AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, Error as TimelineError, - EventSendState, RoomExt, TimelineDetails, TimelineItemContent, + Error as TimelineError, EventSendState, MsgLikeContent, MsgLikeKind, RoomExt, TimelineDetails, + TimelineItemContent, }; use ruma::{ event_id, @@ -91,8 +91,8 @@ async fn test_in_reply_to_details() { assert_let!(VectorDiff::PushBack { value: second } = &timeline_updates[1]); let second_event = second.as_event().unwrap(); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = second_event.content() @@ -127,8 +127,8 @@ async fn test_in_reply_to_details() { assert_let!(VectorDiff::PushBack { value: third } = &timeline_updates[1]); let third_event = third.as_event().unwrap(); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = third_event.content() @@ -162,8 +162,8 @@ async fn test_in_reply_to_details() { // First it's set to pending, because we're starting the request… assert_let!(VectorDiff::Set { index: 3, value: third } = &timeline_updates[0]); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = third.as_event().unwrap().content() @@ -174,8 +174,8 @@ async fn test_in_reply_to_details() { // …then it's marked as an error when the request fails. assert_let!(VectorDiff::Set { index: 3, value: third } = &timeline_updates[1]); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = third.as_event().unwrap().content() @@ -208,8 +208,8 @@ async fn test_in_reply_to_details() { // First it's set to pending, because we're starting the request… assert_let!(VectorDiff::Set { index: 3, value: third } = &timeline_updates[0]); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = third.as_event().unwrap().content() @@ -220,8 +220,8 @@ async fn test_in_reply_to_details() { // …then it's filled when the request succeeds. assert_let!(VectorDiff::Set { index: 3, value: third } = &timeline_updates[1]); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = third.as_event().unwrap().content() @@ -300,8 +300,8 @@ async fn test_fetch_details_utd() { assert_let!(VectorDiff::PushBack { value: second } = &timeline_updates[0]); let second_event = second.as_event().unwrap(); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = second_event.content() @@ -325,8 +325,8 @@ async fn test_fetch_details_utd() { // First it's set to pending, because we're starting the request… assert_let!(VectorDiff::Set { index: 1, value } = &timeline_updates[0]); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = value.as_event().unwrap().content() @@ -336,8 +336,8 @@ async fn test_fetch_details_utd() { // …then it's filled as the request succeeds. assert_let!(VectorDiff::Set { index: 1, value } = &timeline_updates[1]); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = value.as_event().unwrap().content() @@ -406,8 +406,8 @@ async fn test_fetch_details_poll() { assert_let!(VectorDiff::PushBack { value: second } = &timeline_updates[0]); let second_event = second.as_event().unwrap(); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = second_event.content() @@ -431,8 +431,8 @@ async fn test_fetch_details_poll() { // First it's set to pending, because we're starting the request… assert_let!(VectorDiff::Set { index: 1, value } = &timeline_updates[0]); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = value.as_event().unwrap().content() @@ -442,8 +442,8 @@ async fn test_fetch_details_poll() { // …then it's filled as the request succeeds. assert_let!(VectorDiff::Set { index: 1, value } = &timeline_updates[1]); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = value.as_event().unwrap().content() @@ -517,8 +517,8 @@ async fn test_fetch_details_sticker() { assert_let!(VectorDiff::PushBack { value: second } = &timeline_updates[0]); let second_event = second.as_event().unwrap(); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = second_event.content() @@ -542,8 +542,8 @@ async fn test_fetch_details_sticker() { // First it's set to pending, because we're starting the request… assert_let!(VectorDiff::Set { index: 1, value } = &timeline_updates[0]); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = value.as_event().unwrap().content() @@ -553,8 +553,8 @@ async fn test_fetch_details_sticker() { // …then it's filled as the request succeeds. assert_let!(VectorDiff::Set { index: 1, value } = &timeline_updates[1]); assert_let!( - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(_), in_reply_to, .. }) = value.as_event().unwrap().content() @@ -596,8 +596,8 @@ async fn test_transfer_in_reply_to_details_to_re_received_item() { let items = timeline.items().await; assert_eq!(items.len(), 2); // date divider, reply let event_item = items[1].as_event().unwrap(); - let aggregated = event_item.content().as_aggregated().unwrap(); - let in_reply_to = aggregated.in_reply_to.clone().unwrap(); + let msglike = event_item.content().as_msglike().unwrap(); + let in_reply_to = msglike.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_1); assert_matches!(in_reply_to.event, TimelineDetails::Unavailable); @@ -615,15 +615,8 @@ async fn test_transfer_in_reply_to_details_to_re_received_item() { // (which succeeds) let items = timeline.items().await; assert_eq!(items.len(), 2); - let in_reply_to = items[1] - .as_event() - .unwrap() - .content() - .as_aggregated() - .unwrap() - .in_reply_to - .clone() - .unwrap(); + let in_reply_to = + items[1].as_event().unwrap().content().as_msglike().unwrap().in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_1); assert_matches!(in_reply_to.event, TimelineDetails::Ready(_)); @@ -635,15 +628,8 @@ async fn test_transfer_in_reply_to_details_to_re_received_item() { // ... the replied-to event details should remain from when we fetched them let items = timeline.items().await; assert_eq!(items.len(), 2); - let in_reply_to = items[1] - .as_event() - .unwrap() - .content() - .as_aggregated() - .unwrap() - .in_reply_to - .clone() - .unwrap(); + let in_reply_to = + items[1].as_event().unwrap().content().as_msglike().unwrap().in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_1); assert_matches!(in_reply_to.event, TimelineDetails::Ready(_)); } @@ -718,10 +704,10 @@ async fn test_send_reply() { let reply_item = assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => value); assert_matches!(reply_item.send_state(), Some(EventSendState::NotSentYet)); - let aggregated_reply_message = reply_item.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item.content().as_msglike().unwrap(); let reply_message = reply_item.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to Bob"); - let in_reply_to = aggregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_from_bob); // Right now, we don't pass along the replied-to event to the event handler, @@ -736,10 +722,10 @@ async fn test_send_reply() { assert_let!(VectorDiff::Set { index: 0, value: reply_item_remote_echo } = diff); assert_matches!(reply_item_remote_echo.send_state(), Some(EventSendState::Sent { .. })); - let aggregated_reply_message = reply_item_remote_echo.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item_remote_echo.content().as_msglike().unwrap(); let reply_message = reply_item_remote_echo.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to Bob"); - let in_reply_to = aggregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_from_bob); // Same as above. @@ -818,20 +804,20 @@ async fn test_send_reply_to_self() { let reply_item = assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => value); assert_matches!(reply_item.send_state(), Some(EventSendState::NotSentYet)); - let aggregated_reply_message = reply_item.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item.content().as_msglike().unwrap(); let reply_message = reply_item.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to self"); - let in_reply_to = aggregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_from_self); let diff = timeout(timeline_stream.next(), Duration::from_secs(1)).await.unwrap().unwrap(); assert_let!(VectorDiff::Set { index: 0, value: reply_item_remote_echo } = diff); assert_matches!(reply_item_remote_echo.send_state(), Some(EventSendState::Sent { .. })); - let aggregated_reply_message = reply_item_remote_echo.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item_remote_echo.content().as_msglike().unwrap(); let reply_message = reply_item_remote_echo.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to self"); - let in_reply_to = aggregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_from_self); } @@ -884,15 +870,15 @@ async fn test_send_reply_to_threaded() { let reply_item = assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => value); assert_matches!(reply_item.send_state(), Some(EventSendState::NotSentYet)); - let aggregated = reply_item.content().as_aggregated().unwrap(); + let msglike = reply_item.content().as_msglike().unwrap(); let reply_message = reply_item.content().as_message().unwrap(); // The reply should be considered part of the thread. - assert!(aggregated.is_threaded()); + assert!(msglike.is_threaded()); // Some extra assertions. assert_eq!(reply_message.body(), "Hello, Bob!"); - let in_reply_to = aggregated.in_reply_to.clone().unwrap(); + let in_reply_to = msglike.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_1); assert_let!(TimelineDetails::Ready(replied_to_event) = &in_reply_to.event); @@ -905,10 +891,10 @@ async fn test_send_reply_to_threaded() { assert_matches!(reply_item_remote_echo.send_state(), Some(EventSendState::Sent { .. })); // Same assertions as before still hold on the contained message. - assert!(aggregated.is_threaded()); + assert!(msglike.is_threaded()); assert_eq!(reply_message.body(), "Hello, Bob!"); - let in_reply_to = aggregated.in_reply_to.clone().unwrap(); + let in_reply_to = msglike.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_1); assert_let!(TimelineDetails::Ready(replied_to_event) = &in_reply_to.event); @@ -987,20 +973,20 @@ async fn test_send_reply_with_event_id() { let reply_item = assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => value); assert_matches!(reply_item.send_state(), Some(EventSendState::NotSentYet)); - let aggregregated_reply_message = reply_item.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item.content().as_msglike().unwrap(); let reply_message = reply_item.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to Bob"); - let in_reply_to = aggregregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_from_bob); let diff = timeout(timeline_stream.next(), Duration::from_secs(1)).await.unwrap().unwrap(); assert_let!(VectorDiff::Set { index: 0, value: reply_item_remote_echo } = diff); assert_matches!(reply_item_remote_echo.send_state(), Some(EventSendState::Sent { .. })); - let aggregregated_reply_message = reply_item_remote_echo.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item_remote_echo.content().as_msglike().unwrap(); let reply_message = reply_item_remote_echo.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to Bob"); - let in_reply_to = aggregregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_from_bob); } @@ -1073,23 +1059,23 @@ async fn test_send_reply_enforce_thread() { let reply_item = assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => value); assert_matches!(reply_item.send_state(), Some(EventSendState::NotSentYet)); - let aggregated_reply_message = reply_item.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item.content().as_msglike().unwrap(); let reply_message = reply_item.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to Bob"); - let in_reply_to = aggregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_from_bob); - assert_eq!(aggregated_reply_message.thread_root.clone().unwrap(), event_id_from_bob); + assert_eq!(msglike_reply_message.thread_root.clone().unwrap(), event_id_from_bob); let diff = timeout(timeline_stream.next(), Duration::from_secs(1)).await.unwrap().unwrap(); assert_let!(VectorDiff::Set { index: 0, value: reply_item_remote_echo } = diff); assert_matches!(reply_item_remote_echo.send_state(), Some(EventSendState::Sent { .. })); - let aggregated_reply_message = reply_item_remote_echo.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item_remote_echo.content().as_msglike().unwrap(); let reply_message = reply_item_remote_echo.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to Bob"); - let in_reply_to = aggregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_from_bob); - assert_eq!(aggregated_reply_message.thread_root.clone().unwrap(), event_id_from_bob); + assert_eq!(msglike_reply_message.thread_root.clone().unwrap(), event_id_from_bob); } #[async_test] @@ -1170,23 +1156,23 @@ async fn test_send_reply_enforce_thread_is_reply() { let reply_item = assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => value); assert_matches!(reply_item.send_state(), Some(EventSendState::NotSentYet)); - let aggregated_reply_message = reply_item.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item.content().as_msglike().unwrap(); let reply_message = reply_item.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to Bob"); - let in_reply_to = aggregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_from_bob); - assert_eq!(aggregated_reply_message.thread_root.clone().unwrap(), thread_root); + assert_eq!(msglike_reply_message.thread_root.clone().unwrap(), thread_root); let diff = timeout(timeline_stream.next(), Duration::from_secs(1)).await.unwrap().unwrap(); assert_let!(VectorDiff::Set { index: 0, value: reply_item_remote_echo } = diff); assert_matches!(reply_item_remote_echo.send_state(), Some(EventSendState::Sent { .. })); - let aggregated_reply_message = reply_item_remote_echo.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item_remote_echo.content().as_msglike().unwrap(); let reply_message = reply_item_remote_echo.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to Bob"); - let in_reply_to = aggregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, event_id_from_bob); - assert_eq!(aggregated_reply_message.thread_root.clone().unwrap(), thread_root); + assert_eq!(msglike_reply_message.thread_root.clone().unwrap(), thread_root); } #[async_test] @@ -1263,19 +1249,19 @@ async fn test_send_reply_with_event_id_that_is_redacted() { let reply_item = assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => value); assert_matches!(reply_item.send_state(), Some(EventSendState::NotSentYet)); - let aggregregated_reply_message = reply_item.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item.content().as_msglike().unwrap(); let reply_message = reply_item.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to Bob"); - let in_reply_to = aggregregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, redacted_event_id_from_bob); let diff = timeout(timeline_stream.next(), Duration::from_secs(1)).await.unwrap().unwrap(); assert_let!(VectorDiff::Set { index: 0, value: reply_item_remote_echo } = diff); assert_matches!(reply_item_remote_echo.send_state(), Some(EventSendState::Sent { .. })); - let aggregregated_reply_message = reply_item_remote_echo.content().as_aggregated().unwrap(); + let msglike_reply_message = reply_item_remote_echo.content().as_msglike().unwrap(); let reply_message = reply_item_remote_echo.content().as_message().unwrap(); assert_eq!(reply_message.body(), "Replying to Bob"); - let in_reply_to = aggregregated_reply_message.in_reply_to.clone().unwrap(); + let in_reply_to = msglike_reply_message.in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, redacted_event_id_from_bob); } diff --git a/labs/multiverse/src/main.rs b/labs/multiverse/src/main.rs index c9c757b36..b8e2fa139 100644 --- a/labs/multiverse/src/main.rs +++ b/labs/multiverse/src/main.rs @@ -28,8 +28,8 @@ use matrix_sdk_ui::{ room_list_service::{self, filters::new_filter_non_left}, sync_service::SyncService, timeline::{ - AggregatedTimelineItemContent, AggregatedTimelineItemContentKind, TimelineItem, - TimelineItemContent, TimelineItemKind, VirtualTimelineItem, + MsgLikeContent, MsgLikeKind, TimelineItem, TimelineItemContent, TimelineItemKind, + VirtualTimelineItem, }, Timeline as SdkTimeline, }; @@ -806,8 +806,8 @@ impl App { let sender = ev.sender(); match ev.content() { - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Message(message), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Message(message), .. }) => { if let MessageType::Text(text) = message.msgtype() { @@ -821,8 +821,8 @@ impl App { TimelineItemContent::UnableToDecrypt(_) => { content.push(format!("{}: (UTD)", sender)) } - TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Sticker(_), + TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Sticker(_), .. }) | TimelineItemContent::MembershipChange(_) @@ -830,8 +830,8 @@ impl App { | TimelineItemContent::OtherState(_) | TimelineItemContent::FailedToParseMessageLike { .. } | TimelineItemContent::FailedToParseState { .. } - | TimelineItemContent::Aggregated(AggregatedTimelineItemContent { - kind: AggregatedTimelineItemContentKind::Poll(_), + | TimelineItemContent::MsgLike(MsgLikeContent { + kind: MsgLikeKind::Poll(_), .. }) | TimelineItemContent::CallInvite