refactor(tests): Allow converting EventBuilder to state

This commit is contained in:
Robin
2025-04-16 17:40:25 +02:00
committed by Damir Jelić
parent 6f683d3cde
commit 2c8e71e560

View File

@@ -57,8 +57,9 @@ use ruma::{
topic::RoomTopicEventContent,
},
typing::TypingEventContent,
AnySyncTimelineEvent, AnyTimelineEvent, BundledMessageLikeRelations, EventContent,
RedactedMessageLikeEventContent, RedactedStateEventContent,
AnyStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent,
BundledMessageLikeRelations, EventContent, RedactedMessageLikeEventContent,
RedactedStateEventContent, StateEventContent,
},
serde::Raw,
server_name, EventId, Int, MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId, OwnedMxcUri,
@@ -441,6 +442,24 @@ where
}
}
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnySyncStateEvent>
where
E::EventType: Serialize,
{
fn from(val: EventBuilder<E>) -> Self {
Raw::new(&val.construct_json(false)).unwrap().cast()
}
}
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnyStateEvent>
where
E::EventType: Serialize,
{
fn from(val: EventBuilder<E>) -> Self {
Raw::new(&val.construct_json(true)).unwrap().cast()
}
}
#[derive(Debug, Default)]
pub struct EventFactory {
next_ts: AtomicU64,