ruma_events/room/
history_visibility.rs

1//! Types for the [`m.room.history_visibility`] event.
2//!
3//! [`m.room.history_visibility`]: https://spec.matrix.org/latest/client-server-api/#mroomhistory_visibility
4
5use ruma_common::serde::StringEnum;
6use ruma_macros::EventContent;
7use serde::{Deserialize, Serialize};
8
9use crate::{EmptyStateKey, PrivOwnedStr};
10
11/// The content of an `m.room.history_visibility` event.
12///
13/// This event controls whether a member of a room can see the events that happened in a room from
14/// before they joined.
15#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
16#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
17#[ruma_event(type = "m.room.history_visibility", kind = State, state_key_type = EmptyStateKey)]
18pub struct RoomHistoryVisibilityEventContent {
19    /// Who can see the room history.
20    #[ruma_event(skip_redaction)]
21    pub history_visibility: HistoryVisibility,
22}
23
24impl RoomHistoryVisibilityEventContent {
25    /// Creates a new `RoomHistoryVisibilityEventContent` with the given policy.
26    pub fn new(history_visibility: HistoryVisibility) -> Self {
27        Self { history_visibility }
28    }
29}
30
31impl RoomHistoryVisibilityEvent {
32    /// Obtain the history visibility, regardless of whether this event is redacted.
33    pub fn history_visibility(&self) -> &HistoryVisibility {
34        match self {
35            Self::Original(ev) => &ev.content.history_visibility,
36            Self::Redacted(ev) => &ev.content.history_visibility,
37        }
38    }
39}
40
41impl SyncRoomHistoryVisibilityEvent {
42    /// Obtain the history visibility, regardless of whether this event is redacted.
43    pub fn history_visibility(&self) -> &HistoryVisibility {
44        match self {
45            Self::Original(ev) => &ev.content.history_visibility,
46            Self::Redacted(ev) => &ev.content.history_visibility,
47        }
48    }
49}
50
51/// Who can see a room's history.
52#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
53#[derive(Clone, PartialEq, Eq, StringEnum)]
54#[ruma_enum(rename_all = "snake_case")]
55#[non_exhaustive]
56pub enum HistoryVisibility {
57    /// Previous events are accessible to newly joined members from the point they were invited
58    /// onwards.
59    ///
60    /// Events stop being accessible when the member's state changes to something other than
61    /// *invite* or *join*.
62    Invited,
63
64    /// Previous events are accessible to newly joined members from the point they joined the room
65    /// onwards.
66    /// Events stop being accessible when the member's state changes to something other than
67    /// *join*.
68    Joined,
69
70    /// Previous events are always accessible to newly joined members.
71    ///
72    /// All events in the room are accessible, even those sent when the member was not a part of
73    /// the room.
74    Shared,
75
76    /// All events while this is the `HistoryVisibility` value may be shared by any participating
77    /// homeserver with anyone, regardless of whether they have ever joined the room.
78    WorldReadable,
79
80    #[doc(hidden)]
81    _Custom(PrivOwnedStr),
82}