ruma_events/room/
third_party_invite.rs

1//! Types for the [`m.room.third_party_invite`] event.
2//!
3//! [`m.room.third_party_invite`]: https://spec.matrix.org/latest/client-server-api/#mroomthird_party_invite
4
5use ruma_common::serde::Base64;
6use ruma_macros::EventContent;
7use serde::{Deserialize, Serialize};
8
9/// The content of an `m.room.third_party_invite` event.
10///
11/// An invitation to a room issued to a third party identifier, rather than a matrix user ID.
12///
13/// Acts as an `m.room.member` invite event, where there isn't a target user_id to invite. This
14/// event contains a token and a public key whose private key must be used to sign the token.
15/// Any user who can present that signature may use this invitation to join the target room.
16#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
17#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
18#[ruma_event(type = "m.room.third_party_invite", kind = State, state_key_type = String)]
19pub struct RoomThirdPartyInviteEventContent {
20    /// A user-readable string which represents the user who has been invited.
21    ///
22    /// If the `compat-optional` feature is enabled, this field being absent in JSON will result
23    /// in an empty string instead of an error when deserializing.
24    #[cfg_attr(feature = "compat-optional", serde(default))]
25    pub display_name: String,
26
27    /// A URL which can be fetched to validate whether the key has been revoked.
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 key_validity_url: String,
33
34    /// A base64-encoded Ed25519 key with which the token must be signed.
35    ///
36    /// If the `compat-optional` feature is enabled, this field being absent in JSON will result
37    /// in an empty string instead of an error when deserializing.
38    #[cfg_attr(feature = "compat-optional", serde(default = "Base64::empty"))]
39    pub public_key: Base64,
40
41    /// Keys with which the token may be signed.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub public_keys: Option<Vec<PublicKey>>,
44}
45
46impl RoomThirdPartyInviteEventContent {
47    /// Creates a new `RoomThirdPartyInviteEventContent` with the given display name, key validity
48    /// url and public key.
49    pub fn new(display_name: String, key_validity_url: String, public_key: Base64) -> Self {
50        Self { display_name, key_validity_url, public_key, public_keys: None }
51    }
52}
53
54/// A public key for signing a third party invite token.
55#[derive(Clone, Debug, Deserialize, Serialize)]
56#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
57pub struct PublicKey {
58    /// An optional URL which can be fetched to validate whether the key has been revoked.
59    ///
60    /// The URL must return a JSON object containing a boolean property named 'valid'.
61    /// If this URL is absent, the key must be considered valid indefinitely.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub key_validity_url: Option<String>,
64
65    /// A base64-encoded Ed25519 key with which the token must be signed.
66    pub public_key: Base64,
67}
68
69impl PublicKey {
70    /// Creates a new `PublicKey` with the given base64-encoded ed25519 key.
71    pub fn new(public_key: Base64) -> Self {
72        Self { key_validity_url: None, public_key }
73    }
74}