ruma_events/secret/
send.rs

1//! Types for the [`m.secret.send`] event.
2//!
3//! [`m.secret.send`]: https://spec.matrix.org/latest/client-server-api/#msecretsend
4
5use std::fmt;
6
7use ruma_common::OwnedTransactionId;
8use ruma_macros::EventContent;
9use serde::{Deserialize, Serialize};
10
11/// The content of an `m.secret.send` event.
12///
13/// An event sent by a client to share a secret with another device, in response to an
14/// `m.secret.request` event.
15///
16/// It must be encrypted as an `m.room.encrypted` event, then sent as a to-device event.
17#[derive(Clone, Deserialize, Serialize, EventContent)]
18#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
19#[ruma_event(type = "m.secret.send", kind = ToDevice)]
20pub struct ToDeviceSecretSendEventContent {
21    /// The ID of the request that this is a response to.
22    pub request_id: OwnedTransactionId,
23
24    /// The contents of the secret.
25    pub secret: String,
26}
27
28impl ToDeviceSecretSendEventContent {
29    /// Creates a new `SecretSendEventContent` with the given request ID and secret.
30    pub fn new(request_id: OwnedTransactionId, secret: String) -> Self {
31        Self { request_id, secret }
32    }
33}
34
35impl fmt::Debug for ToDeviceSecretSendEventContent {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        f.debug_struct("ToDeviceSecretSendEventContent")
38            .field("request_id", &self.request_id)
39            .finish_non_exhaustive()
40    }
41}