ruma_events/room/message/
key_verification_request.rs

1use ruma_common::{OwnedDeviceId, OwnedUserId};
2use serde::{Deserialize, Serialize};
3
4use super::FormattedBody;
5use crate::key::verification::VerificationMethod;
6
7/// The payload for a key verification request message.
8#[derive(Clone, Debug, Deserialize, Serialize)]
9#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
10#[serde(tag = "msgtype", rename = "m.key.verification.request")]
11pub struct KeyVerificationRequestEventContent {
12    /// A fallback message to alert users that their client does not support the key verification
13    /// framework.
14    ///
15    /// Clients that do support the key verification framework should hide the body and instead
16    /// present the user with an interface to accept or reject the key verification.
17    pub body: String,
18
19    /// Formatted form of the `body`.
20    ///
21    /// As with the `body`, clients that do support the key verification framework should hide the
22    /// formatted body and instead present the user with an interface to accept or reject the key
23    /// verification.
24    #[serde(flatten)]
25    pub formatted: Option<FormattedBody>,
26
27    /// The verification methods supported by the sender.
28    pub methods: Vec<VerificationMethod>,
29
30    /// The device ID which is initiating the request.
31    pub from_device: OwnedDeviceId,
32
33    /// The user ID which should receive the request.
34    ///
35    /// Users should only respond to verification requests if they are named in this field. Users
36    /// who are not named in this field and who did not send this event should ignore all other
37    /// events that have a `m.reference` relationship with this event.
38    pub to: OwnedUserId,
39}
40
41impl KeyVerificationRequestEventContent {
42    /// Creates a new `KeyVerificationRequestEventContent` with the given body, method, device
43    /// and user ID.
44    pub fn new(
45        body: String,
46        methods: Vec<VerificationMethod>,
47        from_device: OwnedDeviceId,
48        to: OwnedUserId,
49    ) -> Self {
50        Self { body, formatted: None, methods, from_device, to }
51    }
52}