From c98b2a1b3fdee71de94147dd29004dddfc9ad2ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 4 Jul 2025 10:51:09 +0200 Subject: [PATCH] refactor(test): Change the bound on EventBuilder to StaticEventContent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `EventContent` trait is gone in Ruma so this will ease the upgrade to the next breaking release. Signed-off-by: Kévin Commaille --- testing/matrix-sdk-test/src/event_factory.rs | 48 ++++++-------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/testing/matrix-sdk-test/src/event_factory.rs b/testing/matrix-sdk-test/src/event_factory.rs index 8eb359a6a..bc2e08136 100644 --- a/testing/matrix-sdk-test/src/event_factory.rs +++ b/testing/matrix-sdk-test/src/event_factory.rs @@ -60,8 +60,8 @@ use ruma::{ sticker::StickerEventContent, typing::TypingEventContent, AnyMessageLikeEvent, AnyStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, - AnyTimelineEvent, BundledMessageLikeRelations, EventContent, - RedactedMessageLikeEventContent, RedactedStateEventContent, StateEventContent, + AnyTimelineEvent, BundledMessageLikeRelations, RedactedMessageLikeEventContent, + RedactedStateEventContent, StateEventContent, StaticEventContent, }, serde::Raw, server_name, EventId, Int, MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId, OwnedMxcUri, @@ -105,7 +105,7 @@ struct RedactedBecause { } #[derive(Debug, Serialize)] -struct Unsigned { +struct Unsigned { #[serde(skip_serializing_if = "Option::is_none")] prev_content: Option, @@ -123,7 +123,7 @@ struct Unsigned { } // rustc can't derive Default because C isn't marked as `Default` 🤔 oh well. -impl Default for Unsigned { +impl Default for Unsigned { fn default() -> Self { Self { prev_content: None, @@ -136,7 +136,7 @@ impl Default for Unsigned { } #[derive(Debug)] -pub struct EventBuilder { +pub struct EventBuilder { sender: Option, /// Whether the event is an ephemeral one. As such, it doesn't require a /// room id or a sender. @@ -152,10 +152,7 @@ pub struct EventBuilder { state_key: Option, } -impl EventBuilder -where - E::EventType: Serialize, -{ +impl EventBuilder { pub fn room(mut self, room_id: &RoomId) -> Self { self.room = Some(room_id.to_owned()); self @@ -257,7 +254,7 @@ where } let mut json = json!({ - "type": self.content.event_type(), + "type": E::TYPE, "content": self.content, "origin_server_ts": self.server_ts, }); @@ -451,46 +448,31 @@ impl EventBuilder { } } -impl From> for Raw -where - E::EventType: Serialize, -{ +impl From> for Raw { fn from(val: EventBuilder) -> Self { val.into_raw_sync() } } -impl From> for Raw -where - E::EventType: Serialize, -{ +impl From> for Raw { fn from(val: EventBuilder) -> Self { val.into_raw_timeline() } } -impl From> for TimelineEvent -where - E::EventType: Serialize, -{ +impl From> for TimelineEvent { fn from(val: EventBuilder) -> Self { val.into_event() } } -impl From> for Raw -where - E::EventType: Serialize, -{ +impl From> for Raw { fn from(val: EventBuilder) -> Self { Raw::new(&val.construct_json(false)).unwrap().cast() } } -impl From> for Raw -where - E::EventType: Serialize, -{ +impl From> for Raw { fn from(val: EventBuilder) -> Self { Raw::new(&val.construct_json(true)).unwrap().cast() } @@ -528,7 +510,7 @@ impl EventFactory { } /// Create an event from any event content. - pub fn event(&self, content: E) -> EventBuilder { + pub fn event(&self, content: E) -> EventBuilder { EventBuilder { sender: self.sender.clone(), is_ephemeral: false, @@ -698,7 +680,7 @@ impl EventFactory { /// Create a redacted event, with extra information in the unsigned section /// about the redaction itself. - pub fn redacted( + pub fn redacted( &self, redacter: &UserId, content: T, @@ -719,7 +701,7 @@ impl EventFactory { /// Create a redacted state event, with extra information in the unsigned /// section about the redaction itself. - pub fn redacted_state( + pub fn redacted_state( &self, redacter: &UserId, state_key: impl Into,