use ruma_common::{
EventEncryptionAlgorithm, OwnedDeviceId, OwnedRoomId, OwnedTransactionId, serde::StringEnum,
};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::PrivOwnedStr;
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
#[ruma_event(type = "m.room_key_request", kind = ToDevice)]
pub struct ToDeviceRoomKeyRequestEventContent {
pub action: Action,
pub body: Option<RequestedKeyInfo>,
pub requesting_device_id: OwnedDeviceId,
pub request_id: OwnedTransactionId,
}
impl ToDeviceRoomKeyRequestEventContent {
pub fn new(
action: Action,
body: Option<RequestedKeyInfo>,
requesting_device_id: OwnedDeviceId,
request_id: OwnedTransactionId,
) -> Self {
Self { action, body, requesting_device_id, request_id }
}
}
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Action {
Request,
#[ruma_enum(rename = "request_cancellation")]
CancelRequest,
#[doc(hidden)]
_Custom(PrivOwnedStr),
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct RequestedKeyInfo {
pub algorithm: EventEncryptionAlgorithm,
pub room_id: OwnedRoomId,
#[deprecated = "Since Matrix 1.3, this field should still be sent but should not be used when received"]
#[serde(skip_serializing_if = "Option::is_none")]
pub sender_key: Option<String>,
pub session_id: String,
}
impl RequestedKeyInfo {
pub fn new(
algorithm: EventEncryptionAlgorithm,
room_id: OwnedRoomId,
sender_key: String,
session_id: String,
) -> Self {
#[allow(deprecated)]
Self { algorithm, room_id, sender_key: Some(sender_key), session_id }
}
}