From 5faff343a0c12b4d4e58d91ecb9d433644a17047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 25 Nov 2022 19:59:15 +0100 Subject: [PATCH] events: Use Reference instead of events::poll::ReferenceRelation --- crates/ruma-common/src/events/enums.rs | 7 +++---- crates/ruma-common/src/events/poll.rs | 20 ------------------- crates/ruma-common/src/events/poll/end.rs | 7 +++---- .../ruma-common/src/events/poll/response.rs | 7 +++---- crates/ruma-common/tests/events/poll.rs | 10 +++++----- 5 files changed, 14 insertions(+), 37 deletions(-) diff --git a/crates/ruma-common/src/events/enums.rs b/crates/ruma-common/src/events/enums.rs index a2bcdf25..a994c1e1 100644 --- a/crates/ruma-common/src/events/enums.rs +++ b/crates/ruma-common/src/events/enums.rs @@ -7,8 +7,8 @@ use super::{ Redact, Relations, }; use crate::{ - events::relation::Reference, serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch, - OwnedRoomId, RoomId, RoomVersionId, TransactionId, UserId, + serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, RoomId, + RoomVersionId, TransactionId, UserId, }; event_enum! { @@ -351,8 +351,7 @@ impl AnyMessageLikeEventContent { #[cfg(feature = "unstable-msc3381")] Self::PollResponse(PollResponseEventContent { relates_to, .. }) | Self::PollEnd(PollEndEventContent { relates_to, .. }) => { - let super::poll::ReferenceRelation { event_id } = relates_to; - Some(encrypted::Relation::Reference(Reference { event_id: event_id.clone() })) + Some(encrypted::Relation::Reference(relates_to.clone())) } #[cfg(feature = "unstable-msc3381")] Self::PollStart(_) => None, diff --git a/crates/ruma-common/src/events/poll.rs b/crates/ruma-common/src/events/poll.rs index 56db6b49..185f00c9 100644 --- a/crates/ruma-common/src/events/poll.rs +++ b/crates/ruma-common/src/events/poll.rs @@ -4,26 +4,6 @@ //! //! [MSC3381]: https://github.com/matrix-org/matrix-spec-proposals/pull/3381 -use serde::{Deserialize, Serialize}; - -use crate::OwnedEventId; - pub mod end; pub mod response; pub mod start; - -/// An `m.reference` relation. -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[serde(tag = "rel_type", rename = "m.reference")] -pub struct ReferenceRelation { - /// The ID of the event this references. - pub event_id: OwnedEventId, -} - -impl ReferenceRelation { - /// Creates a new `ReferenceRelation` that references the given event ID. - pub fn new(event_id: OwnedEventId) -> Self { - Self { event_id } - } -} diff --git a/crates/ruma-common/src/events/poll/end.rs b/crates/ruma-common/src/events/poll/end.rs index 405013e3..491a0ad5 100644 --- a/crates/ruma-common/src/events/poll/end.rs +++ b/crates/ruma-common/src/events/poll/end.rs @@ -3,8 +3,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use super::ReferenceRelation; -use crate::OwnedEventId; +use crate::{events::relation::Reference, OwnedEventId}; /// The payload for a poll end event. #[derive(Clone, Debug, Serialize, Deserialize, EventContent)] @@ -17,14 +16,14 @@ pub struct PollEndEventContent { /// Information about the poll start event this responds to. #[serde(rename = "m.relates_to")] - pub relates_to: ReferenceRelation, + pub relates_to: Reference, } impl PollEndEventContent { /// Creates a new `PollEndEventContent` that responds to the given poll start event ID, /// with the given poll end content. pub fn new(poll_end: PollEndContent, poll_start_id: OwnedEventId) -> Self { - Self { poll_end, relates_to: ReferenceRelation::new(poll_start_id) } + Self { poll_end, relates_to: Reference::new(poll_start_id) } } } diff --git a/crates/ruma-common/src/events/poll/response.rs b/crates/ruma-common/src/events/poll/response.rs index 338a8602..445ea417 100644 --- a/crates/ruma-common/src/events/poll/response.rs +++ b/crates/ruma-common/src/events/poll/response.rs @@ -3,8 +3,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use super::ReferenceRelation; -use crate::OwnedEventId; +use crate::{events::relation::Reference, OwnedEventId}; /// The payload for a poll response event. #[derive(Clone, Debug, Serialize, Deserialize, EventContent)] @@ -17,14 +16,14 @@ pub struct PollResponseEventContent { /// Information about the poll start event this responds to. #[serde(rename = "m.relates_to")] - pub relates_to: ReferenceRelation, + pub relates_to: Reference, } impl PollResponseEventContent { /// Creates a new `PollResponseEventContent` that responds to the given poll start event ID, /// with the given poll response content. pub fn new(poll_response: PollResponseContent, poll_start_id: OwnedEventId) -> Self { - Self { poll_response, relates_to: ReferenceRelation::new(poll_start_id) } + Self { poll_response, relates_to: Reference::new(poll_start_id) } } } diff --git a/crates/ruma-common/tests/events/poll.rs b/crates/ruma-common/tests/events/poll.rs index 0915e523..87c86c4e 100644 --- a/crates/ruma-common/tests/events/poll.rs +++ b/crates/ruma-common/tests/events/poll.rs @@ -14,8 +14,8 @@ use ruma_common::{ PollAnswer, PollAnswers, PollAnswersError, PollKind, PollStartContent, PollStartEventContent, }, - ReferenceRelation, }, + relation::Reference, AnyMessageLikeEvent, MessageLikeEvent, MessageLikeUnsigned, OriginalMessageLikeEvent, }, room_id, user_id, MilliSecondsSinceUnixEpoch, @@ -318,7 +318,7 @@ fn response_event_unstable_deserialization() { assert_eq!(answers[0], "my-answer"); let event_id = assert_matches!( message_event.content.relates_to, - ReferenceRelation { event_id, .. } => event_id + Reference { event_id, .. } => event_id ); assert_eq!(event_id, "$related_event:notareal.hs"); } @@ -354,7 +354,7 @@ fn response_event_stable_deserialization() { assert_eq!(answers[1], "second-answer"); let event_id = assert_matches!( message_event.content.relates_to, - ReferenceRelation { event_id, .. } => event_id + Reference { event_id, .. } => event_id ); assert_eq!(event_id, "$related_event:notareal.hs"); } @@ -435,7 +435,7 @@ fn end_event_unstable_deserialization() { ); let event_id = assert_matches!( message_event.content.relates_to, - ReferenceRelation { event_id, .. } => event_id + Reference { event_id, .. } => event_id ); assert_eq!(event_id, "$related_event:notareal.hs"); } @@ -464,7 +464,7 @@ fn end_event_stable_deserialization() { ); let event_id = assert_matches!( message_event.content.relates_to, - ReferenceRelation { event_id, .. } => event_id + Reference { event_id, .. } => event_id ); assert_eq!(event_id, "$related_event:notareal.hs"); }