diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content.rs index b145012f5..d6cdcd565 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content.rs @@ -12,12 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::{fmt, ops::Deref, sync::Arc}; +use std::{fmt, sync::Arc}; use as_variant::as_variant; use imbl::{vector, Vector}; -use indexmap::IndexMap; -use itertools::Itertools; use matrix_sdk::{deserialized_responses::TimelineEvent, Result}; use matrix_sdk_base::latest_event::{is_suitable_for_latest_event, PossibleLatestEvent}; use ruma::{ @@ -56,17 +54,13 @@ use ruma::{ MessageLikeEventType, StateEventType, }, html::RemoveReplyFallback, - OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedTransactionId, OwnedUserId, RoomVersionId, - UserId, + OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedUserId, RoomVersionId, UserId, }; use tracing::{error, warn}; -use super::{EventItemIdentifier, EventTimelineItem, Profile, TimelineDetails}; +use super::{EventTimelineItem, Profile, TimelineDetails}; use crate::{ - timeline::{ - polls::PollState, traits::RoomDataProvider, Error as TimelineError, ReactionSenderData, - TimelineItem, - }, + timeline::{polls::PollState, traits::RoomDataProvider, Error as TimelineError, TimelineItem}, DEFAULT_SANITIZER_MODE, }; @@ -584,50 +578,6 @@ impl From for EncryptedMessage { } } -/// The reactions grouped by key. -/// -/// Key: The reaction, usually an emoji.\ -/// Value: The group of reactions. -pub type BundledReactions = IndexMap; -/// A group of reaction events on the same event with the same key. -/// -/// This is a map of the event ID or transaction ID of the reactions to the ID -/// of the sender of the reaction. -#[derive(Clone, Debug, Default)] -pub struct ReactionGroup(pub(in crate::timeline) IndexMap); - -impl ReactionGroup { - /// The (deduplicated) senders of the reactions in this group. - pub fn senders(&self) -> impl Iterator { - self.values().unique_by(|v| &v.sender_id) - } - - /// All reactions within this reaction group that were sent by the given - /// user. - /// - /// Note that it is possible for multiple reactions by the same user to - /// have arrived over federation. - pub fn by_sender<'a>( - &'a self, - user_id: &'a UserId, - ) -> impl Iterator, Option<&OwnedEventId>)> + 'a { - self.iter().filter_map(move |(k, v)| { - (v.sender_id == user_id).then_some(match k { - EventItemIdentifier::TransactionId(txn_id) => (Some(txn_id), None), - EventItemIdentifier::EventId(event_id) => (None, Some(event_id)), - }) - }) - } -} - -impl Deref for ReactionGroup { - type Target = IndexMap; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - /// An `m.sticker` event. #[derive(Clone, Debug)] pub struct Sticker { 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 2d9781d5d..684e067cd 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs @@ -28,15 +28,17 @@ use tracing::warn; mod content; mod local; +mod reactions; mod remote; pub use self::{ content::{ - AnyOtherFullStateEventContent, BundledReactions, EncryptedMessage, InReplyToDetails, - MemberProfileChange, MembershipChange, Message, OtherState, ReactionGroup, RepliedToEvent, - RoomMembershipChange, Sticker, TimelineItemContent, + AnyOtherFullStateEventContent, EncryptedMessage, InReplyToDetails, MemberProfileChange, + MembershipChange, Message, OtherState, RepliedToEvent, RoomMembershipChange, Sticker, + TimelineItemContent, }, local::EventSendState, + reactions::{BundledReactions, ReactionGroup}, }; pub(super) use self::{ local::LocalEventTimelineItem, diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/reactions.rs b/crates/matrix-sdk-ui/src/timeline/event_item/reactions.rs new file mode 100644 index 000000000..747651ab7 --- /dev/null +++ b/crates/matrix-sdk-ui/src/timeline/event_item/reactions.rs @@ -0,0 +1,67 @@ +// Copyright 2023 The Matrix.org Foundation C.I.C. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use std::ops::Deref; + +use indexmap::IndexMap; +use itertools::Itertools; +use ruma::{OwnedEventId, OwnedTransactionId, UserId}; + +use super::EventItemIdentifier; +use crate::timeline::ReactionSenderData; + +/// The reactions grouped by key. +/// +/// Key: The reaction, usually an emoji.\ +/// Value: The group of reactions. +pub type BundledReactions = IndexMap; + +/// A group of reaction events on the same event with the same key. +/// +/// This is a map of the event ID or transaction ID of the reactions to the ID +/// of the sender of the reaction. +#[derive(Clone, Debug, Default)] +pub struct ReactionGroup(pub(in crate::timeline) IndexMap); + +impl ReactionGroup { + /// The (deduplicated) senders of the reactions in this group. + pub fn senders(&self) -> impl Iterator { + self.values().unique_by(|v| &v.sender_id) + } + + /// All reactions within this reaction group that were sent by the given + /// user. + /// + /// Note that it is possible for multiple reactions by the same user to + /// have arrived over federation. + pub fn by_sender<'a>( + &'a self, + user_id: &'a UserId, + ) -> impl Iterator, Option<&OwnedEventId>)> + 'a { + self.iter().filter_map(move |(k, v)| { + (v.sender_id == user_id).then_some(match k { + EventItemIdentifier::TransactionId(txn_id) => (Some(txn_id), None), + EventItemIdentifier::EventId(event_id) => (None, Some(event_id)), + }) + }) + } +} + +impl Deref for ReactionGroup { + type Target = IndexMap; + + fn deref(&self) -> &Self::Target { + &self.0 + } +}