make matrix-sdk-ui structs optionally serialisable

This commit is contained in:
Matthew Hodgson
2024-03-06 01:07:24 +00:00
parent 82684d64d4
commit a15aefc50e
13 changed files with 53 additions and 5 deletions

View File

@@ -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"

View File

@@ -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 }

View File

@@ -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<InReplyToDetails>,
@@ -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,

View File

@@ -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<serde_json::Error>,
},
@@ -101,6 +104,7 @@ pub enum TimelineItemContent {
state_key: String,
/// The deserialization error.
#[cfg_attr(feature = "serde", serde(skip_serializing))]
error: Arc<serde_json::Error>,
},
@@ -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<RoomEncryptedEventContent> 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<RoomMemberEventContent>,
@@ -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<Change<Option<String>>>,
@@ -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<PolicyRuleRoomEventContent>),
@@ -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,

View File

@@ -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<Error>,
},
/// Sending has been cancelled because an earlier event in the

View File

@@ -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<RemoteEventTimelineItem> 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<String>,
@@ -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<T> {
/// The details are not available yet, and have not been request from the
/// server.
@@ -471,6 +477,7 @@ pub enum TimelineDetails<T> {
Ready(T),
/// An error occurred when fetching the details.
#[cfg_attr(feature = "serde", serde(skip_serializing))]
Error(Arc<Error>),
}
@@ -494,6 +501,7 @@ impl<T> TimelineDetails<T> {
/// 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,

View File

@@ -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<String, ReactionGroup>;
/// 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<EventItemIdentifier, ReactionSenderData>);
impl ReactionGroup {

View File

@@ -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,

View File

@@ -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,

View File

@@ -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<ResponseData>,
@@ -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,

View File

@@ -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,

View File

@@ -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.
///

View File

@@ -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 = [