use js_int::Int;
use ruma_identifiers::TransactionId;
use serde::{Deserialize, Serialize};
#[cfg(feature = "unstable-msc2675")]
use crate::relation::Relations;
use crate::room::redaction::SyncRoomRedactionEvent;
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Unsigned {
#[serde(skip_serializing_if = "Option::is_none")]
pub age: Option<Int>,
#[serde(skip_serializing_if = "Option::is_none")]
pub transaction_id: Option<Box<TransactionId>>,
#[cfg(feature = "unstable-msc2675")]
#[serde(rename = "m.relations", skip_serializing_if = "Option::is_none")]
pub relations: Option<Relations>,
}
impl Unsigned {
pub fn new() -> Self {
Self::default()
}
pub fn is_empty(&self) -> bool {
#[cfg(not(feature = "unstable-msc2675"))]
{
self.age.is_none() && self.transaction_id.is_none()
}
#[cfg(feature = "unstable-msc2675")]
{
self.age.is_none() && self.transaction_id.is_none() && self.relations.is_none()
}
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct RedactedUnsigned {
#[serde(skip_serializing_if = "Option::is_none")]
pub redacted_because: Option<Box<SyncRoomRedactionEvent>>,
}
impl RedactedUnsigned {
pub fn new() -> Self {
Self::default()
}
pub fn new_because(redacted_because: Box<SyncRoomRedactionEvent>) -> Self {
Self { redacted_because: Some(redacted_because) }
}
pub fn is_empty(&self) -> bool {
self.redacted_because.is_none()
}
}
#[doc(hidden)]
#[cfg(feature = "compat")]
#[derive(Deserialize)]
pub struct UnsignedWithPrevContent {
#[serde(skip_serializing_if = "Option::is_none")]
age: Option<Int>,
#[serde(skip_serializing_if = "Option::is_none")]
transaction_id: Option<Box<TransactionId>>,
#[cfg(feature = "unstable-msc2675")]
#[serde(rename = "m.relations", skip_serializing_if = "Option::is_none")]
relations: Option<Relations>,
pub prev_content: Option<Box<serde_json::value::RawValue>>,
}
#[cfg(feature = "compat")]
impl From<UnsignedWithPrevContent> for Unsigned {
fn from(u: UnsignedWithPrevContent) -> Self {
Self {
age: u.age,
transaction_id: u.transaction_id,
#[cfg(feature = "unstable-msc2675")]
relations: u.relations,
}
}
}
#[doc(hidden)]
#[cfg(feature = "compat")]
#[derive(Deserialize)]
pub struct RedactedUnsignedWithPrevContent {
#[serde(skip_serializing_if = "Option::is_none")]
redacted_because: Option<Box<SyncRoomRedactionEvent>>,
pub prev_content: Option<Box<serde_json::value::RawValue>>,
}
#[cfg(feature = "compat")]
impl From<RedactedUnsignedWithPrevContent> for RedactedUnsigned {
fn from(u: RedactedUnsignedWithPrevContent) -> Self {
Self { redacted_because: u.redacted_because }
}
}