ruma_events/
encrypted.rs
1use ruma_macros::EventContent;
6use serde::{Deserialize, Serialize};
7
8use super::room::encrypted::{EncryptedEventScheme, Relation};
9
10#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
18#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
19#[ruma_event(type = "org.matrix.msc1767.encrypted", kind = MessageLike)]
20pub struct EncryptedEventContent {
21 #[serde(rename = "org.matrix.msc1767.encrypted")]
23 pub encrypted: EncryptedContentBlock,
24
25 #[serde(rename = "m.relates_to", skip_serializing_if = "Option::is_none")]
27 pub relates_to: Option<Relation>,
28}
29
30impl EncryptedEventContent {
31 pub fn new(scheme: EncryptedEventScheme, relates_to: Option<Relation>) -> Self {
33 Self { encrypted: scheme.into(), relates_to }
34 }
35}
36
37impl From<EncryptedEventScheme> for EncryptedEventContent {
38 fn from(scheme: EncryptedEventScheme) -> Self {
39 Self { encrypted: scheme.into(), relates_to: None }
40 }
41}
42
43#[derive(Clone, Debug, Deserialize, Serialize)]
45#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
46pub struct EncryptedContentBlock {
47 #[serde(flatten)]
49 pub scheme: EncryptedEventScheme,
50}
51
52impl From<EncryptedEventScheme> for EncryptedContentBlock {
53 fn from(scheme: EncryptedEventScheme) -> Self {
54 Self { scheme }
55 }
56}