ruma_events/room/message/
key_verification_request.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use ruma_common::{OwnedDeviceId, OwnedUserId};
use serde::{Deserialize, Serialize};

use super::FormattedBody;
use crate::key::verification::VerificationMethod;

/// The payload for a key verification request message.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
#[serde(tag = "msgtype", rename = "m.key.verification.request")]
pub struct KeyVerificationRequestEventContent {
    /// A fallback message to alert users that their client does not support the key verification
    /// framework.
    ///
    /// Clients that do support the key verification framework should hide the body and instead
    /// present the user with an interface to accept or reject the key verification.
    pub body: String,

    /// Formatted form of the `body`.
    ///
    /// As with the `body`, clients that do support the key verification framework should hide the
    /// formatted body and instead present the user with an interface to accept or reject the key
    /// verification.
    #[serde(flatten)]
    pub formatted: Option<FormattedBody>,

    /// The verification methods supported by the sender.
    pub methods: Vec<VerificationMethod>,

    /// The device ID which is initiating the request.
    pub from_device: OwnedDeviceId,

    /// The user ID which should receive the request.
    ///
    /// Users should only respond to verification requests if they are named in this field. Users
    /// who are not named in this field and who did not send this event should ignore all other
    /// events that have a `m.reference` relationship with this event.
    pub to: OwnedUserId,
}

impl KeyVerificationRequestEventContent {
    /// Creates a new `KeyVerificationRequestEventContent` with the given body, method, device
    /// and user ID.
    pub fn new(
        body: String,
        methods: Vec<VerificationMethod>,
        from_device: OwnedDeviceId,
        to: OwnedUserId,
    ) -> Self {
        Self { body, formatted: None, methods, from_device, to }
    }
}