use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::room::encrypted::{EncryptedEventScheme, Relation};
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "org.matrix.msc1767.encrypted", kind = MessageLike)]
pub struct EncryptedEventContent {
#[serde(rename = "org.matrix.msc1767.encrypted")]
pub encrypted: EncryptedContentBlock,
#[serde(rename = "m.relates_to", skip_serializing_if = "Option::is_none")]
pub relates_to: Option<Relation>,
}
impl EncryptedEventContent {
pub fn new(scheme: EncryptedEventScheme, relates_to: Option<Relation>) -> Self {
Self { encrypted: scheme.into(), relates_to }
}
}
impl From<EncryptedEventScheme> for EncryptedEventContent {
fn from(scheme: EncryptedEventScheme) -> Self {
Self { encrypted: scheme.into(), relates_to: None }
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct EncryptedContentBlock {
#[serde(flatten)]
pub scheme: EncryptedEventScheme,
}
impl From<EncryptedEventScheme> for EncryptedContentBlock {
fn from(scheme: EncryptedEventScheme) -> Self {
Self { scheme }
}
}