diff --git a/Cargo.toml b/Cargo.toml index 9704b0730..d4ee8c34f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,16 +28,16 @@ async-trait = "0.1.60" as_variant = "1.2.0" base64 = "0.21.0" byteorder = "1.4.3" -eyeball = { version = "0.8.7", features = ["tracing"] } -eyeball-im = { version = "0.4.1", features = ["tracing"] } -eyeball-im-util = "0.5.1" +eyeball = { path="../eyeball/eyeball", features = ["tracing"] } +eyeball-im = { path="../eyeball/eyeball-im", features = ["tracing"] } +eyeball-im-util = { path="../eyeball/eyeball-im-util" } futures-core = "0.3.28" futures-executor = "0.3.21" futures-util = { version = "0.3.26", default-features = false, features = ["alloc"] } http = "0.2.6" itertools = "0.12.0" -ruma = { git = "https://github.com/ruma/ruma", rev = "68c9bb0930f2195fa8672fbef9633ef62737df5d", features = ["client-api-c", "compat-upload-signatures", "compat-user-id", "compat-arbitrary-length-ids", "unstable-msc3401"] } -ruma-common = { git = "https://github.com/ruma/ruma", rev = "68c9bb0930f2195fa8672fbef9633ef62737df5d" } +ruma = { path="../ruma/crates/ruma", features = ["client-api-c", "compat-upload-signatures", "compat-user-id", "compat-arbitrary-length-ids", "unstable-msc3401"] } +ruma-common = { path="../ruma/crates/ruma-common" } once_cell = "1.16.0" rand = "0.8.5" serde = "1.0.151" diff --git a/crates/matrix-sdk-ui/Cargo.toml b/crates/matrix-sdk-ui/Cargo.toml index f18b6edb5..41f2aa379 100644 --- a/crates/matrix-sdk-ui/Cargo.toml +++ b/crates/matrix-sdk-ui/Cargo.toml @@ -16,6 +16,7 @@ native-tls = ["matrix-sdk/native-tls"] rustls-tls = ["matrix-sdk/rustls-tls"] uniffi = ["dep:uniffi"] +serde = [] [dependencies] as_variant = { workspace = true } diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs index 708edabb9..0ec1a83ba 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs @@ -36,6 +36,7 @@ use ruma::{ OwnedEventId, OwnedUserId, RoomVersionId, UserId, }; use tracing::error; +use serde::Serialize; use super::TimelineItemContent; use crate::{ @@ -49,6 +50,7 @@ use crate::{ /// An `m.room.message` event or extensible event, including edits. #[derive(Clone)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct Message { pub(in crate::timeline) msgtype: MessageType, pub(in crate::timeline) in_reply_to: Option, @@ -208,6 +210,7 @@ impl fmt::Debug for Message { /// Details about an event being replied to. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct InReplyToDetails { /// The ID of the event. pub event_id: OwnedEventId, @@ -238,6 +241,7 @@ impl InReplyToDetails { /// An event that is replied to. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct RepliedToEvent { pub(in crate::timeline) content: TimelineItemContent, pub(in crate::timeline) sender: OwnedUserId, 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 90de9430e..23d0b73c1 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 @@ -52,6 +52,7 @@ use ruma::{ OwnedDeviceId, OwnedMxcUri, OwnedUserId, RoomVersionId, UserId, }; use tracing::warn; +use serde::Serialize; use crate::timeline::{polls::PollState, TimelineItem}; @@ -61,6 +62,7 @@ pub use self::message::{InReplyToDetails, Message, RepliedToEvent}; /// The content of an [`EventTimelineItem`][super::EventTimelineItem]. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub enum TimelineItemContent { /// An `m.room.message` event or extensible event, including edits. Message(Message), @@ -89,6 +91,7 @@ pub enum TimelineItemContent { event_type: MessageLikeEventType, /// The deserialization error. + #[cfg_attr(feature = "serde", serde(skip_serializing))] error: Arc, }, @@ -101,6 +104,7 @@ pub enum TimelineItemContent { state_key: String, /// The deserialization error. + #[cfg_attr(feature = "serde", serde(skip_serializing))] error: Arc, }, @@ -317,6 +321,7 @@ impl TimelineItemContent { /// Metadata about an `m.room.encrypted` event that could not be decrypted. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub enum EncryptedMessage { /// Metadata about an event using the `m.olm.v1.curve25519-aes-sha2` /// algorithm. @@ -361,6 +366,7 @@ impl From for EncryptedMessage { /// An `m.sticker` event. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct Sticker { pub(in crate::timeline) content: StickerEventContent, } @@ -374,6 +380,7 @@ impl Sticker { /// An event changing a room membership. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct RoomMembershipChange { pub(in crate::timeline) user_id: OwnedUserId, pub(in crate::timeline) content: FullStateEventContent, @@ -413,6 +420,7 @@ impl RoomMembershipChange { /// An enum over all the possible room membership changes. #[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub enum MembershipChange { /// No change. None, @@ -471,6 +479,7 @@ pub enum MembershipChange { /// Note that profile changes only occur in the timeline when the user's /// membership is already `join`. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct MemberProfileChange { pub(in crate::timeline) user_id: OwnedUserId, pub(in crate::timeline) displayname_change: Option>>, @@ -509,6 +518,7 @@ impl MemberProfileChange { /// An enum over all the full state event contents that don't have their own /// `TimelineItemContent` variant. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyOtherFullStateEventContent { /// m.policy.rule.room PolicyRuleRoom(FullStateEventContent), @@ -705,6 +715,7 @@ impl AnyOtherFullStateEventContent { /// A state event that doesn't have its own variant. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct OtherState { pub(in crate::timeline) state_key: String, pub(in crate::timeline) content: AnyOtherFullStateEventContent, diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/local.rs b/crates/matrix-sdk-ui/src/timeline/event_item/local.rs index 1ef2f8af0..86873ff6f 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/local.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/local.rs @@ -18,9 +18,12 @@ use as_variant::as_variant; use matrix_sdk::Error; use ruma::{EventId, OwnedEventId, OwnedTransactionId}; +use serde::Serialize; + /// An item for an event that was created locally and not yet echoed back by /// the homeserver. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub(in crate::timeline) struct LocalEventTimelineItem { /// The send state of this local event. pub send_state: EventSendState, @@ -45,6 +48,7 @@ impl LocalEventTimelineItem { /// This type represents the "send state" of a local event timeline item. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub enum EventSendState { /// The local event has not been sent yet. NotSentYet, @@ -52,6 +56,7 @@ pub enum EventSendState { /// sending has failed. SendingFailed { /// Details about how sending the event failed. + #[cfg_attr(feature = "serde", serde(skip_serializing))] error: Arc, }, /// Sending has been cancelled because an earlier event in the 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 3e52d3fe6..ddf569665 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs @@ -25,6 +25,7 @@ use ruma::{ OwnedUserId, RoomId, RoomVersionId, TransactionId, UserId, }; use tracing::warn; +use serde::Serialize; mod content; mod local; @@ -51,6 +52,7 @@ pub(super) use self::{ /// identity but in many cases, additional events like reactions and edits are /// also part of the item. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct EventTimelineItem { /// The sender of the event. pub(super) sender: OwnedUserId, @@ -65,6 +67,7 @@ pub struct EventTimelineItem { } #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub(super) enum EventTimelineItemKind { /// A local event, not yet echoed back by the server. Local(LocalEventTimelineItem), @@ -74,6 +77,7 @@ pub(super) enum EventTimelineItemKind { /// A wrapper that can contain either a transaction id, or an event id. #[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub enum EventItemIdentifier { TransactionId(OwnedTransactionId), EventId(OwnedEventId), @@ -442,6 +446,7 @@ impl From for EventTimelineItemKind { /// The display name and avatar URL of a room member. #[derive(Clone, Debug, Default, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct Profile { /// The display name, if set. pub display_name: Option, @@ -459,6 +464,7 @@ pub struct Profile { /// other than just the regular /// [`sync_events`][ruma::api::client::sync::sync_events]. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub enum TimelineDetails { /// The details are not available yet, and have not been request from the /// server. @@ -471,6 +477,7 @@ pub enum TimelineDetails { Ready(T), /// An error occurred when fetching the details. + #[cfg_attr(feature = "serde", serde(skip_serializing))] Error(Arc), } @@ -494,6 +501,7 @@ impl TimelineDetails { /// Where this event came. #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] +#[cfg_attr(feature = "serde", derive(Serialize))] pub enum EventItemOrigin { /// The event was created locally. Local, diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/reactions.rs b/crates/matrix-sdk-ui/src/timeline/event_item/reactions.rs index 747651ab7..55d8cdfb2 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/reactions.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/reactions.rs @@ -17,6 +17,7 @@ use std::ops::Deref; use indexmap::IndexMap; use itertools::Itertools; use ruma::{OwnedEventId, OwnedTransactionId, UserId}; +use serde::Serialize; use super::EventItemIdentifier; use crate::timeline::ReactionSenderData; @@ -32,6 +33,7 @@ pub type BundledReactions = IndexMap; /// 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)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct ReactionGroup(pub(in crate::timeline) IndexMap); impl ReactionGroup { diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/remote.rs b/crates/matrix-sdk-ui/src/timeline/event_item/remote.rs index 6445abc5c..397ccd87f 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/remote.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/remote.rs @@ -21,15 +21,19 @@ use ruma::{ serde::Raw, OwnedEventId, OwnedUserId, }; +use serde::Serialize; use super::BundledReactions; /// An item for an event that was received from the homeserver. #[derive(Clone)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub(in crate::timeline) struct RemoteEventTimelineItem { /// The event ID. pub event_id: OwnedEventId, /// All bundled reactions about the event. + /// FIXME: Can't serialise ReactionGroup yet as its key is an enum + #[cfg_attr(feature = "serde", serde(skip_serializing))] pub reactions: BundledReactions, /// All read receipts for the event. /// @@ -81,6 +85,7 @@ impl RemoteEventTimelineItem { /// Where we got an event from. #[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub(in crate::timeline) enum RemoteEventOrigin { /// The event came from a cache. Cache, diff --git a/crates/matrix-sdk-ui/src/timeline/item.rs b/crates/matrix-sdk-ui/src/timeline/item.rs index 4f693fa06..2037edd51 100644 --- a/crates/matrix-sdk-ui/src/timeline/item.rs +++ b/crates/matrix-sdk-ui/src/timeline/item.rs @@ -15,10 +15,12 @@ use std::{ops::Deref, sync::Arc}; use as_variant::as_variant; +use serde::Serialize; use super::{EventTimelineItem, VirtualTimelineItem}; #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] #[allow(clippy::large_enum_variant)] pub enum TimelineItemKind { /// An event or aggregation of multiple events. @@ -30,6 +32,7 @@ pub enum TimelineItemKind { /// A single entry in timeline. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct TimelineItem { pub(crate) kind: TimelineItemKind, pub(crate) internal_id: u64, diff --git a/crates/matrix-sdk-ui/src/timeline/polls.rs b/crates/matrix-sdk-ui/src/timeline/polls.rs index 15ac975cf..fad4256ca 100644 --- a/crates/matrix-sdk-ui/src/timeline/polls.rs +++ b/crates/matrix-sdk-ui/src/timeline/polls.rs @@ -16,12 +16,15 @@ use ruma::{ EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, UserId, }; +use serde::Serialize; + /// Holds the state of a poll. /// /// This struct should be created for each poll start event handled and then /// updated whenever handling any poll response or poll end event that relates /// to the same poll start event. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct PollState { pub(super) start_event_content: NewUnstablePollStartEventContent, pub(super) response_data: Vec, @@ -30,6 +33,7 @@ pub struct PollState { } #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub(super) struct ResponseData { pub(super) sender: OwnedUserId, pub(super) timestamp: MilliSecondsSinceUnixEpoch, diff --git a/crates/matrix-sdk-ui/src/timeline/reactions.rs b/crates/matrix-sdk-ui/src/timeline/reactions.rs index a0b3c893c..1d6106787 100644 --- a/crates/matrix-sdk-ui/src/timeline/reactions.rs +++ b/crates/matrix-sdk-ui/src/timeline/reactions.rs @@ -19,6 +19,7 @@ use ruma::{ events::relation::Annotation, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedTransactionId, OwnedUserId, }; +use serde::Serialize; use super::event_item::EventItemIdentifier; @@ -26,6 +27,7 @@ use super::event_item::EventItemIdentifier; /// a details UI component for a reaction with both sender /// names and the date at which they sent a reaction. #[derive(Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct ReactionSenderData { /// Sender identifier. pub sender_id: OwnedUserId, diff --git a/crates/matrix-sdk-ui/src/timeline/virtual_item.rs b/crates/matrix-sdk-ui/src/timeline/virtual_item.rs index 650bc38b6..df3d44e85 100644 --- a/crates/matrix-sdk-ui/src/timeline/virtual_item.rs +++ b/crates/matrix-sdk-ui/src/timeline/virtual_item.rs @@ -13,9 +13,11 @@ // limitations under the License. use ruma::MilliSecondsSinceUnixEpoch; +use serde::Serialize; /// A [`TimelineItem`](super::TimelineItem) that doesn't correspond to an event. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub enum VirtualTimelineItem { /// A divider between messages of two days. /// diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index fa16af25b..662b72458 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -41,6 +41,7 @@ sso-login = ["dep:hyper", "dep:rand", "dep:tower"] image-proc = ["dep:image"] image-rayon = ["image-proc", "image?/jpeg_rayon"] +serde = [] uniffi = ["dep:uniffi"] experimental-oidc = [