ruma_events/room/
tombstone.rs

1//! Types for the [`m.room.tombstone`] event.
2//!
3//! [`m.room.tombstone`]: https://spec.matrix.org/latest/client-server-api/#mroomtombstone
4
5use ruma_common::OwnedRoomId;
6use ruma_macros::EventContent;
7use serde::{Deserialize, Serialize};
8
9use crate::{
10    EmptyStateKey, EventContent, PossiblyRedactedStateEventContent, StateEventType,
11    StaticEventContent,
12};
13
14/// 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(
20    type = "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))]
32    pub body: String,
33
34    /// The new room the client should be visiting.
35    pub replacement_room: OwnedRoomId,
36}
37
38impl RoomTombstoneEventContent {
39    /// Creates a new `RoomTombstoneEventContent` with the given body and replacement room ID.
40    pub fn new(body: String, replacement_room: OwnedRoomId) -> Self {
41        Self { body, replacement_room }
42    }
43}
44
45/// 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.
52    pub body: Option<String>,
53
54    /// The new room the client should be visiting.
55    pub replacement_room: Option<OwnedRoomId>,
56}
57
58impl EventContent for PossiblyRedactedRoomTombstoneEventContent {
59    type EventType = StateEventType;
60
61    fn event_type(&self) -> Self::EventType {
62        StateEventType::RoomTombstone
63    }
64}
65
66impl PossiblyRedactedStateEventContent for PossiblyRedactedRoomTombstoneEventContent {
67    type StateKey = EmptyStateKey;
68}
69
70impl StaticEventContent for PossiblyRedactedRoomTombstoneEventContent {
71    const TYPE: &'static str = "m.room.tombstone";
72}