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::{EmptyStateKey, PossiblyRedactedStateEventContent, StateEventType, StaticEventContent};
10
11/// The content of an `m.room.tombstone` event.
12///
13/// A state event signifying that a room has been upgraded to a different room version, and that
14/// clients should go there.
15#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
16#[ruma_event(
17    type = "m.room.tombstone",
18    kind = State,
19    state_key_type = EmptyStateKey,
20    custom_possibly_redacted,
21)]
22#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
23pub struct RoomTombstoneEventContent {
24    /// A server-defined message.
25    ///
26    /// If the `compat-optional` feature is enabled, this field being absent in JSON will result
27    /// in an empty string instead of an error when deserializing.
28    #[cfg_attr(feature = "compat-optional", serde(default))]
29    pub body: String,
30
31    /// The new room the client should be visiting.
32    pub replacement_room: OwnedRoomId,
33}
34
35impl RoomTombstoneEventContent {
36    /// Creates a new `RoomTombstoneEventContent` with the given body and replacement room ID.
37    pub fn new(body: String, replacement_room: OwnedRoomId) -> Self {
38        Self { body, replacement_room }
39    }
40}
41
42/// The possibly redacted form of [`RoomTombstoneEventContent`].
43///
44/// This type is used when it's not obvious whether the content is redacted or not.
45#[derive(Clone, Debug, Deserialize, Serialize)]
46#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
47pub struct PossiblyRedactedRoomTombstoneEventContent {
48    /// A server-defined message.
49    pub body: Option<String>,
50
51    /// The new room the client should be visiting.
52    pub replacement_room: Option<OwnedRoomId>,
53}
54
55impl PossiblyRedactedStateEventContent for PossiblyRedactedRoomTombstoneEventContent {
56    type StateKey = EmptyStateKey;
57
58    fn event_type(&self) -> StateEventType {
59        StateEventType::RoomTombstone
60    }
61}
62
63impl StaticEventContent for PossiblyRedactedRoomTombstoneEventContent {
64    const TYPE: &'static str = RoomTombstoneEventContent::TYPE;
65    type IsPrefix = <RoomTombstoneEventContent as StaticEventContent>::IsPrefix;
66}