From 69337d1f4e4790a96c40377e895c0b1e44785e14 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 25 Jan 2023 16:38:07 +0100 Subject: [PATCH] events: Add custom PossiblyRedactedRoomTombstoneEventContent The auto-generated type would look different based on whether the compat feature is active or not previously. --- .../ruma-common/src/events/room/tombstone.rs | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/crates/ruma-common/src/events/room/tombstone.rs b/crates/ruma-common/src/events/room/tombstone.rs index 7e678129..75939a4d 100644 --- a/crates/ruma-common/src/events/room/tombstone.rs +++ b/crates/ruma-common/src/events/room/tombstone.rs @@ -5,14 +5,25 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::{events::EmptyStateKey, OwnedRoomId}; +use crate::{ + events::{ + EmptyStateKey, EventContent, PossiblyRedactedStateEventContent, StateEventType, + StaticEventContent, + }, + OwnedRoomId, +}; /// The content of an `m.room.tombstone` event. /// /// A state event signifying that a room has been upgraded to a different room version, and that /// clients should go there. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.room.tombstone", kind = State, state_key_type = EmptyStateKey)] +#[ruma_event( + type = "m.room.tombstone", + kind = State, + state_key_type = EmptyStateKey, + custom_possibly_redacted, +)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct RoomTombstoneEventContent { /// A server-defined message. @@ -32,3 +43,32 @@ impl RoomTombstoneEventContent { Self { body, replacement_room } } } + +/// The possibly redacted form of [`RoomTombstoneEventContent`]. +/// +/// This type is used when it's not obvious whether the content is redacted or not. +#[derive(Clone, Debug, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] +pub struct PossiblyRedactedRoomTombstoneEventContent { + /// A server-defined message. + pub body: Option, + + /// The new room the client should be visiting. + pub replacement_room: Option, +} + +impl EventContent for PossiblyRedactedRoomTombstoneEventContent { + type EventType = StateEventType; + + fn event_type(&self) -> Self::EventType { + StateEventType::RoomTombstone + } +} + +impl PossiblyRedactedStateEventContent for PossiblyRedactedRoomTombstoneEventContent { + type StateKey = EmptyStateKey; +} + +impl StaticEventContent for PossiblyRedactedRoomTombstoneEventContent { + const TYPE: &'static str = "m.room.tombstone"; +}