1//! Types for the [`m.room.tombstone`] event.
2//!
3//! [`m.room.tombstone`]: https://spec.matrix.org/latest/client-server-api/#mroomtombstone
45use ruma_common::OwnedRoomId;
6use ruma_macros::EventContent;
7use serde::{Deserialize, Serialize};
89use crate::{
10 EmptyStateKey, EventContent, PossiblyRedactedStateEventContent, StateEventType,
11 StaticEventContent,
12};
1314/// The content of an `m.room.tombstone` event.
15///
16/// A state event signifying that a room has been upgraded to a different room version, and that
17/// clients should go there.
18#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
19#[ruma_event(
20type = "m.room.tombstone",
21 kind = State,
22 state_key_type = EmptyStateKey,
23 custom_possibly_redacted,
24)]
25#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
26pub struct RoomTombstoneEventContent {
27/// A server-defined message.
28 ///
29 /// If the `compat-optional` feature is enabled, this field being absent in JSON will result
30 /// in an empty string instead of an error when deserializing.
31#[cfg_attr(feature = "compat-optional", serde(default))]
32pub body: String,
3334/// The new room the client should be visiting.
35pub replacement_room: OwnedRoomId,
36}
3738impl RoomTombstoneEventContent {
39/// Creates a new `RoomTombstoneEventContent` with the given body and replacement room ID.
40pub fn new(body: String, replacement_room: OwnedRoomId) -> Self {
41Self { body, replacement_room }
42 }
43}
4445/// The possibly redacted form of [`RoomTombstoneEventContent`].
46///
47/// This type is used when it's not obvious whether the content is redacted or not.
48#[derive(Clone, Debug, Deserialize, Serialize)]
49#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
50pub struct PossiblyRedactedRoomTombstoneEventContent {
51/// A server-defined message.
52pub body: Option<String>,
5354/// The new room the client should be visiting.
55pub replacement_room: Option<OwnedRoomId>,
56}
5758impl EventContent for PossiblyRedactedRoomTombstoneEventContent {
59type EventType = StateEventType;
6061fn event_type(&self) -> Self::EventType {
62 StateEventType::RoomTombstone
63 }
64}
6566impl PossiblyRedactedStateEventContent for PossiblyRedactedRoomTombstoneEventContent {
67type StateKey = EmptyStateKey;
68}
6970impl StaticEventContent for PossiblyRedactedRoomTombstoneEventContent {
71const TYPE: &'static str = "m.room.tombstone";
72}