ruma_events/room/policy.rs
1//! Types for the [`m.room.policy`] event.
2//!
3//! [`m.room.policy`]: https://spec.matrix.org/v1.18/client-server-api/#mroompolicy
4
5use std::collections::BTreeMap;
6
7use ruma_common::{OwnedServerName, SigningKeyAlgorithm, serde::Base64};
8use ruma_macros::EventContent;
9use serde::{Deserialize, Serialize};
10
11use crate::EmptyStateKey;
12
13/// The content of an [`m.room.policy`] event.
14///
15/// A [Policy Server] configuration.
16///
17/// If invalid or not set, the room does not use a Policy Server.
18///
19/// [`m.room.policy`]: https://spec.matrix.org/v1.18/client-server-api/#mroompolicy
20/// [Policy Server]: https://spec.matrix.org/v1.18/client-server-api/#policy-servers
21#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
22#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
23#[ruma_event(type = "m.room.policy", kind = State, state_key_type = EmptyStateKey)]
24pub struct RoomPolicyEventContent {
25 /// The server name to use as a Policy Server.
26 ///
27 /// MUST have a joined user in the room.
28 pub via: OwnedServerName,
29
30 /// The public keys for the Policy Server.
31 ///
32 /// MUST contain at least `ed25519`.
33 pub public_keys: BTreeMap<SigningKeyAlgorithm, Base64>,
34}
35
36impl RoomPolicyEventContent {
37 /// Creates a new `RoomPolicyEventContent` with the given server name and ed25519 public key.
38 pub fn new(via: OwnedServerName, ed25519_public_key: Base64) -> Self {
39 Self { via, public_keys: [(SigningKeyAlgorithm::Ed25519, ed25519_public_key)].into() }
40 }
41}