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