events: Include all event type segments in Rust type names
This commit is contained in:
parent
4e4b71bcdd
commit
04080085f9
@ -1,7 +1,7 @@
|
|||||||
//! [GET /_matrix/client/r0/rooms/{roomId}/members](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-members)
|
//! [GET /_matrix/client/r0/rooms/{roomId}/members](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-members)
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_events::room::member::MemberEvent;
|
use ruma_events::room::member::RoomMemberEvent;
|
||||||
use ruma_identifiers::RoomId;
|
use ruma_identifiers::RoomId;
|
||||||
use ruma_serde::{Raw, StringEnum};
|
use ruma_serde::{Raw, StringEnum};
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ ruma_api! {
|
|||||||
|
|
||||||
response: {
|
response: {
|
||||||
/// A list of member events.
|
/// A list of member events.
|
||||||
pub chunk: Vec<Raw<MemberEvent>>,
|
pub chunk: Vec<Raw<RoomMemberEvent>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
error: crate::Error
|
error: crate::Error
|
||||||
@ -57,7 +57,7 @@ impl<'a> Request<'a> {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given member event chunk.
|
/// Creates a new `Response` with the given member event chunk.
|
||||||
pub fn new(chunk: Vec<Raw<MemberEvent>>) -> Self {
|
pub fn new(chunk: Vec<Raw<RoomMemberEvent>>) -> Self {
|
||||||
Self { chunk }
|
Self { chunk }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ use ruma_api::ruma_api;
|
|||||||
use ruma_events::room::create::RoomType;
|
use ruma_events::room::create::RoomType;
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::{
|
room::{
|
||||||
create::{CreateEventContent, PreviousRoom},
|
create::{PreviousRoom, RoomCreateEventContent},
|
||||||
power_levels::PowerLevelsEventContent,
|
power_levels::RoomPowerLevelsEventContent,
|
||||||
},
|
},
|
||||||
AnyInitialStateEvent,
|
AnyInitialStateEvent,
|
||||||
};
|
};
|
||||||
@ -61,7 +61,7 @@ ruma_api! {
|
|||||||
|
|
||||||
/// Power level content to override in the default power level event.
|
/// Power level content to override in the default power level event.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub power_level_content_override: Option<Raw<PowerLevelsEventContent>>,
|
pub power_level_content_override: Option<Raw<RoomPowerLevelsEventContent>>,
|
||||||
|
|
||||||
/// Convenience parameter for setting various default state events based on a preset.
|
/// Convenience parameter for setting various default state events based on a preset.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
@ -151,14 +151,14 @@ impl CreationContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Given a `CreationContent` and the other fields that a homeserver has to fill, construct
|
/// Given a `CreationContent` and the other fields that a homeserver has to fill, construct
|
||||||
/// a `CreateEventContent`.
|
/// a `RoomCreateEventContent`.
|
||||||
pub fn into_event_content(
|
pub fn into_event_content(
|
||||||
self,
|
self,
|
||||||
creator: UserId,
|
creator: UserId,
|
||||||
room_version: RoomVersionId,
|
room_version: RoomVersionId,
|
||||||
) -> CreateEventContent {
|
) -> RoomCreateEventContent {
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
let mut content = assign!(CreateEventContent::new(creator), {
|
let mut content = assign!(RoomCreateEventContent::new(creator), {
|
||||||
federate: self.federate,
|
federate: self.federate,
|
||||||
room_version: room_version,
|
room_version: room_version,
|
||||||
predecessor: self.predecessor,
|
predecessor: self.predecessor,
|
||||||
|
@ -458,7 +458,7 @@ fn expand_redact_event(
|
|||||||
|
|
||||||
fn redact(
|
fn redact(
|
||||||
self,
|
self,
|
||||||
redaction: #ruma_events::room::redaction::SyncRedactionEvent,
|
redaction: #ruma_events::room::redaction::SyncRoomRedactionEvent,
|
||||||
version: &#ruma_identifiers::RoomVersionId,
|
version: &#ruma_identifiers::RoomVersionId,
|
||||||
) -> Self::Redacted {
|
) -> Self::Redacted {
|
||||||
let content = #ruma_events::RedactContent::redact(self.content, version);
|
let content = #ruma_events::RedactContent::redact(self.content, version);
|
||||||
|
@ -332,7 +332,7 @@ fn generate_event_type_aliases(
|
|||||||
ruma_events: &TokenStream,
|
ruma_events: &TokenStream,
|
||||||
) -> syn::Result<TokenStream> {
|
) -> syn::Result<TokenStream> {
|
||||||
// The redaction module has its own event types.
|
// The redaction module has its own event types.
|
||||||
if ident == "RedactionEventContent" {
|
if ident == "RoomRedactionEventContent" {
|
||||||
return Ok(quote! {});
|
return Ok(quote! {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,7 +394,7 @@ fn generate_marker_trait_impl(
|
|||||||
EventKind::Message => quote! { MessageEventContent },
|
EventKind::Message => quote! { MessageEventContent },
|
||||||
EventKind::State => quote! { StateEventContent },
|
EventKind::State => quote! { StateEventContent },
|
||||||
EventKind::ToDevice => quote! { ToDeviceEventContent },
|
EventKind::ToDevice => quote! { ToDeviceEventContent },
|
||||||
EventKind::Redaction | EventKind::Presence | EventKind::Decrypted => {
|
EventKind::RoomRedaction | EventKind::Presence | EventKind::Decrypted => {
|
||||||
return Err(syn::Error::new_spanned(
|
return Err(syn::Error::new_spanned(
|
||||||
ident,
|
ident,
|
||||||
"valid event kinds are GlobalAccountData, RoomAccountData, \
|
"valid event kinds are GlobalAccountData, RoomAccountData, \
|
||||||
@ -454,7 +454,7 @@ fn generate_static_event_content_impl(
|
|||||||
EventKind::Message => quote! { Message { redacted: #redacted } },
|
EventKind::Message => quote! { Message { redacted: #redacted } },
|
||||||
EventKind::State => quote! { State { redacted: #redacted } },
|
EventKind::State => quote! { State { redacted: #redacted } },
|
||||||
EventKind::ToDevice => quote! { ToDevice },
|
EventKind::ToDevice => quote! { ToDevice },
|
||||||
EventKind::Redaction | EventKind::Presence | EventKind::Decrypted => {
|
EventKind::RoomRedaction | EventKind::Presence | EventKind::Decrypted => {
|
||||||
unreachable!("not a valid event content kind")
|
unreachable!("not a valid event content kind")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -475,7 +475,7 @@ fn expand_redact(
|
|||||||
|
|
||||||
fn redact(
|
fn redact(
|
||||||
self,
|
self,
|
||||||
redaction: #ruma_events::room::redaction::SyncRedactionEvent,
|
redaction: #ruma_events::room::redaction::SyncRoomRedactionEvent,
|
||||||
version: &#ruma_identifiers::RoomVersionId,
|
version: &#ruma_identifiers::RoomVersionId,
|
||||||
) -> #redacted_enum {
|
) -> #redacted_enum {
|
||||||
match self {
|
match self {
|
||||||
@ -729,9 +729,8 @@ fn to_event_path(
|
|||||||
|
|
||||||
let path: Vec<_> = name[2..].split('.').collect();
|
let path: Vec<_> = name[2..].split('.').collect();
|
||||||
|
|
||||||
let event_str = path.last().unwrap();
|
let event: String = name[2..]
|
||||||
let event: String = event_str
|
.split(&['.', '_'] as &[char])
|
||||||
.split('_')
|
|
||||||
.map(|s| s.chars().next().unwrap().to_uppercase().to_string() + &s[1..])
|
.map(|s| s.chars().next().unwrap().to_uppercase().to_string() + &s[1..])
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -760,9 +759,8 @@ fn to_event_content_path(
|
|||||||
|
|
||||||
let path: Vec<_> = name[2..].split('.').collect();
|
let path: Vec<_> = name[2..].split('.').collect();
|
||||||
|
|
||||||
let event_str = path.last().unwrap();
|
let event: String = name[2..]
|
||||||
let event: String = event_str
|
.split(&['.', '_'] as &[char])
|
||||||
.split('_')
|
|
||||||
.map(|s| s.chars().next().unwrap().to_uppercase().to_string() + &s[1..])
|
.map(|s| s.chars().next().unwrap().to_uppercase().to_string() + &s[1..])
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ pub enum EventKind {
|
|||||||
Message,
|
Message,
|
||||||
State,
|
State,
|
||||||
ToDevice,
|
ToDevice,
|
||||||
Redaction,
|
RoomRedaction,
|
||||||
Presence,
|
Presence,
|
||||||
Decrypted,
|
Decrypted,
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ impl fmt::Display for EventKind {
|
|||||||
EventKind::Message => write!(f, "MessageEvent"),
|
EventKind::Message => write!(f, "MessageEvent"),
|
||||||
EventKind::State => write!(f, "StateEvent"),
|
EventKind::State => write!(f, "StateEvent"),
|
||||||
EventKind::ToDevice => write!(f, "ToDeviceEvent"),
|
EventKind::ToDevice => write!(f, "ToDeviceEvent"),
|
||||||
EventKind::Redaction => write!(f, "RedactionEvent"),
|
EventKind::RoomRedaction => write!(f, "RoomRedactionEvent"),
|
||||||
EventKind::Presence => write!(f, "PresenceEvent"),
|
EventKind::Presence => write!(f, "PresenceEvent"),
|
||||||
EventKind::Decrypted => unreachable!(),
|
EventKind::Decrypted => unreachable!(),
|
||||||
}
|
}
|
||||||
@ -133,10 +133,10 @@ impl EventKind {
|
|||||||
| (Self::State, V::Stripped)
|
| (Self::State, V::Stripped)
|
||||||
| (Self::State, V::Initial)
|
| (Self::State, V::Initial)
|
||||||
| (Self::Message, V::Redacted)
|
| (Self::Message, V::Redacted)
|
||||||
| (Self::Redaction, V::Redacted)
|
| (Self::RoomRedaction, V::Redacted)
|
||||||
| (Self::State, V::Redacted)
|
| (Self::State, V::Redacted)
|
||||||
| (Self::Message, V::RedactedSync)
|
| (Self::Message, V::RedactedSync)
|
||||||
| (Self::Redaction, V::RedactedSync)
|
| (Self::RoomRedaction, V::RedactedSync)
|
||||||
| (Self::State, V::RedactedSync) => Some(format_ident!("{}{}", var, self)),
|
| (Self::State, V::RedactedSync) => Some(format_ident!("{}{}", var, self)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
@ -203,11 +203,13 @@ pub fn to_kind_variation(ident: &Ident) -> Option<(EventKind, EventKindVariation
|
|||||||
"RedactedSyncStateEvent" => Some((EventKind::State, EventKindVariation::RedactedSync)),
|
"RedactedSyncStateEvent" => Some((EventKind::State, EventKindVariation::RedactedSync)),
|
||||||
"ToDeviceEvent" => Some((EventKind::ToDevice, EventKindVariation::Full)),
|
"ToDeviceEvent" => Some((EventKind::ToDevice, EventKindVariation::Full)),
|
||||||
"PresenceEvent" => Some((EventKind::Presence, EventKindVariation::Full)),
|
"PresenceEvent" => Some((EventKind::Presence, EventKindVariation::Full)),
|
||||||
"RedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Full)),
|
"RoomRedactionEvent" => Some((EventKind::RoomRedaction, EventKindVariation::Full)),
|
||||||
"SyncRedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Sync)),
|
"SyncRoomRedactionEvent" => Some((EventKind::RoomRedaction, EventKindVariation::Sync)),
|
||||||
"RedactedRedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Redacted)),
|
"RedactedRoomRedactionEvent" => {
|
||||||
"RedactedSyncRedactionEvent" => {
|
Some((EventKind::RoomRedaction, EventKindVariation::Redacted))
|
||||||
Some((EventKind::Redaction, EventKindVariation::RedactedSync))
|
}
|
||||||
|
"RedactedSyncRoomRedactionEvent" => {
|
||||||
|
Some((EventKind::RoomRedaction, EventKindVariation::RedactedSync))
|
||||||
}
|
}
|
||||||
"DecryptedOlmV1Event" | "DecryptedMegolmV1Event" => {
|
"DecryptedOlmV1Event" | "DecryptedMegolmV1Event" => {
|
||||||
Some((EventKind::Decrypted, EventKindVariation::Full))
|
Some((EventKind::Decrypted, EventKindVariation::Full))
|
||||||
|
@ -31,7 +31,7 @@ pub fn expand_event_type_enum(
|
|||||||
room.push(&event.events);
|
room.push(&event.events);
|
||||||
}
|
}
|
||||||
EventKind::ToDevice => to_device.push(&event.events),
|
EventKind::ToDevice => to_device.push(&event.events),
|
||||||
EventKind::Redaction | EventKind::Presence | EventKind::Decrypted => {}
|
EventKind::RoomRedaction | EventKind::Presence | EventKind::Decrypted => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let presence = vec![EventEnumEntry {
|
let presence = vec![EventEnumEntry {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#[cfg(feature = "criterion")]
|
#[cfg(feature = "criterion")]
|
||||||
use criterion::{criterion_group, criterion_main, Criterion};
|
use criterion::{criterion_group, criterion_main, Criterion};
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::power_levels::PowerLevelsEventContent, AnyRoomEvent, AnyStateEvent, StateEvent,
|
room::power_levels::RoomPowerLevelsEventContent, AnyRoomEvent, AnyStateEvent, StateEvent,
|
||||||
};
|
};
|
||||||
use ruma_serde::Raw;
|
use ruma_serde::Raw;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@ -75,9 +75,10 @@ fn deserialize_specific_event(c: &mut Criterion) {
|
|||||||
|
|
||||||
c.bench_function("deserialize to `StateEvent<PowerLevelsEventContent>`", |b| {
|
c.bench_function("deserialize to `StateEvent<PowerLevelsEventContent>`", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let _ =
|
let _ = serde_json::from_value::<StateEvent<RoomPowerLevelsEventContent>>(
|
||||||
serde_json::from_value::<StateEvent<PowerLevelsEventContent>>(json_data.clone())
|
json_data.clone(),
|
||||||
.unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ use super::SessionDescription;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.call.answer", kind = Message)]
|
#[ruma_event(type = "m.call.answer", kind = Message)]
|
||||||
pub struct AnswerEventContent {
|
pub struct CallAnswerEventContent {
|
||||||
/// The VoIP session description object. The session description type must be *answer*.
|
/// The VoIP session description object. The session description type must be *answer*.
|
||||||
pub answer: SessionDescription,
|
pub answer: SessionDescription,
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ pub struct AnswerEventContent {
|
|||||||
pub version: UInt,
|
pub version: UInt,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnswerEventContent {
|
impl CallAnswerEventContent {
|
||||||
/// Creates an `AnswerEventContent` with the given answer, call ID and VoIP version.
|
/// Creates an `AnswerEventContent` with the given answer, call ID and VoIP version.
|
||||||
pub fn new(answer: SessionDescription, call_id: String, version: UInt) -> Self {
|
pub fn new(answer: SessionDescription, call_id: String, version: UInt) -> Self {
|
||||||
Self { answer, call_id, version }
|
Self { answer, call_id, version }
|
||||||
|
@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.call.candidates", kind = Message)]
|
#[ruma_event(type = "m.call.candidates", kind = Message)]
|
||||||
pub struct CandidatesEventContent {
|
pub struct CallCandidatesEventContent {
|
||||||
/// The ID of the call this event relates to.
|
/// The ID of the call this event relates to.
|
||||||
pub call_id: String,
|
pub call_id: String,
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ pub struct CandidatesEventContent {
|
|||||||
pub version: UInt,
|
pub version: UInt,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CandidatesEventContent {
|
impl CallCandidatesEventContent {
|
||||||
/// Creates a new `CandidatesEventContent` with the given call id, candidate list and VoIP
|
/// Creates a new `CandidatesEventContent` with the given call id, candidate list and VoIP
|
||||||
/// version.
|
/// version.
|
||||||
pub fn new(call_id: String, candidates: Vec<Candidate>, version: UInt) -> Self {
|
pub fn new(call_id: String, candidates: Vec<Candidate>, version: UInt) -> Self {
|
||||||
|
@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.call.hangup", kind = Message)]
|
#[ruma_event(type = "m.call.hangup", kind = Message)]
|
||||||
pub struct HangupEventContent {
|
pub struct CallHangupEventContent {
|
||||||
/// The ID of the call this event relates to.
|
/// The ID of the call this event relates to.
|
||||||
pub call_id: String,
|
pub call_id: String,
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ pub struct HangupEventContent {
|
|||||||
pub reason: Option<Reason>,
|
pub reason: Option<Reason>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HangupEventContent {
|
impl CallHangupEventContent {
|
||||||
/// Creates a new `HangupEventContent` with the given call ID and VoIP version.
|
/// Creates a new `HangupEventContent` with the given call ID and VoIP version.
|
||||||
pub fn new(call_id: String, version: UInt) -> Self {
|
pub fn new(call_id: String, version: UInt) -> Self {
|
||||||
Self { call_id, version, reason: None }
|
Self { call_id, version, reason: None }
|
||||||
|
@ -12,7 +12,7 @@ use super::SessionDescription;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.call.invite", kind = Message)]
|
#[ruma_event(type = "m.call.invite", kind = Message)]
|
||||||
pub struct InviteEventContent {
|
pub struct CallInviteEventContent {
|
||||||
/// A unique identifier for the call.
|
/// A unique identifier for the call.
|
||||||
pub call_id: String,
|
pub call_id: String,
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ pub struct InviteEventContent {
|
|||||||
pub version: UInt,
|
pub version: UInt,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InviteEventContent {
|
impl CallInviteEventContent {
|
||||||
/// Creates a new `InviteEventContent` with the given call ID, lifetime and VoIP version.
|
/// Creates a new `InviteEventContent` with the given call ID, lifetime and VoIP version.
|
||||||
pub fn new(call_id: String, lifetime: UInt, offer: SessionDescription, version: UInt) -> Self {
|
pub fn new(call_id: String, lifetime: UInt, offer: SessionDescription, version: UInt) -> Self {
|
||||||
Self { call_id, lifetime, offer, version }
|
Self { call_id, lifetime, offer, version }
|
||||||
|
@ -4,7 +4,9 @@ use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
|
|||||||
use serde::{de, Deserialize, Serialize};
|
use serde::{de, Deserialize, Serialize};
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
use crate::{from_raw_json_value, room::redaction::SyncRedactionEvent, Redact, UnsignedDeHelper};
|
use crate::{
|
||||||
|
from_raw_json_value, room::redaction::SyncRoomRedactionEvent, Redact, UnsignedDeHelper,
|
||||||
|
};
|
||||||
|
|
||||||
event_enum! {
|
event_enum! {
|
||||||
/// Any global account data event.
|
/// Any global account data event.
|
||||||
@ -281,7 +283,7 @@ impl Redact for AnyRoomEvent {
|
|||||||
/// Redacts `self`, referencing the given event in `unsigned.redacted_because`.
|
/// Redacts `self`, referencing the given event in `unsigned.redacted_because`.
|
||||||
///
|
///
|
||||||
/// Does nothing for events that are already redacted.
|
/// Does nothing for events that are already redacted.
|
||||||
fn redact(self, redaction: SyncRedactionEvent, version: &RoomVersionId) -> Self::Redacted {
|
fn redact(self, redaction: SyncRoomRedactionEvent, version: &RoomVersionId) -> Self::Redacted {
|
||||||
match self {
|
match self {
|
||||||
Self::Message(ev) => Self::Redacted::Message(ev.redact(redaction, version)),
|
Self::Message(ev) => Self::Redacted::Message(ev.redact(redaction, version)),
|
||||||
Self::State(ev) => Self::Redacted::State(ev.redact(redaction, version)),
|
Self::State(ev) => Self::Redacted::State(ev.redact(redaction, version)),
|
||||||
@ -317,7 +319,7 @@ impl Redact for AnySyncRoomEvent {
|
|||||||
/// Redacts `self`, referencing the given event in `unsigned.redacted_because`.
|
/// Redacts `self`, referencing the given event in `unsigned.redacted_because`.
|
||||||
///
|
///
|
||||||
/// Does nothing for events that are already redacted.
|
/// Does nothing for events that are already redacted.
|
||||||
fn redact(self, redaction: SyncRedactionEvent, version: &RoomVersionId) -> Self::Redacted {
|
fn redact(self, redaction: SyncRoomRedactionEvent, version: &RoomVersionId) -> Self::Redacted {
|
||||||
match self {
|
match self {
|
||||||
Self::Message(ev) => Self::Redacted::Message(ev.redact(redaction, version)),
|
Self::Message(ev) => Self::Redacted::Message(ev.redact(redaction, version)),
|
||||||
Self::State(ev) => Self::Redacted::State(ev.redact(redaction, version)),
|
Self::State(ev) => Self::Redacted::State(ev.redact(redaction, version)),
|
||||||
@ -344,21 +346,22 @@ impl AnyMessageEventContent {
|
|||||||
pub fn relation(&self) -> Option<crate::room::encrypted::Relation> {
|
pub fn relation(&self) -> Option<crate::room::encrypted::Relation> {
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use crate::key::verification::{
|
use crate::key::verification::{
|
||||||
accept::AcceptEventContent, cancel::CancelEventContent, done::DoneEventContent,
|
accept::KeyVerificationAcceptEventContent, cancel::KeyVerificationCancelEventContent,
|
||||||
key::KeyEventContent, mac::MacEventContent, ready::ReadyEventContent,
|
done::KeyVerificationDoneEventContent, key::KeyVerificationKeyEventContent,
|
||||||
start::StartEventContent,
|
mac::KeyVerificationMacEventContent, ready::KeyVerificationReadyEventContent,
|
||||||
|
start::KeyVerificationStartEventContent,
|
||||||
};
|
};
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
AnyMessageEventContent::KeyVerificationReady(ReadyEventContent { relates_to, .. })
|
AnyMessageEventContent::KeyVerificationReady(KeyVerificationReadyEventContent { relates_to, .. })
|
||||||
| AnyMessageEventContent::KeyVerificationStart(StartEventContent { relates_to, .. })
|
| AnyMessageEventContent::KeyVerificationStart(KeyVerificationStartEventContent { relates_to, .. })
|
||||||
| AnyMessageEventContent::KeyVerificationCancel(CancelEventContent { relates_to, .. })
|
| AnyMessageEventContent::KeyVerificationCancel(KeyVerificationCancelEventContent { relates_to, .. })
|
||||||
| AnyMessageEventContent::KeyVerificationAccept(AcceptEventContent { relates_to, .. })
|
| AnyMessageEventContent::KeyVerificationAccept(KeyVerificationAcceptEventContent { relates_to, .. })
|
||||||
| AnyMessageEventContent::KeyVerificationKey(KeyEventContent { relates_to, .. })
|
| AnyMessageEventContent::KeyVerificationKey(KeyVerificationKeyEventContent { relates_to, .. })
|
||||||
| AnyMessageEventContent::KeyVerificationMac(MacEventContent { relates_to, .. })
|
| AnyMessageEventContent::KeyVerificationMac(KeyVerificationMacEventContent { relates_to, .. })
|
||||||
| AnyMessageEventContent::KeyVerificationDone(DoneEventContent { relates_to, .. }) => {
|
| AnyMessageEventContent::KeyVerificationDone(KeyVerificationDoneEventContent { relates_to, .. }) => {
|
||||||
Some(relates_to.clone().into())
|
Some(relates_to.clone().into())
|
||||||
},
|
},
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
@ -18,7 +18,7 @@ use super::{
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.accept", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.accept", kind = ToDevice)]
|
||||||
pub struct ToDeviceAcceptEventContent {
|
pub struct ToDeviceKeyVerificationAcceptEventContent {
|
||||||
/// An opaque identifier for the verification process.
|
/// An opaque identifier for the verification process.
|
||||||
///
|
///
|
||||||
/// Must be the same as the one used for the `m.key.verification.start` message.
|
/// Must be the same as the one used for the `m.key.verification.start` message.
|
||||||
@ -29,9 +29,9 @@ pub struct ToDeviceAcceptEventContent {
|
|||||||
pub method: AcceptMethod,
|
pub method: AcceptMethod,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToDeviceAcceptEventContent {
|
impl ToDeviceKeyVerificationAcceptEventContent {
|
||||||
/// Creates a new `ToDeviceAcceptEventContent` with the given transaction ID and method-specific
|
/// Creates a new `ToDeviceKeyVerificationAcceptEventContent` with the given transaction ID and
|
||||||
/// content.
|
/// method-specific content.
|
||||||
pub fn new(transaction_id: String, method: AcceptMethod) -> Self {
|
pub fn new(transaction_id: String, method: AcceptMethod) -> Self {
|
||||||
Self { transaction_id, method }
|
Self { transaction_id, method }
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ impl ToDeviceAcceptEventContent {
|
|||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct AcceptEventContent {
|
pub struct KeyVerificationAcceptEventContent {
|
||||||
/// The method specific content.
|
/// The method specific content.
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub method: AcceptMethod,
|
pub method: AcceptMethod,
|
||||||
@ -56,9 +56,9 @@ pub struct AcceptEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
impl AcceptEventContent {
|
impl KeyVerificationAcceptEventContent {
|
||||||
/// Creates a new `ToDeviceAcceptEventContent` with the given method-specific content and
|
/// Creates a new `ToDeviceKeyVerificationAcceptEventContent` with the given method-specific
|
||||||
/// relation.
|
/// content and relation.
|
||||||
pub fn new(method: AcceptMethod, relates_to: Relation) -> Self {
|
pub fn new(method: AcceptMethod, relates_to: Relation) -> Self {
|
||||||
Self { method, relates_to }
|
Self { method, relates_to }
|
||||||
}
|
}
|
||||||
@ -174,10 +174,10 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use super::AcceptEventContent;
|
use super::KeyVerificationAcceptEventContent;
|
||||||
use super::{
|
use super::{
|
||||||
AcceptMethod, HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, SasV1Content,
|
AcceptMethod, HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, SasV1Content,
|
||||||
ShortAuthenticationString, ToDeviceAcceptEventContent, _CustomContent,
|
ShortAuthenticationString, ToDeviceKeyVerificationAcceptEventContent, _CustomContent,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use crate::key::verification::Relation;
|
use crate::key::verification::Relation;
|
||||||
@ -185,7 +185,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization() {
|
fn serialization() {
|
||||||
let key_verification_accept_content = ToDeviceAcceptEventContent {
|
let key_verification_accept_content = ToDeviceKeyVerificationAcceptEventContent {
|
||||||
transaction_id: "456".into(),
|
transaction_id: "456".into(),
|
||||||
method: AcceptMethod::SasV1(SasV1Content {
|
method: AcceptMethod::SasV1(SasV1Content {
|
||||||
hash: HashAlgorithm::Sha256,
|
hash: HashAlgorithm::Sha256,
|
||||||
@ -229,7 +229,7 @@ mod tests {
|
|||||||
"type": "m.key.verification.accept"
|
"type": "m.key.verification.accept"
|
||||||
});
|
});
|
||||||
|
|
||||||
let key_verification_accept_content = ToDeviceAcceptEventContent {
|
let key_verification_accept_content = ToDeviceKeyVerificationAcceptEventContent {
|
||||||
transaction_id: "456".into(),
|
transaction_id: "456".into(),
|
||||||
method: AcceptMethod::_Custom(_CustomContent {
|
method: AcceptMethod::_Custom(_CustomContent {
|
||||||
method: "m.sas.custom".to_owned(),
|
method: "m.sas.custom".to_owned(),
|
||||||
@ -250,7 +250,7 @@ mod tests {
|
|||||||
fn in_room_serialization() {
|
fn in_room_serialization() {
|
||||||
let event_id = event_id!("$1598361704261elfgc:localhost");
|
let event_id = event_id!("$1598361704261elfgc:localhost");
|
||||||
|
|
||||||
let key_verification_accept_content = AcceptEventContent {
|
let key_verification_accept_content = KeyVerificationAcceptEventContent {
|
||||||
relates_to: Relation { event_id: event_id.clone() },
|
relates_to: Relation { event_id: event_id.clone() },
|
||||||
method: AcceptMethod::SasV1(SasV1Content {
|
method: AcceptMethod::SasV1(SasV1Content {
|
||||||
hash: HashAlgorithm::Sha256,
|
hash: HashAlgorithm::Sha256,
|
||||||
@ -291,8 +291,8 @@ mod tests {
|
|||||||
|
|
||||||
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
|
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<ToDeviceAcceptEventContent>(json).unwrap(),
|
from_json_value::<ToDeviceKeyVerificationAcceptEventContent>(json).unwrap(),
|
||||||
ToDeviceAcceptEventContent {
|
ToDeviceKeyVerificationAcceptEventContent {
|
||||||
transaction_id,
|
transaction_id,
|
||||||
method: AcceptMethod::SasV1(SasV1Content {
|
method: AcceptMethod::SasV1(SasV1Content {
|
||||||
commitment,
|
commitment,
|
||||||
@ -326,10 +326,10 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<ToDeviceEvent<ToDeviceAcceptEventContent>>(json).unwrap(),
|
from_json_value::<ToDeviceEvent<ToDeviceKeyVerificationAcceptEventContent>>(json).unwrap(),
|
||||||
ToDeviceEvent {
|
ToDeviceEvent {
|
||||||
sender,
|
sender,
|
||||||
content: ToDeviceAcceptEventContent {
|
content: ToDeviceKeyVerificationAcceptEventContent {
|
||||||
transaction_id,
|
transaction_id,
|
||||||
method: AcceptMethod::SasV1(SasV1Content {
|
method: AcceptMethod::SasV1(SasV1Content {
|
||||||
commitment,
|
commitment,
|
||||||
@ -362,10 +362,10 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<ToDeviceEvent<ToDeviceAcceptEventContent>>(json).unwrap(),
|
from_json_value::<ToDeviceEvent<ToDeviceKeyVerificationAcceptEventContent>>(json).unwrap(),
|
||||||
ToDeviceEvent {
|
ToDeviceEvent {
|
||||||
sender,
|
sender,
|
||||||
content: ToDeviceAcceptEventContent {
|
content: ToDeviceKeyVerificationAcceptEventContent {
|
||||||
transaction_id,
|
transaction_id,
|
||||||
method: AcceptMethod::_Custom(_CustomContent {
|
method: AcceptMethod::_Custom(_CustomContent {
|
||||||
method,
|
method,
|
||||||
@ -399,8 +399,8 @@ mod tests {
|
|||||||
|
|
||||||
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
|
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AcceptEventContent>(json).unwrap(),
|
from_json_value::<KeyVerificationAcceptEventContent>(json).unwrap(),
|
||||||
AcceptEventContent {
|
KeyVerificationAcceptEventContent {
|
||||||
relates_to: Relation {
|
relates_to: Relation {
|
||||||
event_id
|
event_id
|
||||||
},
|
},
|
||||||
|
@ -13,7 +13,7 @@ use super::Relation;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.cancel", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.cancel", kind = ToDevice)]
|
||||||
pub struct ToDeviceCancelEventContent {
|
pub struct ToDeviceKeyVerificationCancelEventContent {
|
||||||
/// The opaque identifier for the verification process/request.
|
/// The opaque identifier for the verification process/request.
|
||||||
pub transaction_id: String,
|
pub transaction_id: String,
|
||||||
|
|
||||||
@ -26,8 +26,9 @@ pub struct ToDeviceCancelEventContent {
|
|||||||
pub code: CancelCode,
|
pub code: CancelCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToDeviceCancelEventContent {
|
impl ToDeviceKeyVerificationCancelEventContent {
|
||||||
/// Creates a new `ToDeviceCancelEventContent` with the given transaction ID, reason and code.
|
/// Creates a new `ToDeviceKeyVerificationCancelEventContent` with the given transaction ID,
|
||||||
|
/// reason and code.
|
||||||
pub fn new(transaction_id: String, reason: String, code: CancelCode) -> Self {
|
pub fn new(transaction_id: String, reason: String, code: CancelCode) -> Self {
|
||||||
Self { transaction_id, reason, code }
|
Self { transaction_id, reason, code }
|
||||||
}
|
}
|
||||||
@ -41,7 +42,7 @@ impl ToDeviceCancelEventContent {
|
|||||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.cancel", kind = Message)]
|
#[ruma_event(type = "m.key.verification.cancel", kind = Message)]
|
||||||
pub struct CancelEventContent {
|
pub struct KeyVerificationCancelEventContent {
|
||||||
/// A human readable description of the `code`.
|
/// A human readable description of the `code`.
|
||||||
///
|
///
|
||||||
/// The client should only rely on this string if it does not understand the `code`.
|
/// The client should only rely on this string if it does not understand the `code`.
|
||||||
@ -56,8 +57,8 @@ pub struct CancelEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
impl CancelEventContent {
|
impl KeyVerificationCancelEventContent {
|
||||||
/// Creates a new `CancelEventContent` with the given reason, code and relation.
|
/// Creates a new `KeyVerificationCancelEventContent` with the given reason, code and relation.
|
||||||
pub fn new(reason: String, code: CancelCode, relates_to: Relation) -> Self {
|
pub fn new(reason: String, code: CancelCode, relates_to: Relation) -> Self {
|
||||||
Self { reason, code, relates_to }
|
Self { reason, code, relates_to }
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,15 @@ use super::Relation;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.done", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.done", kind = ToDevice)]
|
||||||
pub struct ToDeviceDoneEventContent {
|
pub struct ToDeviceKeyVerificationDoneEventContent {
|
||||||
/// An opaque identifier for the verification process.
|
/// An opaque identifier for the verification process.
|
||||||
///
|
///
|
||||||
/// Must be the same as the one used for the `m.key.verification.start` message.
|
/// Must be the same as the one used for the `m.key.verification.start` message.
|
||||||
pub transaction_id: String,
|
pub transaction_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToDeviceDoneEventContent {
|
impl ToDeviceKeyVerificationDoneEventContent {
|
||||||
/// Creates a new `ToDeviceDoneEventContent` with the given transaction ID.
|
/// Creates a new `ToDeviceKeyVerificationDoneEventContent` with the given transaction ID.
|
||||||
pub fn new(transaction_id: String) -> Self {
|
pub fn new(transaction_id: String) -> Self {
|
||||||
Self { transaction_id }
|
Self { transaction_id }
|
||||||
}
|
}
|
||||||
@ -31,14 +31,14 @@ impl ToDeviceDoneEventContent {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.done", kind = Message)]
|
#[ruma_event(type = "m.key.verification.done", kind = Message)]
|
||||||
pub struct DoneEventContent {
|
pub struct KeyVerificationDoneEventContent {
|
||||||
/// Relation signaling which verification request this event is responding to.
|
/// Relation signaling which verification request this event is responding to.
|
||||||
#[serde(rename = "m.relates_to")]
|
#[serde(rename = "m.relates_to")]
|
||||||
pub relates_to: Relation,
|
pub relates_to: Relation,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DoneEventContent {
|
impl KeyVerificationDoneEventContent {
|
||||||
/// Creates a new `DoneEventContent` with the given relation.
|
/// Creates a new `KeyVerificationDoneEventContent` with the given relation.
|
||||||
pub fn new(relates_to: Relation) -> Self {
|
pub fn new(relates_to: Relation) -> Self {
|
||||||
Self { relates_to }
|
Self { relates_to }
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ mod tests {
|
|||||||
use ruma_identifiers::event_id;
|
use ruma_identifiers::event_id;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::DoneEventContent;
|
use super::KeyVerificationDoneEventContent;
|
||||||
use crate::key::verification::Relation;
|
use crate::key::verification::Relation;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -64,7 +64,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let content = DoneEventContent { relates_to: Relation { event_id } };
|
let content = KeyVerificationDoneEventContent { relates_to: Relation { event_id } };
|
||||||
|
|
||||||
assert_eq!(to_json_value(&content).unwrap(), json_data);
|
assert_eq!(to_json_value(&content).unwrap(), json_data);
|
||||||
}
|
}
|
||||||
@ -81,8 +81,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<DoneEventContent>(json_data).unwrap(),
|
from_json_value::<KeyVerificationDoneEventContent>(json_data).unwrap(),
|
||||||
DoneEventContent {
|
KeyVerificationDoneEventContent {
|
||||||
relates_to: Relation {
|
relates_to: Relation {
|
||||||
event_id
|
event_id
|
||||||
},
|
},
|
||||||
|
@ -12,7 +12,7 @@ use super::Relation;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.key", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.key", kind = ToDevice)]
|
||||||
pub struct ToDeviceKeyEventContent {
|
pub struct ToDeviceKeyVerificationKeyEventContent {
|
||||||
/// An opaque identifier for the verification process.
|
/// An opaque identifier for the verification process.
|
||||||
///
|
///
|
||||||
/// Must be the same as the one used for the `m.key.verification.start` message.
|
/// Must be the same as the one used for the `m.key.verification.start` message.
|
||||||
@ -22,8 +22,9 @@ pub struct ToDeviceKeyEventContent {
|
|||||||
pub key: String,
|
pub key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToDeviceKeyEventContent {
|
impl ToDeviceKeyVerificationKeyEventContent {
|
||||||
/// Creates a new `ToDeviceKeyEventContent` with the given transaction ID and key.
|
/// Creates a new `ToDeviceKeyVerificationKeyEventContent` with the given transaction ID and
|
||||||
|
/// key.
|
||||||
pub fn new(transaction_id: String, key: String) -> Self {
|
pub fn new(transaction_id: String, key: String) -> Self {
|
||||||
Self { transaction_id, key }
|
Self { transaction_id, key }
|
||||||
}
|
}
|
||||||
@ -37,7 +38,7 @@ impl ToDeviceKeyEventContent {
|
|||||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.key", kind = Message)]
|
#[ruma_event(type = "m.key.verification.key", kind = Message)]
|
||||||
pub struct KeyEventContent {
|
pub struct KeyVerificationKeyEventContent {
|
||||||
/// The device's ephemeral public key, encoded as unpadded Base64.
|
/// The device's ephemeral public key, encoded as unpadded Base64.
|
||||||
pub key: String,
|
pub key: String,
|
||||||
|
|
||||||
@ -47,8 +48,8 @@ pub struct KeyEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
impl KeyEventContent {
|
impl KeyVerificationKeyEventContent {
|
||||||
/// Creates a new `KeyEventContent` with the given key and relation.
|
/// Creates a new `KeyVerificationKeyEventContent` with the given key and relation.
|
||||||
pub fn new(key: String, relates_to: Relation) -> Self {
|
pub fn new(key: String, relates_to: Relation) -> Self {
|
||||||
Self { key, relates_to }
|
Self { key, relates_to }
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ use super::Relation;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.mac", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.mac", kind = ToDevice)]
|
||||||
pub struct ToDeviceMacEventContent {
|
pub struct ToDeviceKeyVerificationMacEventContent {
|
||||||
/// An opaque identifier for the verification process.
|
/// An opaque identifier for the verification process.
|
||||||
///
|
///
|
||||||
/// Must be the same as the one used for the `m.key.verification.start` message.
|
/// Must be the same as the one used for the `m.key.verification.start` message.
|
||||||
@ -30,9 +30,9 @@ pub struct ToDeviceMacEventContent {
|
|||||||
pub keys: String,
|
pub keys: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToDeviceMacEventContent {
|
impl ToDeviceKeyVerificationMacEventContent {
|
||||||
/// Creates a new `ToDeviceMacEventContent` with the given transaction ID, key ID to MAC map and
|
/// Creates a new `ToDeviceKeyVerificationMacEventContent` with the given transaction ID, key ID
|
||||||
/// key MAC.
|
/// to MAC map and key MAC.
|
||||||
pub fn new(transaction_id: String, mac: BTreeMap<String, String>, keys: String) -> Self {
|
pub fn new(transaction_id: String, mac: BTreeMap<String, String>, keys: String) -> Self {
|
||||||
Self { transaction_id, mac, keys }
|
Self { transaction_id, mac, keys }
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ impl ToDeviceMacEventContent {
|
|||||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.mac", kind = Message)]
|
#[ruma_event(type = "m.key.verification.mac", kind = Message)]
|
||||||
pub struct MacEventContent {
|
pub struct KeyVerificationMacEventContent {
|
||||||
/// A map of the key ID to the MAC of the key, using the algorithm in the verification process.
|
/// A map of the key ID to the MAC of the key, using the algorithm in the verification process.
|
||||||
///
|
///
|
||||||
/// The MAC is encoded as unpadded Base64.
|
/// The MAC is encoded as unpadded Base64.
|
||||||
@ -62,8 +62,9 @@ pub struct MacEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
impl MacEventContent {
|
impl KeyVerificationMacEventContent {
|
||||||
/// Creates a new `MacEventContent` with the given key ID to MAC map, key MAC and relation.
|
/// Creates a new `KeyVerificationMacEventContent` with the given key ID to MAC map, key MAC and
|
||||||
|
/// relation.
|
||||||
pub fn new(mac: BTreeMap<String, String>, keys: String, relates_to: Relation) -> Self {
|
pub fn new(mac: BTreeMap<String, String>, keys: String, relates_to: Relation) -> Self {
|
||||||
Self { mac, keys, relates_to }
|
Self { mac, keys, relates_to }
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ use super::{Relation, VerificationMethod};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.ready", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.ready", kind = ToDevice)]
|
||||||
pub struct ToDeviceReadyEventContent {
|
pub struct ToDeviceKeyVerificationReadyEventContent {
|
||||||
/// The device ID which is initiating the request.
|
/// The device ID which is initiating the request.
|
||||||
pub from_device: DeviceIdBox,
|
pub from_device: DeviceIdBox,
|
||||||
|
|
||||||
@ -27,9 +27,9 @@ pub struct ToDeviceReadyEventContent {
|
|||||||
pub transaction_id: String,
|
pub transaction_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToDeviceReadyEventContent {
|
impl ToDeviceKeyVerificationReadyEventContent {
|
||||||
/// Creates a new `ToDeviceReadyEventContent` with the given device ID, verification methods and
|
/// Creates a new `ToDeviceKeyVerificationReadyEventContent` with the given device ID,
|
||||||
/// transaction ID.
|
/// verification methods and transaction ID.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
from_device: DeviceIdBox,
|
from_device: DeviceIdBox,
|
||||||
methods: Vec<VerificationMethod>,
|
methods: Vec<VerificationMethod>,
|
||||||
@ -45,7 +45,7 @@ impl ToDeviceReadyEventContent {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.ready", kind = Message)]
|
#[ruma_event(type = "m.key.verification.ready", kind = Message)]
|
||||||
pub struct ReadyEventContent {
|
pub struct KeyVerificationReadyEventContent {
|
||||||
/// The device ID which is initiating the request.
|
/// The device ID which is initiating the request.
|
||||||
pub from_device: DeviceIdBox,
|
pub from_device: DeviceIdBox,
|
||||||
|
|
||||||
@ -58,8 +58,9 @@ pub struct ReadyEventContent {
|
|||||||
pub relates_to: Relation,
|
pub relates_to: Relation,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReadyEventContent {
|
impl KeyVerificationReadyEventContent {
|
||||||
/// Creates a new `ReadyEventContent` with the given device ID, methods and relation.
|
/// Creates a new `KeyVerificationReadyEventContent` with the given device ID, methods and
|
||||||
|
/// relation.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
from_device: DeviceIdBox,
|
from_device: DeviceIdBox,
|
||||||
methods: Vec<VerificationMethod>,
|
methods: Vec<VerificationMethod>,
|
||||||
@ -75,7 +76,7 @@ mod tests {
|
|||||||
use ruma_identifiers::{event_id, DeviceIdBox};
|
use ruma_identifiers::{event_id, DeviceIdBox};
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{ReadyEventContent, ToDeviceReadyEventContent};
|
use super::{KeyVerificationReadyEventContent, ToDeviceKeyVerificationReadyEventContent};
|
||||||
use crate::key::verification::{Relation, VerificationMethod};
|
use crate::key::verification::{Relation, VerificationMethod};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -92,7 +93,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let content = ReadyEventContent {
|
let content = KeyVerificationReadyEventContent {
|
||||||
from_device: device.clone(),
|
from_device: device.clone(),
|
||||||
relates_to: Relation { event_id },
|
relates_to: Relation { event_id },
|
||||||
methods: vec![VerificationMethod::SasV1],
|
methods: vec![VerificationMethod::SasV1],
|
||||||
@ -106,7 +107,7 @@ mod tests {
|
|||||||
"transaction_id": "456",
|
"transaction_id": "456",
|
||||||
});
|
});
|
||||||
|
|
||||||
let content = ToDeviceReadyEventContent {
|
let content = ToDeviceKeyVerificationReadyEventContent {
|
||||||
from_device: device,
|
from_device: device,
|
||||||
transaction_id: "456".to_owned(),
|
transaction_id: "456".to_owned(),
|
||||||
methods: vec![VerificationMethod::SasV1],
|
methods: vec![VerificationMethod::SasV1],
|
||||||
@ -130,8 +131,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<ReadyEventContent>(json_data).unwrap(),
|
from_json_value::<KeyVerificationReadyEventContent>(json_data).unwrap(),
|
||||||
ReadyEventContent {
|
KeyVerificationReadyEventContent {
|
||||||
from_device,
|
from_device,
|
||||||
relates_to: Relation {
|
relates_to: Relation {
|
||||||
event_id
|
event_id
|
||||||
@ -149,8 +150,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<ToDeviceReadyEventContent>(json_data).unwrap(),
|
from_json_value::<ToDeviceKeyVerificationReadyEventContent>(json_data).unwrap(),
|
||||||
ToDeviceReadyEventContent {
|
ToDeviceKeyVerificationReadyEventContent {
|
||||||
from_device,
|
from_device,
|
||||||
transaction_id,
|
transaction_id,
|
||||||
methods,
|
methods,
|
||||||
|
@ -11,7 +11,7 @@ use super::VerificationMethod;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.request", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.request", kind = ToDevice)]
|
||||||
pub struct ToDeviceRequestEventContent {
|
pub struct ToDeviceKeyVerificationRequestEventContent {
|
||||||
/// The device ID which is initiating the request.
|
/// The device ID which is initiating the request.
|
||||||
pub from_device: DeviceIdBox,
|
pub from_device: DeviceIdBox,
|
||||||
|
|
||||||
@ -30,9 +30,9 @@ pub struct ToDeviceRequestEventContent {
|
|||||||
pub timestamp: MilliSecondsSinceUnixEpoch,
|
pub timestamp: MilliSecondsSinceUnixEpoch,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToDeviceRequestEventContent {
|
impl ToDeviceKeyVerificationRequestEventContent {
|
||||||
/// Creates a new `ToDeviceRequestEventContent` with the given device ID, transaction ID,
|
/// Creates a new `ToDeviceKeyVerificationRequestEventContent` with the given device ID,
|
||||||
/// methods and timestamp.
|
/// transaction ID, methods and timestamp.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
from_device: DeviceIdBox,
|
from_device: DeviceIdBox,
|
||||||
transaction_id: String,
|
transaction_id: String,
|
||||||
|
@ -19,7 +19,7 @@ use super::{
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.start", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.start", kind = ToDevice)]
|
||||||
pub struct ToDeviceStartEventContent {
|
pub struct ToDeviceKeyVerificationStartEventContent {
|
||||||
/// The device ID which is initiating the process.
|
/// The device ID which is initiating the process.
|
||||||
pub from_device: DeviceIdBox,
|
pub from_device: DeviceIdBox,
|
||||||
|
|
||||||
@ -35,9 +35,9 @@ pub struct ToDeviceStartEventContent {
|
|||||||
pub method: StartMethod,
|
pub method: StartMethod,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToDeviceStartEventContent {
|
impl ToDeviceKeyVerificationStartEventContent {
|
||||||
/// Creates a new `ToDeviceStartEventContent` with the given device ID, transaction ID and
|
/// Creates a new `ToDeviceKeyVerificationStartEventContent` with the given device ID,
|
||||||
/// method specific content.
|
/// transaction ID and method specific content.
|
||||||
pub fn new(from_device: DeviceIdBox, transaction_id: String, method: StartMethod) -> Self {
|
pub fn new(from_device: DeviceIdBox, transaction_id: String, method: StartMethod) -> Self {
|
||||||
Self { from_device, transaction_id, method }
|
Self { from_device, transaction_id, method }
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ impl ToDeviceStartEventContent {
|
|||||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.start", kind = Message)]
|
#[ruma_event(type = "m.key.verification.start", kind = Message)]
|
||||||
pub struct StartEventContent {
|
pub struct KeyVerificationStartEventContent {
|
||||||
/// The device ID which is initiating the process.
|
/// The device ID which is initiating the process.
|
||||||
pub from_device: DeviceIdBox,
|
pub from_device: DeviceIdBox,
|
||||||
|
|
||||||
@ -65,8 +65,9 @@ pub struct StartEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
impl StartEventContent {
|
impl KeyVerificationStartEventContent {
|
||||||
/// Creates a new `StartEventContent` with the given device ID, method and relation.
|
/// Creates a new `KeyVerificationStartEventContent` with the given device ID, method and
|
||||||
|
/// relation.
|
||||||
pub fn new(from_device: DeviceIdBox, method: StartMethod, relates_to: Relation) -> Self {
|
pub fn new(from_device: DeviceIdBox, method: StartMethod, relates_to: Relation) -> Self {
|
||||||
Self { from_device, method, relates_to }
|
Self { from_device, method, relates_to }
|
||||||
}
|
}
|
||||||
@ -209,18 +210,18 @@ mod tests {
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, SasV1Content,
|
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, SasV1Content,
|
||||||
SasV1ContentInit, ShortAuthenticationString, StartMethod, ToDeviceStartEventContent,
|
SasV1ContentInit, ShortAuthenticationString, StartMethod,
|
||||||
_CustomContent,
|
ToDeviceKeyVerificationStartEventContent, _CustomContent,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use super::{ReciprocateV1Content, StartEventContent};
|
use super::{KeyVerificationStartEventContent, ReciprocateV1Content};
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use crate::key::verification::Relation;
|
use crate::key::verification::Relation;
|
||||||
use crate::ToDeviceEvent;
|
use crate::ToDeviceEvent;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization() {
|
fn serialization() {
|
||||||
let key_verification_start_content = ToDeviceStartEventContent {
|
let key_verification_start_content = ToDeviceKeyVerificationStartEventContent {
|
||||||
from_device: "123".into(),
|
from_device: "123".into(),
|
||||||
transaction_id: "456".into(),
|
transaction_id: "456".into(),
|
||||||
method: StartMethod::SasV1(
|
method: StartMethod::SasV1(
|
||||||
@ -268,7 +269,7 @@ mod tests {
|
|||||||
"sender": sender
|
"sender": sender
|
||||||
});
|
});
|
||||||
|
|
||||||
let key_verification_start_content = ToDeviceStartEventContent {
|
let key_verification_start_content = ToDeviceKeyVerificationStartEventContent {
|
||||||
from_device: "123".into(),
|
from_device: "123".into(),
|
||||||
transaction_id: "456".into(),
|
transaction_id: "456".into(),
|
||||||
method: StartMethod::_Custom(_CustomContent {
|
method: StartMethod::_Custom(_CustomContent {
|
||||||
@ -288,7 +289,7 @@ mod tests {
|
|||||||
{
|
{
|
||||||
let secret = "This is a secret to everybody".to_owned();
|
let secret = "This is a secret to everybody".to_owned();
|
||||||
|
|
||||||
let key_verification_start_content = ToDeviceStartEventContent {
|
let key_verification_start_content = ToDeviceKeyVerificationStartEventContent {
|
||||||
from_device: "123".into(),
|
from_device: "123".into(),
|
||||||
transaction_id: "456".into(),
|
transaction_id: "456".into(),
|
||||||
method: StartMethod::ReciprocateV1(ReciprocateV1Content::new(secret.clone())),
|
method: StartMethod::ReciprocateV1(ReciprocateV1Content::new(secret.clone())),
|
||||||
@ -310,7 +311,7 @@ mod tests {
|
|||||||
fn in_room_serialization() {
|
fn in_room_serialization() {
|
||||||
let event_id = event_id!("$1598361704261elfgc:localhost");
|
let event_id = event_id!("$1598361704261elfgc:localhost");
|
||||||
|
|
||||||
let key_verification_start_content = StartEventContent {
|
let key_verification_start_content = KeyVerificationStartEventContent {
|
||||||
from_device: "123".into(),
|
from_device: "123".into(),
|
||||||
relates_to: Relation { event_id: event_id.clone() },
|
relates_to: Relation { event_id: event_id.clone() },
|
||||||
method: StartMethod::SasV1(
|
method: StartMethod::SasV1(
|
||||||
@ -341,7 +342,7 @@ mod tests {
|
|||||||
|
|
||||||
let secret = "This is a secret to everybody".to_owned();
|
let secret = "This is a secret to everybody".to_owned();
|
||||||
|
|
||||||
let key_verification_start_content = StartEventContent {
|
let key_verification_start_content = KeyVerificationStartEventContent {
|
||||||
from_device: "123".into(),
|
from_device: "123".into(),
|
||||||
relates_to: Relation { event_id: event_id.clone() },
|
relates_to: Relation { event_id: event_id.clone() },
|
||||||
method: StartMethod::ReciprocateV1(ReciprocateV1Content::new(secret.clone())),
|
method: StartMethod::ReciprocateV1(ReciprocateV1Content::new(secret.clone())),
|
||||||
@ -374,8 +375,8 @@ mod tests {
|
|||||||
|
|
||||||
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
|
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<ToDeviceStartEventContent>(json).unwrap(),
|
from_json_value::<ToDeviceKeyVerificationStartEventContent>(json).unwrap(),
|
||||||
ToDeviceStartEventContent {
|
ToDeviceKeyVerificationStartEventContent {
|
||||||
from_device,
|
from_device,
|
||||||
transaction_id,
|
transaction_id,
|
||||||
method: StartMethod::SasV1(SasV1Content {
|
method: StartMethod::SasV1(SasV1Content {
|
||||||
@ -409,10 +410,10 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<ToDeviceEvent<ToDeviceStartEventContent>>(json).unwrap(),
|
from_json_value::<ToDeviceEvent<ToDeviceKeyVerificationStartEventContent>>(json).unwrap(),
|
||||||
ToDeviceEvent {
|
ToDeviceEvent {
|
||||||
sender,
|
sender,
|
||||||
content: ToDeviceStartEventContent {
|
content: ToDeviceKeyVerificationStartEventContent {
|
||||||
from_device,
|
from_device,
|
||||||
transaction_id,
|
transaction_id,
|
||||||
method: StartMethod::SasV1(SasV1Content {
|
method: StartMethod::SasV1(SasV1Content {
|
||||||
@ -445,10 +446,10 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<ToDeviceEvent<ToDeviceStartEventContent>>(json).unwrap(),
|
from_json_value::<ToDeviceEvent<ToDeviceKeyVerificationStartEventContent>>(json).unwrap(),
|
||||||
ToDeviceEvent {
|
ToDeviceEvent {
|
||||||
sender,
|
sender,
|
||||||
content: ToDeviceStartEventContent {
|
content: ToDeviceKeyVerificationStartEventContent {
|
||||||
from_device,
|
from_device,
|
||||||
transaction_id,
|
transaction_id,
|
||||||
method: StartMethod::_Custom(_CustomContent { method, data })
|
method: StartMethod::_Custom(_CustomContent { method, data })
|
||||||
@ -474,10 +475,10 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<ToDeviceEvent<ToDeviceStartEventContent>>(json).unwrap(),
|
from_json_value::<ToDeviceEvent<ToDeviceKeyVerificationStartEventContent>>(json).unwrap(),
|
||||||
ToDeviceEvent {
|
ToDeviceEvent {
|
||||||
sender,
|
sender,
|
||||||
content: ToDeviceStartEventContent {
|
content: ToDeviceKeyVerificationStartEventContent {
|
||||||
from_device,
|
from_device,
|
||||||
transaction_id,
|
transaction_id,
|
||||||
method: StartMethod::ReciprocateV1(ReciprocateV1Content { secret }),
|
method: StartMethod::ReciprocateV1(ReciprocateV1Content { secret }),
|
||||||
@ -510,8 +511,8 @@ mod tests {
|
|||||||
|
|
||||||
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
|
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<StartEventContent>(json).unwrap(),
|
from_json_value::<KeyVerificationStartEventContent>(json).unwrap(),
|
||||||
StartEventContent {
|
KeyVerificationStartEventContent {
|
||||||
from_device,
|
from_device,
|
||||||
relates_to: Relation { event_id },
|
relates_to: Relation { event_id },
|
||||||
method: StartMethod::SasV1(SasV1Content {
|
method: StartMethod::SasV1(SasV1Content {
|
||||||
@ -539,8 +540,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<StartEventContent>(json).unwrap(),
|
from_json_value::<KeyVerificationStartEventContent>(json).unwrap(),
|
||||||
StartEventContent {
|
KeyVerificationStartEventContent {
|
||||||
from_device,
|
from_device,
|
||||||
relates_to: Relation { event_id },
|
relates_to: Relation { event_id },
|
||||||
method: StartMethod::ReciprocateV1(ReciprocateV1Content { secret }),
|
method: StartMethod::ReciprocateV1(ReciprocateV1Content { secret }),
|
||||||
|
@ -125,7 +125,7 @@ use serde::{
|
|||||||
};
|
};
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
use self::room::redaction::SyncRedactionEvent;
|
use self::room::redaction::SyncRoomRedactionEvent;
|
||||||
|
|
||||||
mod enums;
|
mod enums;
|
||||||
mod event_kinds;
|
mod event_kinds;
|
||||||
@ -220,7 +220,7 @@ pub trait Redact {
|
|||||||
///
|
///
|
||||||
/// A small number of events have room-version specific redaction behavior, so a version has to
|
/// A small number of events have room-version specific redaction behavior, so a version has to
|
||||||
/// be specified.
|
/// be specified.
|
||||||
fn redact(self, redaction: SyncRedactionEvent, version: &RoomVersionId) -> Self::Redacted;
|
fn redact(self, redaction: SyncRoomRedactionEvent, version: &RoomVersionId) -> Self::Redacted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait to define the behavior of redact an event's content object.
|
/// Trait to define the behavior of redact an event's content object.
|
||||||
|
@ -11,7 +11,7 @@ use crate::policy::rule::PolicyRuleEventContent;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
#[ruma_event(type = "m.policy.rule.room", kind = State)]
|
#[ruma_event(type = "m.policy.rule.room", kind = State)]
|
||||||
pub struct RoomEventContent(pub PolicyRuleEventContent);
|
pub struct PolicyRuleRoomEventContent(pub PolicyRuleEventContent);
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
@ -23,7 +23,7 @@ mod tests {
|
|||||||
use ruma_serde::Raw;
|
use ruma_serde::Raw;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{RoomEvent, RoomEventContent};
|
use super::{PolicyRuleRoomEvent, PolicyRuleRoomEventContent};
|
||||||
use crate::{
|
use crate::{
|
||||||
policy::rule::{PolicyRuleEventContent, Recommendation},
|
policy::rule::{PolicyRuleEventContent, Recommendation},
|
||||||
Unsigned,
|
Unsigned,
|
||||||
@ -31,7 +31,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization() {
|
fn serialization() {
|
||||||
let room_event = RoomEvent {
|
let room_event = PolicyRuleRoomEvent {
|
||||||
event_id: event_id!("$143273582443PhrSn:example.org"),
|
event_id: event_id!("$143273582443PhrSn:example.org"),
|
||||||
sender: user_id!("@example:example.org"),
|
sender: user_id!("@example:example.org"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(1_432_735_824_653_u64.try_into().unwrap()),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(1_432_735_824_653_u64.try_into().unwrap()),
|
||||||
@ -44,7 +44,7 @@ mod tests {
|
|||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
relations: None,
|
relations: None,
|
||||||
},
|
},
|
||||||
content: RoomEventContent(PolicyRuleEventContent {
|
content: PolicyRuleRoomEventContent(PolicyRuleEventContent {
|
||||||
entity: "#*:example.org".into(),
|
entity: "#*:example.org".into(),
|
||||||
reason: "undesirable content".into(),
|
reason: "undesirable content".into(),
|
||||||
recommendation: Recommendation::Ban,
|
recommendation: Recommendation::Ban,
|
||||||
@ -90,6 +90,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
assert!(from_json_value::<Raw<RoomEvent>>(json).unwrap().deserialize().is_ok());
|
assert!(from_json_value::<Raw<PolicyRuleRoomEvent>>(json).unwrap().deserialize().is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,4 @@ use crate::policy::rule::PolicyRuleEventContent;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
#[ruma_event(type = "m.policy.rule.server", kind = State)]
|
#[ruma_event(type = "m.policy.rule.server", kind = State)]
|
||||||
pub struct ServerEventContent(pub PolicyRuleEventContent);
|
pub struct PolicyRuleServerEventContent(pub PolicyRuleEventContent);
|
||||||
|
@ -11,4 +11,4 @@ use crate::policy::rule::PolicyRuleEventContent;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
#[ruma_event(type = "m.policy.rule.user", kind = State)]
|
#[ruma_event(type = "m.policy.rule.user", kind = State)]
|
||||||
pub struct UserEventContent(pub PolicyRuleEventContent);
|
pub struct PolicyRuleUserEventContent(pub PolicyRuleEventContent);
|
||||||
|
@ -16,22 +16,22 @@ use crate::{
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.aliases", kind = State, custom_redacted)]
|
#[ruma_event(type = "m.room.aliases", kind = State, custom_redacted)]
|
||||||
pub struct AliasesEventContent {
|
pub struct RoomAliasesEventContent {
|
||||||
/// A list of room aliases.
|
/// A list of room aliases.
|
||||||
pub aliases: Vec<RoomAliasId>,
|
pub aliases: Vec<RoomAliasId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AliasesEventContent {
|
impl RoomAliasesEventContent {
|
||||||
/// Create an `AliasesEventContent` from the given aliases.
|
/// Create an `RoomAliasesEventContent` from the given aliases.
|
||||||
pub fn new(aliases: Vec<RoomAliasId>) -> Self {
|
pub fn new(aliases: Vec<RoomAliasId>) -> Self {
|
||||||
Self { aliases }
|
Self { aliases }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RedactContent for AliasesEventContent {
|
impl RedactContent for RoomAliasesEventContent {
|
||||||
type Redacted = RedactedAliasesEventContent;
|
type Redacted = RedactedRoomAliasesEventContent;
|
||||||
|
|
||||||
fn redact(self, version: &RoomVersionId) -> RedactedAliasesEventContent {
|
fn redact(self, version: &RoomVersionId) -> RedactedRoomAliasesEventContent {
|
||||||
// We compare the long way to avoid pre version 6 behavior if/when
|
// We compare the long way to avoid pre version 6 behavior if/when
|
||||||
// a new room version is introduced.
|
// a new room version is introduced.
|
||||||
let aliases = match version {
|
let aliases = match version {
|
||||||
@ -43,14 +43,14 @@ impl RedactContent for AliasesEventContent {
|
|||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
RedactedAliasesEventContent { aliases }
|
RedactedRoomAliasesEventContent { aliases }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An aliases event that has been redacted.
|
/// An aliases event that has been redacted.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct RedactedAliasesEventContent {
|
pub struct RedactedRoomAliasesEventContent {
|
||||||
/// A list of room aliases.
|
/// A list of room aliases.
|
||||||
///
|
///
|
||||||
/// According to the Matrix spec version 1 redaction rules allowed this field to be
|
/// According to the Matrix spec version 1 redaction rules allowed this field to be
|
||||||
@ -58,7 +58,7 @@ pub struct RedactedAliasesEventContent {
|
|||||||
pub aliases: Option<Vec<RoomAliasId>>,
|
pub aliases: Option<Vec<RoomAliasId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RedactedAliasesEventContent {
|
impl RedactedRoomAliasesEventContent {
|
||||||
/// Create a `RedactedAliasesEventContent` with the given aliases.
|
/// Create a `RedactedAliasesEventContent` with the given aliases.
|
||||||
///
|
///
|
||||||
/// This is only valid for room version 5 and below.
|
/// This is only valid for room version 5 and below.
|
||||||
@ -74,7 +74,7 @@ impl RedactedAliasesEventContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventContent for RedactedAliasesEventContent {
|
impl EventContent for RedactedRoomAliasesEventContent {
|
||||||
fn event_type(&self) -> &str {
|
fn event_type(&self) -> &str {
|
||||||
"m.room.aliases"
|
"m.room.aliases"
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ impl EventContent for RedactedAliasesEventContent {
|
|||||||
|
|
||||||
// Since this redacted event has fields we leave the default `empty` method
|
// Since this redacted event has fields we leave the default `empty` method
|
||||||
// that will error if called.
|
// that will error if called.
|
||||||
impl RedactedEventContent for RedactedAliasesEventContent {
|
impl RedactedEventContent for RedactedRoomAliasesEventContent {
|
||||||
fn has_serialize_fields(&self) -> bool {
|
fn has_serialize_fields(&self) -> bool {
|
||||||
self.aliases.is_some()
|
self.aliases.is_some()
|
||||||
}
|
}
|
||||||
@ -103,4 +103,4 @@ impl RedactedEventContent for RedactedAliasesEventContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RedactedStateEventContent for RedactedAliasesEventContent {}
|
impl RedactedStateEventContent for RedactedRoomAliasesEventContent {}
|
||||||
|
@ -16,7 +16,7 @@ use super::ThumbnailInfo;
|
|||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[cfg_attr(feature = "unstable-pre-spec", derive(Default))]
|
#[cfg_attr(feature = "unstable-pre-spec", derive(Default))]
|
||||||
#[ruma_event(type = "m.room.avatar", kind = State)]
|
#[ruma_event(type = "m.room.avatar", kind = State)]
|
||||||
pub struct AvatarEventContent {
|
pub struct RoomAvatarEventContent {
|
||||||
/// Information about the avatar image.
|
/// Information about the avatar image.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub info: Option<Box<ImageInfo>>,
|
pub info: Option<Box<ImageInfo>>,
|
||||||
@ -34,8 +34,8 @@ pub struct AvatarEventContent {
|
|||||||
pub url: Option<MxcUri>,
|
pub url: Option<MxcUri>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AvatarEventContent {
|
impl RoomAvatarEventContent {
|
||||||
/// Create an `AvatarEventContent` from the given image URL.
|
/// Create an `RoomAvatarEventContent` from the given image URL.
|
||||||
///
|
///
|
||||||
/// With the `unstable-pre-spec` feature, this method takes no parameters.
|
/// With the `unstable-pre-spec` feature, this method takes no parameters.
|
||||||
#[cfg(not(feature = "unstable-pre-spec"))]
|
#[cfg(not(feature = "unstable-pre-spec"))]
|
||||||
@ -43,7 +43,7 @@ impl AvatarEventContent {
|
|||||||
Self { info: None, url }
|
Self { info: None, url }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an empty `AvatarEventContent`.
|
/// Create an empty `RoomAvatarEventContent`.
|
||||||
///
|
///
|
||||||
/// With the `unstable-pre-spec` feature, this method takes an `MxcUri`.
|
/// With the `unstable-pre-spec` feature, this method takes an `MxcUri`.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.canonical_alias", kind = State)]
|
#[ruma_event(type = "m.room.canonical_alias", kind = State)]
|
||||||
pub struct CanonicalAliasEventContent {
|
pub struct RoomCanonicalAliasEventContent {
|
||||||
/// The canonical alias.
|
/// The canonical alias.
|
||||||
///
|
///
|
||||||
/// Rooms with `alias: None` should be treated the same as a room
|
/// Rooms with `alias: None` should be treated the same as a room
|
||||||
@ -27,8 +27,8 @@ pub struct CanonicalAliasEventContent {
|
|||||||
pub alt_aliases: Vec<RoomAliasId>,
|
pub alt_aliases: Vec<RoomAliasId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CanonicalAliasEventContent {
|
impl RoomCanonicalAliasEventContent {
|
||||||
/// Creates an empty `CanonicalAliasEventContent`.
|
/// Creates an empty `RoomCanonicalAliasEventContent`.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { alias: None, alt_aliases: Vec::new() }
|
Self { alias: None, alt_aliases: Vec::new() }
|
||||||
}
|
}
|
||||||
@ -41,13 +41,13 @@ mod tests {
|
|||||||
use ruma_identifiers::{event_id, room_alias_id, room_id, user_id};
|
use ruma_identifiers::{event_id, room_alias_id, room_id, user_id};
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::CanonicalAliasEventContent;
|
use super::RoomCanonicalAliasEventContent;
|
||||||
use crate::{StateEvent, Unsigned};
|
use crate::{StateEvent, Unsigned};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization_with_optional_fields_as_none() {
|
fn serialization_with_optional_fields_as_none() {
|
||||||
let canonical_alias_event = StateEvent {
|
let canonical_alias_event = StateEvent {
|
||||||
content: CanonicalAliasEventContent {
|
content: RoomCanonicalAliasEventContent {
|
||||||
alias: Some(room_alias_id!("#somewhere:localhost")),
|
alias: Some(room_alias_id!("#somewhere:localhost")),
|
||||||
alt_aliases: Vec::new(),
|
alt_aliases: Vec::new(),
|
||||||
},
|
},
|
||||||
@ -89,7 +89,7 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_json_value::<StateEvent<CanonicalAliasEventContent>>(json_data)
|
from_json_value::<StateEvent<RoomCanonicalAliasEventContent>>(json_data)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.content
|
.content
|
||||||
.alias,
|
.alias,
|
||||||
@ -111,7 +111,7 @@ mod tests {
|
|||||||
"type": "m.room.canonical_alias"
|
"type": "m.room.canonical_alias"
|
||||||
});
|
});
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_json_value::<StateEvent<CanonicalAliasEventContent>>(json_data)
|
from_json_value::<StateEvent<RoomCanonicalAliasEventContent>>(json_data)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.content
|
.content
|
||||||
.alias,
|
.alias,
|
||||||
@ -133,7 +133,7 @@ mod tests {
|
|||||||
"type": "m.room.canonical_alias"
|
"type": "m.room.canonical_alias"
|
||||||
});
|
});
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_json_value::<StateEvent<CanonicalAliasEventContent>>(json_data)
|
from_json_value::<StateEvent<RoomCanonicalAliasEventContent>>(json_data)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.content
|
.content
|
||||||
.alias,
|
.alias,
|
||||||
@ -156,7 +156,7 @@ mod tests {
|
|||||||
"type": "m.room.canonical_alias"
|
"type": "m.room.canonical_alias"
|
||||||
});
|
});
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_json_value::<StateEvent<CanonicalAliasEventContent>>(json_data)
|
from_json_value::<StateEvent<RoomCanonicalAliasEventContent>>(json_data)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.content
|
.content
|
||||||
.alias,
|
.alias,
|
||||||
|
@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.create", kind = State)]
|
#[ruma_event(type = "m.room.create", kind = State)]
|
||||||
pub struct CreateEventContent {
|
pub struct RoomCreateEventContent {
|
||||||
/// The `user_id` of the room creator. This is set by the homeserver.
|
/// The `user_id` of the room creator. This is set by the homeserver.
|
||||||
#[ruma_event(skip_redaction)]
|
#[ruma_event(skip_redaction)]
|
||||||
pub creator: UserId,
|
pub creator: UserId,
|
||||||
@ -42,8 +42,8 @@ pub struct CreateEventContent {
|
|||||||
pub room_type: Option<RoomType>,
|
pub room_type: Option<RoomType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CreateEventContent {
|
impl RoomCreateEventContent {
|
||||||
/// Creates a new `CreateEventContent` with the given creator.
|
/// Creates a new `RoomCreateEventContent` with the given creator.
|
||||||
pub fn new(creator: UserId) -> Self {
|
pub fn new(creator: UserId) -> Self {
|
||||||
Self {
|
Self {
|
||||||
creator,
|
creator,
|
||||||
@ -107,14 +107,14 @@ mod tests {
|
|||||||
use ruma_identifiers::{user_id, RoomVersionId};
|
use ruma_identifiers::{user_id, RoomVersionId};
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::CreateEventContent;
|
use super::RoomCreateEventContent;
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use super::RoomType;
|
use super::RoomType;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization() {
|
fn serialization() {
|
||||||
let content = CreateEventContent {
|
let content = RoomCreateEventContent {
|
||||||
creator: user_id!("@carl:example.com"),
|
creator: user_id!("@carl:example.com"),
|
||||||
federate: false,
|
federate: false,
|
||||||
room_version: RoomVersionId::Version4,
|
room_version: RoomVersionId::Version4,
|
||||||
@ -135,7 +135,7 @@ mod tests {
|
|||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
#[test]
|
#[test]
|
||||||
fn space_serialization() {
|
fn space_serialization() {
|
||||||
let content = CreateEventContent {
|
let content = RoomCreateEventContent {
|
||||||
creator: user_id!("@carl:example.com"),
|
creator: user_id!("@carl:example.com"),
|
||||||
federate: false,
|
federate: false,
|
||||||
room_version: RoomVersionId::Version4,
|
room_version: RoomVersionId::Version4,
|
||||||
@ -162,8 +162,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<CreateEventContent>(json).unwrap(),
|
from_json_value::<RoomCreateEventContent>(json).unwrap(),
|
||||||
CreateEventContent {
|
RoomCreateEventContent {
|
||||||
creator,
|
creator,
|
||||||
federate: true,
|
federate: true,
|
||||||
room_version: RoomVersionId::Version4,
|
room_version: RoomVersionId::Version4,
|
||||||
@ -185,8 +185,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<CreateEventContent>(json).unwrap(),
|
from_json_value::<RoomCreateEventContent>(json).unwrap(),
|
||||||
CreateEventContent {
|
RoomCreateEventContent {
|
||||||
creator,
|
creator,
|
||||||
federate: true,
|
federate: true,
|
||||||
room_version: RoomVersionId::Version4,
|
room_version: RoomVersionId::Version4,
|
||||||
|
@ -19,7 +19,7 @@ mod relation_serde;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.encrypted", kind = Message, kind = ToDevice)]
|
#[ruma_event(type = "m.room.encrypted", kind = Message, kind = ToDevice)]
|
||||||
pub struct EncryptedEventContent {
|
pub struct RoomEncryptedEventContent {
|
||||||
/// Algorithm-specific fields.
|
/// Algorithm-specific fields.
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub scheme: EncryptedEventScheme,
|
pub scheme: EncryptedEventScheme,
|
||||||
@ -31,14 +31,14 @@ pub struct EncryptedEventContent {
|
|||||||
pub relates_to: Option<Relation>,
|
pub relates_to: Option<Relation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncryptedEventContent {
|
impl RoomEncryptedEventContent {
|
||||||
/// Creates a new `EncryptedEventContent` with the given scheme and relation.
|
/// Creates a new `RoomEncryptedEventContent` with the given scheme and relation.
|
||||||
pub fn new(scheme: EncryptedEventScheme, relates_to: Option<Relation>) -> Self {
|
pub fn new(scheme: EncryptedEventScheme, relates_to: Option<Relation>) -> Self {
|
||||||
Self { scheme, relates_to }
|
Self { scheme, relates_to }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<EncryptedEventScheme> for EncryptedEventContent {
|
impl From<EncryptedEventScheme> for RoomEncryptedEventContent {
|
||||||
fn from(scheme: EncryptedEventScheme) -> Self {
|
fn from(scheme: EncryptedEventScheme) -> Self {
|
||||||
Self { scheme, relates_to: None }
|
Self { scheme, relates_to: None }
|
||||||
}
|
}
|
||||||
@ -48,26 +48,26 @@ impl From<EncryptedEventScheme> for EncryptedEventContent {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.encrypted", kind = ToDevice)]
|
#[ruma_event(type = "m.room.encrypted", kind = ToDevice)]
|
||||||
pub struct ToDeviceEncryptedEventContent {
|
pub struct ToDeviceRoomEncryptedEventContent {
|
||||||
/// Algorithm-specific fields.
|
/// Algorithm-specific fields.
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub scheme: EncryptedEventScheme,
|
pub scheme: EncryptedEventScheme,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToDeviceEncryptedEventContent {
|
impl ToDeviceRoomEncryptedEventContent {
|
||||||
/// Creates a new `ToDeviceEncryptedEventContent` with the given scheme.
|
/// Creates a new `ToDeviceRoomEncryptedEventContent` with the given scheme.
|
||||||
pub fn new(scheme: EncryptedEventScheme) -> Self {
|
pub fn new(scheme: EncryptedEventScheme) -> Self {
|
||||||
Self { scheme }
|
Self { scheme }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<EncryptedEventScheme> for ToDeviceEncryptedEventContent {
|
impl From<EncryptedEventScheme> for ToDeviceRoomEncryptedEventContent {
|
||||||
fn from(scheme: EncryptedEventScheme) -> Self {
|
fn from(scheme: EncryptedEventScheme) -> Self {
|
||||||
Self { scheme }
|
Self { scheme }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The encryption scheme for `EncryptedEventContent`.
|
/// The encryption scheme for `RoomEncryptedEventContent`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[serde(tag = "algorithm")]
|
#[serde(tag = "algorithm")]
|
||||||
@ -288,13 +288,15 @@ mod tests {
|
|||||||
use ruma_serde::Raw;
|
use ruma_serde::Raw;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{EncryptedEventContent, EncryptedEventScheme, MegolmV1AesSha2Content, Relation};
|
use super::{
|
||||||
|
EncryptedEventScheme, MegolmV1AesSha2Content, Relation, RoomEncryptedEventContent,
|
||||||
|
};
|
||||||
use crate::room::message::InReplyTo;
|
use crate::room::message::InReplyTo;
|
||||||
use ruma_identifiers::event_id;
|
use ruma_identifiers::event_id;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization() {
|
fn serialization() {
|
||||||
let key_verification_start_content = EncryptedEventContent {
|
let key_verification_start_content = RoomEncryptedEventContent {
|
||||||
scheme: EncryptedEventScheme::MegolmV1AesSha2(MegolmV1AesSha2Content {
|
scheme: EncryptedEventScheme::MegolmV1AesSha2(MegolmV1AesSha2Content {
|
||||||
ciphertext: "ciphertext".into(),
|
ciphertext: "ciphertext".into(),
|
||||||
sender_key: "sender_key".into(),
|
sender_key: "sender_key".into(),
|
||||||
@ -337,7 +339,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let content: EncryptedEventContent = from_json_value(json_data).unwrap();
|
let content: RoomEncryptedEventContent = from_json_value(json_data).unwrap();
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
content.scheme,
|
content.scheme,
|
||||||
@ -371,7 +373,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
"algorithm": "m.olm.v1.curve25519-aes-sha2"
|
"algorithm": "m.olm.v1.curve25519-aes-sha2"
|
||||||
});
|
});
|
||||||
let content: EncryptedEventContent = from_json_value(json_data).unwrap();
|
let content: RoomEncryptedEventContent = from_json_value(json_data).unwrap();
|
||||||
|
|
||||||
match content.scheme {
|
match content.scheme {
|
||||||
EncryptedEventScheme::OlmV1Curve25519AesSha2(c) => {
|
EncryptedEventScheme::OlmV1Curve25519AesSha2(c) => {
|
||||||
@ -386,7 +388,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialization_failure() {
|
fn deserialization_failure() {
|
||||||
assert!(from_json_value::<Raw<EncryptedEventContent>>(
|
assert!(from_json_value::<Raw<RoomEncryptedEventContent>>(
|
||||||
json!({ "algorithm": "m.megolm.v1.aes-sha2" })
|
json!({ "algorithm": "m.megolm.v1.aes-sha2" })
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -12,7 +12,7 @@ use crate::EventEncryptionAlgorithm;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.encryption", kind = State)]
|
#[ruma_event(type = "m.room.encryption", kind = State)]
|
||||||
pub struct EncryptionEventContent {
|
pub struct RoomEncryptionEventContent {
|
||||||
/// The encryption algorithm to be used to encrypt messages sent in this room.
|
/// The encryption algorithm to be used to encrypt messages sent in this room.
|
||||||
///
|
///
|
||||||
/// Must be `m.megolm.v1.aes-sha2`.
|
/// Must be `m.megolm.v1.aes-sha2`.
|
||||||
@ -31,8 +31,8 @@ pub struct EncryptionEventContent {
|
|||||||
pub rotation_period_msgs: Option<UInt>,
|
pub rotation_period_msgs: Option<UInt>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncryptionEventContent {
|
impl RoomEncryptionEventContent {
|
||||||
/// Creates a new `EncryptionEventContent` with the given algorithm.
|
/// Creates a new `RoomEncryptionEventContent` with the given algorithm.
|
||||||
pub fn new(algorithm: EventEncryptionAlgorithm) -> Self {
|
pub fn new(algorithm: EventEncryptionAlgorithm) -> Self {
|
||||||
Self { algorithm, rotation_period_ms: None, rotation_period_msgs: None }
|
Self { algorithm, rotation_period_ms: None, rotation_period_msgs: None }
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,13 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.guest_access", kind = State)]
|
#[ruma_event(type = "m.room.guest_access", kind = State)]
|
||||||
pub struct GuestAccessEventContent {
|
pub struct RoomGuestAccessEventContent {
|
||||||
/// A policy for guest user access to a room.
|
/// A policy for guest user access to a room.
|
||||||
pub guest_access: GuestAccess,
|
pub guest_access: GuestAccess,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuestAccessEventContent {
|
impl RoomGuestAccessEventContent {
|
||||||
/// Creates a new `GuestAccessEventContent` with the given policy.
|
/// Creates a new `RoomGuestAccessEventContent` with the given policy.
|
||||||
pub fn new(guest_access: GuestAccess) -> Self {
|
pub fn new(guest_access: GuestAccess) -> Self {
|
||||||
Self { guest_access }
|
Self { guest_access }
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,14 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.history_visibility", kind = State)]
|
#[ruma_event(type = "m.room.history_visibility", kind = State)]
|
||||||
pub struct HistoryVisibilityEventContent {
|
pub struct RoomHistoryVisibilityEventContent {
|
||||||
/// Who can see the room history.
|
/// Who can see the room history.
|
||||||
#[ruma_event(skip_redaction)]
|
#[ruma_event(skip_redaction)]
|
||||||
pub history_visibility: HistoryVisibility,
|
pub history_visibility: HistoryVisibility,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HistoryVisibilityEventContent {
|
impl RoomHistoryVisibilityEventContent {
|
||||||
/// Creates a new `HistoryVisibilityEventContent` with the given policy.
|
/// Creates a new `RoomHistoryVisibilityEventContent` with the given policy.
|
||||||
pub fn new(history_visibility: HistoryVisibility) -> Self {
|
pub fn new(history_visibility: HistoryVisibility) -> Self {
|
||||||
Self { history_visibility }
|
Self { history_visibility }
|
||||||
}
|
}
|
||||||
|
@ -22,34 +22,34 @@ use std::collections::BTreeMap;
|
|||||||
#[derive(Clone, Debug, Serialize, EventContent)]
|
#[derive(Clone, Debug, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.join_rules", kind = State)]
|
#[ruma_event(type = "m.room.join_rules", kind = State)]
|
||||||
pub struct JoinRulesEventContent {
|
pub struct RoomJoinRulesEventContent {
|
||||||
/// The type of rules used for users wishing to join this room.
|
/// The type of rules used for users wishing to join this room.
|
||||||
#[ruma_event(skip_redaction)]
|
#[ruma_event(skip_redaction)]
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub join_rule: JoinRule,
|
pub join_rule: JoinRule,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JoinRulesEventContent {
|
impl RoomJoinRulesEventContent {
|
||||||
/// Creates a new `JoinRulesEventContent` with the given rule.
|
/// Creates a new `RoomJoinRulesEventContent` with the given rule.
|
||||||
pub fn new(join_rule: JoinRule) -> Self {
|
pub fn new(join_rule: JoinRule) -> Self {
|
||||||
Self { join_rule }
|
Self { join_rule }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `JoinRulesEventContent` with the restricted rule and the given set of allow
|
/// Creates a new `RoomJoinRulesEventContent` with the restricted rule and the given set of
|
||||||
/// rules.
|
/// allow rules.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
pub fn restricted(allow: Vec<AllowRule>) -> Self {
|
pub fn restricted(allow: Vec<AllowRule>) -> Self {
|
||||||
Self { join_rule: JoinRule::Restricted(Restricted::new(allow)) }
|
Self { join_rule: JoinRule::Restricted(Restricted::new(allow)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for JoinRulesEventContent {
|
impl<'de> Deserialize<'de> for RoomJoinRulesEventContent {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let join_rule = JoinRule::deserialize(deserializer)?;
|
let join_rule = JoinRule::deserialize(deserializer)?;
|
||||||
Ok(JoinRulesEventContent { join_rule })
|
Ok(RoomJoinRulesEventContent { join_rule })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,15 +241,15 @@ impl<'de> Deserialize<'de> for AllowRule {
|
|||||||
mod tests {
|
mod tests {
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use super::AllowRule;
|
use super::AllowRule;
|
||||||
use super::{JoinRule, JoinRulesEventContent};
|
use super::{JoinRule, RoomJoinRulesEventContent};
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use ruma_identifiers::room_id;
|
use ruma_identifiers::room_id;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize() {
|
fn deserialize() {
|
||||||
let json = r#"{"join_rule": "public"}"#;
|
let json = r#"{"join_rule": "public"}"#;
|
||||||
let event: JoinRulesEventContent = serde_json::from_str(json).unwrap();
|
let event: RoomJoinRulesEventContent = serde_json::from_str(json).unwrap();
|
||||||
assert!(matches!(event, JoinRulesEventContent { join_rule: JoinRule::Public }));
|
assert!(matches!(event, RoomJoinRulesEventContent { join_rule: JoinRule::Public }));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
@ -268,7 +268,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}"#;
|
}"#;
|
||||||
let event: JoinRulesEventContent = serde_json::from_str(json).unwrap();
|
let event: RoomJoinRulesEventContent = serde_json::from_str(json).unwrap();
|
||||||
match event.join_rule {
|
match event.join_rule {
|
||||||
JoinRule::Restricted(restricted) => assert_eq!(
|
JoinRule::Restricted(restricted) => assert_eq!(
|
||||||
restricted.allow,
|
restricted.allow,
|
||||||
|
@ -39,7 +39,7 @@ use crate::{StrippedStateEvent, SyncStateEvent};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.member", kind = State)]
|
#[ruma_event(type = "m.room.member", kind = State)]
|
||||||
pub struct MemberEventContent {
|
pub struct RoomMemberEventContent {
|
||||||
/// The avatar URL for this user, if any. This is added by the homeserver.
|
/// The avatar URL for this user, if any. This is added by the homeserver.
|
||||||
///
|
///
|
||||||
/// If you activate the `compat` feature, this field being an empty string in JSON will give
|
/// If you activate the `compat` feature, this field being an empty string in JSON will give
|
||||||
@ -95,8 +95,8 @@ pub struct MemberEventContent {
|
|||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemberEventContent {
|
impl RoomMemberEventContent {
|
||||||
/// Creates a new `MemberEventContent` with the given membership state.
|
/// Creates a new `RoomMemberEventContent` with the given membership state.
|
||||||
pub fn new(membership: MembershipState) -> Self {
|
pub fn new(membership: MembershipState) -> Self {
|
||||||
Self {
|
Self {
|
||||||
membership,
|
membership,
|
||||||
@ -246,11 +246,11 @@ pub enum MembershipChange {
|
|||||||
NotImplemented,
|
NotImplemented,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internal function so all `MemberEventContent` state event kinds can share the same
|
/// Internal function so all `RoomMemberEventContent` state event kinds can share the same
|
||||||
/// implementation.
|
/// implementation.
|
||||||
fn membership_change(
|
fn membership_change(
|
||||||
content: &MemberEventContent,
|
content: &RoomMemberEventContent,
|
||||||
prev_content: Option<&MemberEventContent>,
|
prev_content: Option<&RoomMemberEventContent>,
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
state_key: &str,
|
state_key: &str,
|
||||||
) -> MembershipChange {
|
) -> MembershipChange {
|
||||||
@ -260,7 +260,7 @@ fn membership_change(
|
|||||||
let prev_content = if let Some(prev_content) = &prev_content {
|
let prev_content = if let Some(prev_content) = &prev_content {
|
||||||
prev_content
|
prev_content
|
||||||
} else {
|
} else {
|
||||||
&MemberEventContent {
|
&RoomMemberEventContent {
|
||||||
avatar_url: None,
|
avatar_url: None,
|
||||||
displayname: None,
|
displayname: None,
|
||||||
is_direct: None,
|
is_direct: None,
|
||||||
@ -303,7 +303,7 @@ fn membership_change(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemberEvent {
|
impl RoomMemberEvent {
|
||||||
/// Helper function for membership change. Check [the specification][spec] for details.
|
/// Helper function for membership change. Check [the specification][spec] for details.
|
||||||
///
|
///
|
||||||
/// [spec]: https://matrix.org/docs/spec/client_server/r0.6.1#m-room-member
|
/// [spec]: https://matrix.org/docs/spec/client_server/r0.6.1#m-room-member
|
||||||
@ -312,7 +312,7 @@ impl MemberEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SyncStateEvent<MemberEventContent> {
|
impl SyncStateEvent<RoomMemberEventContent> {
|
||||||
/// Helper function for membership change. Check [the specification][spec] for details.
|
/// Helper function for membership change. Check [the specification][spec] for details.
|
||||||
///
|
///
|
||||||
/// [spec]: https://matrix.org/docs/spec/client_server/r0.6.1#m-room-member
|
/// [spec]: https://matrix.org/docs/spec/client_server/r0.6.1#m-room-member
|
||||||
@ -321,7 +321,7 @@ impl SyncStateEvent<MemberEventContent> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StrippedStateEvent<MemberEventContent> {
|
impl StrippedStateEvent<RoomMemberEventContent> {
|
||||||
/// Helper function for membership change. Check [the specification][spec] for details.
|
/// Helper function for membership change. Check [the specification][spec] for details.
|
||||||
///
|
///
|
||||||
/// [spec]: https://matrix.org/docs/spec/client_server/r0.6.1#m-room-member
|
/// [spec]: https://matrix.org/docs/spec/client_server/r0.6.1#m-room-member
|
||||||
@ -339,7 +339,7 @@ mod tests {
|
|||||||
use ruma_identifiers::{server_name, server_signing_key_id};
|
use ruma_identifiers::{server_name, server_signing_key_id};
|
||||||
use serde_json::{from_value as from_json_value, json};
|
use serde_json::{from_value as from_json_value, json};
|
||||||
|
|
||||||
use super::{MemberEventContent, MembershipState, SignedContent, ThirdPartyInvite};
|
use super::{MembershipState, RoomMemberEventContent, SignedContent, ThirdPartyInvite};
|
||||||
use crate::StateEvent;
|
use crate::StateEvent;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -357,9 +357,9 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<StateEvent<MemberEventContent>>(json).unwrap(),
|
from_json_value::<StateEvent<RoomMemberEventContent>>(json).unwrap(),
|
||||||
StateEvent {
|
StateEvent {
|
||||||
content: MemberEventContent {
|
content: RoomMemberEventContent {
|
||||||
avatar_url: None,
|
avatar_url: None,
|
||||||
displayname: None,
|
displayname: None,
|
||||||
is_direct: None,
|
is_direct: None,
|
||||||
@ -401,9 +401,9 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<StateEvent<MemberEventContent>>(json).unwrap(),
|
from_json_value::<StateEvent<RoomMemberEventContent>>(json).unwrap(),
|
||||||
StateEvent {
|
StateEvent {
|
||||||
content: MemberEventContent {
|
content: RoomMemberEventContent {
|
||||||
avatar_url: None,
|
avatar_url: None,
|
||||||
displayname: None,
|
displayname: None,
|
||||||
is_direct: None,
|
is_direct: None,
|
||||||
@ -417,7 +417,7 @@ mod tests {
|
|||||||
sender,
|
sender,
|
||||||
state_key,
|
state_key,
|
||||||
unsigned,
|
unsigned,
|
||||||
prev_content: Some(MemberEventContent {
|
prev_content: Some(RoomMemberEventContent {
|
||||||
avatar_url: None,
|
avatar_url: None,
|
||||||
displayname: None,
|
displayname: None,
|
||||||
is_direct: None,
|
is_direct: None,
|
||||||
@ -464,9 +464,9 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<StateEvent<MemberEventContent>>(json).unwrap(),
|
from_json_value::<StateEvent<RoomMemberEventContent>>(json).unwrap(),
|
||||||
StateEvent {
|
StateEvent {
|
||||||
content: MemberEventContent {
|
content: RoomMemberEventContent {
|
||||||
avatar_url: Some(avatar_url),
|
avatar_url: Some(avatar_url),
|
||||||
displayname: Some(displayname),
|
displayname: Some(displayname),
|
||||||
is_direct: Some(true),
|
is_direct: Some(true),
|
||||||
@ -536,9 +536,9 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<StateEvent<MemberEventContent>>(json).unwrap(),
|
from_json_value::<StateEvent<RoomMemberEventContent>>(json).unwrap(),
|
||||||
StateEvent {
|
StateEvent {
|
||||||
content: MemberEventContent {
|
content: RoomMemberEventContent {
|
||||||
avatar_url: None,
|
avatar_url: None,
|
||||||
displayname: None,
|
displayname: None,
|
||||||
is_direct: None,
|
is_direct: None,
|
||||||
@ -552,7 +552,7 @@ mod tests {
|
|||||||
sender,
|
sender,
|
||||||
state_key,
|
state_key,
|
||||||
unsigned,
|
unsigned,
|
||||||
prev_content: Some(MemberEventContent {
|
prev_content: Some(RoomMemberEventContent {
|
||||||
avatar_url: Some(avatar_url),
|
avatar_url: Some(avatar_url),
|
||||||
displayname: Some(displayname),
|
displayname: Some(displayname),
|
||||||
is_direct: Some(true),
|
is_direct: Some(true),
|
||||||
@ -583,7 +583,7 @@ mod tests {
|
|||||||
|
|
||||||
#[cfg(feature = "compat")]
|
#[cfg(feature = "compat")]
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<StateEvent<MemberEventContent>>(json!({
|
from_json_value::<StateEvent<RoomMemberEventContent>>(json!({
|
||||||
"type": "m.room.member",
|
"type": "m.room.member",
|
||||||
"content": {
|
"content": {
|
||||||
"membership": "join"
|
"membership": "join"
|
||||||
@ -613,7 +613,7 @@ mod tests {
|
|||||||
"state_key": "@alice:example.org"
|
"state_key": "@alice:example.org"
|
||||||
})).unwrap(),
|
})).unwrap(),
|
||||||
StateEvent {
|
StateEvent {
|
||||||
content: MemberEventContent {
|
content: RoomMemberEventContent {
|
||||||
avatar_url: None,
|
avatar_url: None,
|
||||||
displayname: None,
|
displayname: None,
|
||||||
is_direct: None,
|
is_direct: None,
|
||||||
@ -627,7 +627,7 @@ mod tests {
|
|||||||
sender,
|
sender,
|
||||||
state_key,
|
state_key,
|
||||||
unsigned,
|
unsigned,
|
||||||
prev_content: Some(MemberEventContent {
|
prev_content: Some(RoomMemberEventContent {
|
||||||
avatar_url: None,
|
avatar_url: None,
|
||||||
displayname: Some(displayname),
|
displayname: Some(displayname),
|
||||||
is_direct: Some(true),
|
is_direct: Some(true),
|
||||||
|
@ -28,7 +28,7 @@ mod relation_serde;
|
|||||||
#[derive(Clone, Debug, Serialize, EventContent)]
|
#[derive(Clone, Debug, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.message", kind = Message)]
|
#[ruma_event(type = "m.room.message", kind = Message)]
|
||||||
pub struct MessageEventContent {
|
pub struct RoomMessageEventContent {
|
||||||
/// A key which identifies the type of message being sent.
|
/// A key which identifies the type of message being sent.
|
||||||
///
|
///
|
||||||
/// This also holds the specific content of each message.
|
/// This also holds the specific content of each message.
|
||||||
@ -42,8 +42,8 @@ pub struct MessageEventContent {
|
|||||||
pub relates_to: Option<Relation>,
|
pub relates_to: Option<Relation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageEventContent {
|
impl RoomMessageEventContent {
|
||||||
/// Create a `MessageEventContent` with the given `MessageType`.
|
/// Create a `RoomMessageEventContent` with the given `MessageType`.
|
||||||
pub fn new(msgtype: MessageType) -> Self {
|
pub fn new(msgtype: MessageType) -> Self {
|
||||||
Self { msgtype, relates_to: None }
|
Self { msgtype, relates_to: None }
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ impl MessageEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a plain text reply to a message.
|
/// Creates a plain text reply to a message.
|
||||||
pub fn text_reply_plain(reply: impl Into<String>, original_message: &MessageEvent) -> Self {
|
pub fn text_reply_plain(reply: impl Into<String>, original_message: &RoomMessageEvent) -> Self {
|
||||||
let quoted = get_plain_quote_fallback(original_message);
|
let quoted = get_plain_quote_fallback(original_message);
|
||||||
|
|
||||||
let body = format!("{}\n\n{}", quoted, reply.into());
|
let body = format!("{}\n\n{}", quoted, reply.into());
|
||||||
@ -86,7 +86,7 @@ impl MessageEventContent {
|
|||||||
pub fn text_reply_html(
|
pub fn text_reply_html(
|
||||||
reply: impl Into<String>,
|
reply: impl Into<String>,
|
||||||
html_reply: impl Into<String>,
|
html_reply: impl Into<String>,
|
||||||
original_message: &MessageEvent,
|
original_message: &RoomMessageEvent,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let quoted = get_plain_quote_fallback(original_message);
|
let quoted = get_plain_quote_fallback(original_message);
|
||||||
let quoted_html = get_html_quote_fallback(original_message);
|
let quoted_html = get_html_quote_fallback(original_message);
|
||||||
@ -103,7 +103,10 @@ impl MessageEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a plain text notice reply to a message.
|
/// Creates a plain text notice reply to a message.
|
||||||
pub fn notice_reply_plain(reply: impl Into<String>, original_message: &MessageEvent) -> Self {
|
pub fn notice_reply_plain(
|
||||||
|
reply: impl Into<String>,
|
||||||
|
original_message: &RoomMessageEvent,
|
||||||
|
) -> Self {
|
||||||
let quoted = get_plain_quote_fallback(original_message);
|
let quoted = get_plain_quote_fallback(original_message);
|
||||||
|
|
||||||
let body = format!("{}\n\n{}", quoted, reply.into());
|
let body = format!("{}\n\n{}", quoted, reply.into());
|
||||||
@ -119,7 +122,7 @@ impl MessageEventContent {
|
|||||||
pub fn notice_reply_html(
|
pub fn notice_reply_html(
|
||||||
reply: impl Into<String>,
|
reply: impl Into<String>,
|
||||||
html_reply: impl Into<String>,
|
html_reply: impl Into<String>,
|
||||||
original_message: &MessageEvent,
|
original_message: &RoomMessageEvent,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let quoted = get_plain_quote_fallback(original_message);
|
let quoted = get_plain_quote_fallback(original_message);
|
||||||
let quoted_html = get_html_quote_fallback(original_message);
|
let quoted_html = get_html_quote_fallback(original_message);
|
||||||
@ -287,7 +290,7 @@ impl MessageType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<MessageType> for MessageEventContent {
|
impl From<MessageType> for RoomMessageEventContent {
|
||||||
fn from(msgtype: MessageType) -> Self {
|
fn from(msgtype: MessageType) -> Self {
|
||||||
Self::new(msgtype)
|
Self::new(msgtype)
|
||||||
}
|
}
|
||||||
@ -340,13 +343,13 @@ pub struct Replacement {
|
|||||||
pub event_id: EventId,
|
pub event_id: EventId,
|
||||||
|
|
||||||
/// New content.
|
/// New content.
|
||||||
pub new_content: Box<MessageEventContent>,
|
pub new_content: Box<RoomMessageEventContent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
impl Replacement {
|
impl Replacement {
|
||||||
/// Creates a new `Replacement` with the given event ID and new content.
|
/// Creates a new `Replacement` with the given event ID and new content.
|
||||||
pub fn new(event_id: EventId, new_content: Box<MessageEventContent>) -> Self {
|
pub fn new(event_id: EventId, new_content: Box<RoomMessageEventContent>) -> Self {
|
||||||
Self { event_id, new_content }
|
Self { event_id, new_content }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -377,13 +380,14 @@ pub struct AudioMessageEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AudioMessageEventContent {
|
impl AudioMessageEventContent {
|
||||||
/// Creates a new non-encrypted `AudioMessageEventContent` with the given body, url and optional
|
/// Creates a new non-encrypted `RoomAudioMessageEventContent` with the given body, url and
|
||||||
/// extra info.
|
/// optional extra info.
|
||||||
pub fn plain(body: String, url: MxcUri, info: Option<Box<AudioInfo>>) -> Self {
|
pub fn plain(body: String, url: MxcUri, info: Option<Box<AudioInfo>>) -> Self {
|
||||||
Self { body, url: Some(url), info, file: None }
|
Self { body, url: Some(url), info, file: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new encrypted `AudioMessageEventContent` with the given body and encrypted file.
|
/// Creates a new encrypted `RoomAudioMessageEventContent` with the given body and encrypted
|
||||||
|
/// file.
|
||||||
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
||||||
Self { body, url: None, info: None, file: Some(Box::new(file)) }
|
Self { body, url: None, info: None, file: Some(Box::new(file)) }
|
||||||
}
|
}
|
||||||
@ -478,13 +482,14 @@ pub struct FileMessageEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FileMessageEventContent {
|
impl FileMessageEventContent {
|
||||||
/// Creates a new non-encrypted `FileMessageEventContent` with the given body, url and optional
|
/// Creates a new non-encrypted `RoomFileMessageEventContent` with the given body, url and
|
||||||
/// extra info.
|
/// optional extra info.
|
||||||
pub fn plain(body: String, url: MxcUri, info: Option<Box<FileInfo>>) -> Self {
|
pub fn plain(body: String, url: MxcUri, info: Option<Box<FileInfo>>) -> Self {
|
||||||
Self { body, filename: None, url: Some(url), info, file: None }
|
Self { body, filename: None, url: Some(url), info, file: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new encrypted `FileMessageEventContent` with the given body and encrypted file.
|
/// Creates a new encrypted `RoomFileMessageEventContent` with the given body and encrypted
|
||||||
|
/// file.
|
||||||
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
||||||
Self { body, filename: None, url: None, info: None, file: Some(Box::new(file)) }
|
Self { body, filename: None, url: None, info: None, file: Some(Box::new(file)) }
|
||||||
}
|
}
|
||||||
@ -553,13 +558,14 @@ pub struct ImageMessageEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ImageMessageEventContent {
|
impl ImageMessageEventContent {
|
||||||
/// Creates a new non-encrypted `ImageMessageEventContent` with the given body, url and optional
|
/// Creates a new non-encrypted `RoomImageMessageEventContent` with the given body, url and
|
||||||
/// extra info.
|
/// optional extra info.
|
||||||
pub fn plain(body: String, url: MxcUri, info: Option<Box<ImageInfo>>) -> Self {
|
pub fn plain(body: String, url: MxcUri, info: Option<Box<ImageInfo>>) -> Self {
|
||||||
Self { body, url: Some(url), info, file: None }
|
Self { body, url: Some(url), info, file: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new encrypted `ImageMessageEventContent` with the given body and encrypted file.
|
/// Creates a new encrypted `RoomImageMessageEventContent` with the given body and encrypted
|
||||||
|
/// file.
|
||||||
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
||||||
Self { body, url: None, info: None, file: Some(Box::new(file)) }
|
Self { body, url: None, info: None, file: Some(Box::new(file)) }
|
||||||
}
|
}
|
||||||
@ -583,7 +589,7 @@ pub struct LocationMessageEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LocationMessageEventContent {
|
impl LocationMessageEventContent {
|
||||||
/// Creates a new `LocationMessageEventContent` with the given body and geo URI.
|
/// Creates a new `RoomLocationMessageEventContent` with the given body and geo URI.
|
||||||
pub fn new(body: String, geo_uri: String) -> Self {
|
pub fn new(body: String, geo_uri: String) -> Self {
|
||||||
Self { body, geo_uri, info: None }
|
Self { body, geo_uri, info: None }
|
||||||
}
|
}
|
||||||
@ -677,7 +683,7 @@ pub struct ServerNoticeMessageEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ServerNoticeMessageEventContent {
|
impl ServerNoticeMessageEventContent {
|
||||||
/// Creates a new `ServerNoticeMessageEventContent` with the given body and notice type.
|
/// Creates a new `RoomServerNoticeMessageEventContent` with the given body and notice type.
|
||||||
pub fn new(body: String, server_notice_type: ServerNoticeType) -> Self {
|
pub fn new(body: String, server_notice_type: ServerNoticeType) -> Self {
|
||||||
Self { body, server_notice_type, admin_contact: None, limit_type: None }
|
Self { body, server_notice_type, admin_contact: None, limit_type: None }
|
||||||
}
|
}
|
||||||
@ -846,13 +852,14 @@ pub struct VideoMessageEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl VideoMessageEventContent {
|
impl VideoMessageEventContent {
|
||||||
/// Creates a new non-encrypted `VideoMessageEventContent` with the given body, url and optional
|
/// Creates a new non-encrypted `RoomVideoMessageEventContent` with the given body, url and
|
||||||
/// extra info.
|
/// optional extra info.
|
||||||
pub fn plain(body: String, url: MxcUri, info: Option<Box<VideoInfo>>) -> Self {
|
pub fn plain(body: String, url: MxcUri, info: Option<Box<VideoInfo>>) -> Self {
|
||||||
Self { body, url: Some(url), info, file: None }
|
Self { body, url: Some(url), info, file: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new encrypted `VideoMessageEventContent` with the given body and encrypted file.
|
/// Creates a new encrypted `RoomVideoMessageEventContent` with the given body and encrypted
|
||||||
|
/// file.
|
||||||
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
||||||
Self { body, url: None, info: None, file: Some(Box::new(file)) }
|
Self { body, url: None, info: None, file: Some(Box::new(file)) }
|
||||||
}
|
}
|
||||||
@ -945,8 +952,8 @@ pub struct KeyVerificationRequestEventContent {
|
|||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
impl KeyVerificationRequestEventContent {
|
impl KeyVerificationRequestEventContent {
|
||||||
/// Creates a new `KeyVerificationRequestEventContent` with the given body, method, device and
|
/// Creates a new `RoomKeyVerificationRequestEventContent` with the given body, method, device
|
||||||
/// user ID.
|
/// and user ID.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
body: String,
|
body: String,
|
||||||
methods: Vec<VerificationMethod>,
|
methods: Vec<VerificationMethod>,
|
||||||
@ -972,7 +979,7 @@ pub struct CustomEventContent {
|
|||||||
data: JsonObject,
|
data: JsonObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_plain_quote_fallback(original_message: &MessageEvent) -> String {
|
fn get_plain_quote_fallback(original_message: &RoomMessageEvent) -> String {
|
||||||
match &original_message.content.msgtype {
|
match &original_message.content.msgtype {
|
||||||
MessageType::Audio(_) => {
|
MessageType::Audio(_) => {
|
||||||
format!("> <{:?}> sent an audio file.", original_message.sender)
|
format!("> <{:?}> sent an audio file.", original_message.sender)
|
||||||
@ -1013,7 +1020,7 @@ fn get_plain_quote_fallback(original_message: &MessageEvent) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::nonstandard_macro_braces)]
|
#[allow(clippy::nonstandard_macro_braces)]
|
||||||
fn get_html_quote_fallback(original_message: &MessageEvent) -> String {
|
fn get_html_quote_fallback(original_message: &RoomMessageEvent) -> String {
|
||||||
match &original_message.content.msgtype {
|
match &original_message.content.msgtype {
|
||||||
MessageType::Audio(_) => {
|
MessageType::Audio(_) => {
|
||||||
formatdoc!(
|
formatdoc!(
|
||||||
@ -1228,7 +1235,7 @@ mod tests {
|
|||||||
use ruma_identifiers::{event_id, EventId, RoomId, UserId};
|
use ruma_identifiers::{event_id, EventId, RoomId, UserId};
|
||||||
use serde_json::{from_value as from_json_value, json};
|
use serde_json::{from_value as from_json_value, json};
|
||||||
|
|
||||||
use super::{InReplyTo, MessageEvent, MessageEventContent, MessageType, Relation};
|
use super::{InReplyTo, MessageType, Relation, RoomMessageEvent, RoomMessageEventContent};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_reply() {
|
fn deserialize_reply() {
|
||||||
@ -1245,8 +1252,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<MessageEventContent>(json).unwrap(),
|
from_json_value::<RoomMessageEventContent>(json).unwrap(),
|
||||||
MessageEventContent {
|
RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(_),
|
msgtype: MessageType::Text(_),
|
||||||
relates_to: Some(Relation::Reply { in_reply_to: InReplyTo { event_id } }),
|
relates_to: Some(Relation::Reply { in_reply_to: InReplyTo { event_id } }),
|
||||||
} if event_id == ev_id
|
} if event_id == ev_id
|
||||||
@ -1257,8 +1264,8 @@ mod tests {
|
|||||||
fn plain_quote_fallback_multiline() {
|
fn plain_quote_fallback_multiline() {
|
||||||
let sender = UserId::try_from("@alice:example.com").unwrap();
|
let sender = UserId::try_from("@alice:example.com").unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::get_plain_quote_fallback(&MessageEvent {
|
super::get_plain_quote_fallback(&RoomMessageEvent {
|
||||||
content: MessageEventContent::text_plain("multi\nline"),
|
content: RoomMessageEventContent::text_plain("multi\nline"),
|
||||||
event_id: EventId::new(sender.server_name()),
|
event_id: EventId::new(sender.server_name()),
|
||||||
sender,
|
sender,
|
||||||
origin_server_ts: ruma_common::MilliSecondsSinceUnixEpoch::now(),
|
origin_server_ts: ruma_common::MilliSecondsSinceUnixEpoch::now(),
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
//! `Deserialize` implementation for MessageEventContent and MessageType.
|
//! `Deserialize` implementation for RoomMessageEventContent and MessageType.
|
||||||
|
|
||||||
use serde::{de, Deserialize};
|
use serde::{de, Deserialize};
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
use super::{MessageEventContent, MessageType, Relation};
|
use super::{MessageType, Relation, RoomMessageEventContent};
|
||||||
use crate::from_raw_json_value;
|
use crate::from_raw_json_value;
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for MessageEventContent {
|
impl<'de> Deserialize<'de> for RoomMessageEventContent {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
D: de::Deserializer<'de>,
|
D: de::Deserializer<'de>,
|
||||||
|
@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.message.feedback", kind = Message)]
|
#[ruma_event(type = "m.room.message.feedback", kind = Message)]
|
||||||
pub struct FeedbackEventContent {
|
pub struct RoomMessageFeedbackEventContent {
|
||||||
/// The event that this feedback is related to.
|
/// The event that this feedback is related to.
|
||||||
pub target_event_id: EventId,
|
pub target_event_id: EventId,
|
||||||
|
|
||||||
@ -23,8 +23,8 @@ pub struct FeedbackEventContent {
|
|||||||
pub feedback_type: FeedbackType,
|
pub feedback_type: FeedbackType,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FeedbackEventContent {
|
impl RoomMessageFeedbackEventContent {
|
||||||
/// Create a `FeedbackEventContent` from the given target event id and feedback type.
|
/// Create a `RoomFeedbackEventContent` from the given target event id and feedback type.
|
||||||
pub fn new(target_event_id: EventId, feedback_type: FeedbackType) -> Self {
|
pub fn new(target_event_id: EventId, feedback_type: FeedbackType) -> Self {
|
||||||
Self { target_event_id, feedback_type }
|
Self { target_event_id, feedback_type }
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|||||||
use super::Replacement;
|
use super::Replacement;
|
||||||
use super::{InReplyTo, Relation};
|
use super::{InReplyTo, Relation};
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use crate::room::message::MessageEventContent;
|
use crate::room::message::RoomMessageEventContent;
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Relation {
|
impl<'de> Deserialize<'de> for Relation {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
@ -74,7 +74,7 @@ struct EventWithRelatesToJsonRepr {
|
|||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
#[serde(rename = "m.new_content", skip_serializing_if = "Option::is_none")]
|
#[serde(rename = "m.new_content", skip_serializing_if = "Option::is_none")]
|
||||||
new_content: Option<Box<MessageEventContent>>,
|
new_content: Option<Box<RoomMessageEventContent>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventWithRelatesToJsonRepr {
|
impl EventWithRelatesToJsonRepr {
|
||||||
|
@ -10,14 +10,14 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[ruma_event(type = "m.room.name", kind = State)]
|
#[ruma_event(type = "m.room.name", kind = State)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct NameEventContent {
|
pub struct RoomNameEventContent {
|
||||||
/// The name of the room.
|
/// The name of the room.
|
||||||
#[serde(default, deserialize_with = "ruma_serde::empty_string_as_none")]
|
#[serde(default, deserialize_with = "ruma_serde::empty_string_as_none")]
|
||||||
pub name: Option<RoomNameBox>,
|
pub name: Option<RoomNameBox>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NameEventContent {
|
impl RoomNameEventContent {
|
||||||
/// Create a new `NameEventContent` with the given name.
|
/// Create a new `RoomNameEventContent` with the given name.
|
||||||
pub fn new(name: Option<RoomNameBox>) -> Self {
|
pub fn new(name: Option<RoomNameBox>) -> Self {
|
||||||
Self { name }
|
Self { name }
|
||||||
}
|
}
|
||||||
@ -34,13 +34,13 @@ mod tests {
|
|||||||
use ruma_serde::Raw;
|
use ruma_serde::Raw;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::NameEventContent;
|
use super::RoomNameEventContent;
|
||||||
use crate::{StateEvent, Unsigned};
|
use crate::{StateEvent, Unsigned};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization_with_optional_fields_as_none() {
|
fn serialization_with_optional_fields_as_none() {
|
||||||
let name_event = StateEvent {
|
let name_event = StateEvent {
|
||||||
content: NameEventContent { name: RoomNameBox::try_from("The room name").ok() },
|
content: RoomNameEventContent { name: RoomNameBox::try_from("The room name").ok() },
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
prev_content: None,
|
prev_content: None,
|
||||||
@ -69,10 +69,10 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn serialization_with_all_fields() {
|
fn serialization_with_all_fields() {
|
||||||
let name_event = StateEvent {
|
let name_event = StateEvent {
|
||||||
content: NameEventContent { name: RoomNameBox::try_from("The room name").ok() },
|
content: RoomNameEventContent { name: RoomNameBox::try_from("The room name").ok() },
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
prev_content: Some(NameEventContent {
|
prev_content: Some(RoomNameEventContent {
|
||||||
name: RoomNameBox::try_from("The old name").ok(),
|
name: RoomNameBox::try_from("The old name").ok(),
|
||||||
}),
|
}),
|
||||||
room_id: room_id!("!n8f893n9:example.com"),
|
room_id: room_id!("!n8f893n9:example.com"),
|
||||||
@ -113,7 +113,7 @@ mod tests {
|
|||||||
"type": "m.room.name"
|
"type": "m.room.name"
|
||||||
});
|
});
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_json_value::<StateEvent<NameEventContent>>(json_data).unwrap().content.name,
|
from_json_value::<StateEvent<RoomNameEventContent>>(json_data).unwrap().content.name,
|
||||||
None
|
None
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ mod tests {
|
|||||||
assert_eq!(long_string.len(), 256);
|
assert_eq!(long_string.len(), 256);
|
||||||
|
|
||||||
let long_content_json = json!({ "name": &long_string });
|
let long_content_json = json!({ "name": &long_string });
|
||||||
let from_raw: Raw<NameEventContent> = from_json_value(long_content_json).unwrap();
|
let from_raw: Raw<RoomNameEventContent> = from_json_value(long_content_json).unwrap();
|
||||||
|
|
||||||
let result = from_raw.deserialize();
|
let result = from_raw.deserialize();
|
||||||
assert!(result.is_err(), "Result should be invalid: {:?}", result);
|
assert!(result.is_err(), "Result should be invalid: {:?}", result);
|
||||||
@ -134,15 +134,15 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn json_with_empty_name_creates_content_as_none() {
|
fn json_with_empty_name_creates_content_as_none() {
|
||||||
let long_content_json = json!({ "name": "" });
|
let long_content_json = json!({ "name": "" });
|
||||||
let from_raw: Raw<NameEventContent> = from_json_value(long_content_json).unwrap();
|
let from_raw: Raw<RoomNameEventContent> = from_json_value(long_content_json).unwrap();
|
||||||
assert_matches!(from_raw.deserialize().unwrap(), NameEventContent { name: None });
|
assert_matches!(from_raw.deserialize().unwrap(), RoomNameEventContent { name: None });
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn new_with_empty_name_creates_content_as_none() {
|
fn new_with_empty_name_creates_content_as_none() {
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
NameEventContent::new(RoomNameBox::try_from(String::new()).ok()),
|
RoomNameEventContent::new(RoomNameBox::try_from(String::new()).ok()),
|
||||||
NameEventContent { name: None }
|
RoomNameEventContent { name: None }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ mod tests {
|
|||||||
"type": "m.room.name"
|
"type": "m.room.name"
|
||||||
});
|
});
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_json_value::<StateEvent<NameEventContent>>(json_data).unwrap().content.name,
|
from_json_value::<StateEvent<RoomNameEventContent>>(json_data).unwrap().content.name,
|
||||||
None
|
None
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -179,7 +179,7 @@ mod tests {
|
|||||||
"type": "m.room.name"
|
"type": "m.room.name"
|
||||||
});
|
});
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_json_value::<StateEvent<NameEventContent>>(json_data).unwrap().content.name,
|
from_json_value::<StateEvent<RoomNameEventContent>>(json_data).unwrap().content.name,
|
||||||
None
|
None
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -200,7 +200,7 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_json_value::<StateEvent<NameEventContent>>(json_data).unwrap().content.name,
|
from_json_value::<StateEvent<RoomNameEventContent>>(json_data).unwrap().content.name,
|
||||||
name
|
name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,13 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.pinned_events", kind = State)]
|
#[ruma_event(type = "m.room.pinned_events", kind = State)]
|
||||||
pub struct PinnedEventsEventContent {
|
pub struct RoomPinnedEventsEventContent {
|
||||||
/// An ordered list of event IDs to pin.
|
/// An ordered list of event IDs to pin.
|
||||||
pub pinned: Vec<EventId>,
|
pub pinned: Vec<EventId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PinnedEventsEventContent {
|
impl RoomPinnedEventsEventContent {
|
||||||
/// Creates a new `PinnedEventsEventContent` with the given events.
|
/// Creates a new `RoomPinnedEventsEventContent` with the given events.
|
||||||
pub fn new(pinned: Vec<EventId>) -> Self {
|
pub fn new(pinned: Vec<EventId>) -> Self {
|
||||||
Self { pinned }
|
Self { pinned }
|
||||||
}
|
}
|
||||||
@ -29,12 +29,13 @@ mod tests {
|
|||||||
use ruma_common::MilliSecondsSinceUnixEpoch;
|
use ruma_common::MilliSecondsSinceUnixEpoch;
|
||||||
use ruma_identifiers::{server_name, EventId, RoomId, UserId};
|
use ruma_identifiers::{server_name, EventId, RoomId, UserId};
|
||||||
|
|
||||||
use super::PinnedEventsEventContent;
|
use super::RoomPinnedEventsEventContent;
|
||||||
use crate::{StateEvent, Unsigned};
|
use crate::{StateEvent, Unsigned};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization_deserialization() {
|
fn serialization_deserialization() {
|
||||||
let mut content: PinnedEventsEventContent = PinnedEventsEventContent { pinned: Vec::new() };
|
let mut content: RoomPinnedEventsEventContent =
|
||||||
|
RoomPinnedEventsEventContent { pinned: Vec::new() };
|
||||||
let server_name = server_name!("example.com");
|
let server_name = server_name!("example.com");
|
||||||
|
|
||||||
content.pinned.push(EventId::new(&server_name));
|
content.pinned.push(EventId::new(&server_name));
|
||||||
@ -52,7 +53,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let serialized_event = serde_json::to_string(&event).unwrap();
|
let serialized_event = serde_json::to_string(&event).unwrap();
|
||||||
let parsed_event: StateEvent<PinnedEventsEventContent> =
|
let parsed_event: StateEvent<RoomPinnedEventsEventContent> =
|
||||||
serde_json::from_str(&serialized_event).unwrap();
|
serde_json::from_str(&serialized_event).unwrap();
|
||||||
|
|
||||||
assert_eq!(parsed_event.event_id, event.event_id);
|
assert_eq!(parsed_event.event_id, event.event_id);
|
||||||
|
@ -18,7 +18,7 @@ use ruma_common::power_levels::NotificationPowerLevels;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.power_levels", kind = State)]
|
#[ruma_event(type = "m.room.power_levels", kind = State)]
|
||||||
pub struct PowerLevelsEventContent {
|
pub struct RoomPowerLevelsEventContent {
|
||||||
/// The level required to ban a user.
|
/// The level required to ban a user.
|
||||||
///
|
///
|
||||||
/// If you activate the `compat` feature, deserialization will work for stringified
|
/// If you activate the `compat` feature, deserialization will work for stringified
|
||||||
@ -116,8 +116,8 @@ pub struct PowerLevelsEventContent {
|
|||||||
pub notifications: NotificationPowerLevels,
|
pub notifications: NotificationPowerLevels,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PowerLevelsEventContent {
|
impl RoomPowerLevelsEventContent {
|
||||||
/// Creates a new `PowerLevelsEventContent` with all-default values.
|
/// Creates a new `RoomPowerLevelsEventContent` with all-default values.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
// events_default and users_default having a default of 0 while the others have a default
|
// events_default and users_default having a default of 0 while the others have a default
|
||||||
// of 50 is not an oversight, these defaults are from the Matrix specification.
|
// of 50 is not an oversight, these defaults are from the Matrix specification.
|
||||||
@ -136,7 +136,7 @@ impl PowerLevelsEventContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PowerLevelsEventContent {
|
impl Default for RoomPowerLevelsEventContent {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ mod tests {
|
|||||||
use ruma_identifiers::{event_id, room_id, user_id};
|
use ruma_identifiers::{event_id, room_id, user_id};
|
||||||
use serde_json::{json, to_value as to_json_value};
|
use serde_json::{json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{default_power_level, NotificationPowerLevels, PowerLevelsEventContent};
|
use super::{default_power_level, NotificationPowerLevels, RoomPowerLevelsEventContent};
|
||||||
use crate::{EventType, StateEvent, Unsigned};
|
use crate::{EventType, StateEvent, Unsigned};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -167,7 +167,7 @@ mod tests {
|
|||||||
let default = default_power_level();
|
let default = default_power_level();
|
||||||
|
|
||||||
let power_levels_event = StateEvent {
|
let power_levels_event = StateEvent {
|
||||||
content: PowerLevelsEventContent {
|
content: RoomPowerLevelsEventContent {
|
||||||
ban: default,
|
ban: default,
|
||||||
events: BTreeMap::new(),
|
events: BTreeMap::new(),
|
||||||
events_default: int!(0),
|
events_default: int!(0),
|
||||||
@ -206,7 +206,7 @@ mod tests {
|
|||||||
fn serialization_with_all_fields() {
|
fn serialization_with_all_fields() {
|
||||||
let user = user_id!("@carl:example.com");
|
let user = user_id!("@carl:example.com");
|
||||||
let power_levels_event = StateEvent {
|
let power_levels_event = StateEvent {
|
||||||
content: PowerLevelsEventContent {
|
content: RoomPowerLevelsEventContent {
|
||||||
ban: int!(23),
|
ban: int!(23),
|
||||||
events: btreemap! {
|
events: btreemap! {
|
||||||
EventType::Dummy => int!(23)
|
EventType::Dummy => int!(23)
|
||||||
@ -224,7 +224,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
prev_content: Some(PowerLevelsEventContent {
|
prev_content: Some(RoomPowerLevelsEventContent {
|
||||||
// Make just one field different so we at least know they're two different objects.
|
// Make just one field different so we at least know they're two different objects.
|
||||||
ban: int!(42),
|
ban: int!(42),
|
||||||
events: btreemap! {
|
events: btreemap! {
|
||||||
|
@ -10,9 +10,9 @@ use crate::{Redact, RedactContent, RedactedUnsigned, Unsigned};
|
|||||||
/// Redaction event.
|
/// Redaction event.
|
||||||
#[derive(Clone, Debug, Event)]
|
#[derive(Clone, Debug, Event)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
pub struct RedactionEvent {
|
pub struct RoomRedactionEvent {
|
||||||
/// Data specific to the event type.
|
/// Data specific to the event type.
|
||||||
pub content: RedactionEventContent,
|
pub content: RoomRedactionEventContent,
|
||||||
|
|
||||||
/// The ID of the event that was redacted.
|
/// The ID of the event that was redacted.
|
||||||
pub redacts: EventId,
|
pub redacts: EventId,
|
||||||
@ -33,15 +33,15 @@ pub struct RedactionEvent {
|
|||||||
pub unsigned: Unsigned,
|
pub unsigned: Unsigned,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Redact for RedactionEvent {
|
impl Redact for RoomRedactionEvent {
|
||||||
type Redacted = RedactedRedactionEvent;
|
type Redacted = RedactedRoomRedactionEvent;
|
||||||
|
|
||||||
fn redact(
|
fn redact(
|
||||||
self,
|
self,
|
||||||
redaction: SyncRedactionEvent,
|
redaction: SyncRoomRedactionEvent,
|
||||||
version: &ruma_identifiers::RoomVersionId,
|
version: &ruma_identifiers::RoomVersionId,
|
||||||
) -> Self::Redacted {
|
) -> Self::Redacted {
|
||||||
RedactedRedactionEvent {
|
RedactedRoomRedactionEvent {
|
||||||
content: self.content.redact(version),
|
content: self.content.redact(version),
|
||||||
// There is no released room version where this isn't redacted yet
|
// There is no released room version where this isn't redacted yet
|
||||||
redacts: None,
|
redacts: None,
|
||||||
@ -57,9 +57,9 @@ impl Redact for RedactionEvent {
|
|||||||
/// Redacted redaction event.
|
/// Redacted redaction event.
|
||||||
#[derive(Clone, Debug, Event)]
|
#[derive(Clone, Debug, Event)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
pub struct RedactedRedactionEvent {
|
pub struct RedactedRoomRedactionEvent {
|
||||||
/// Data specific to the event type.
|
/// Data specific to the event type.
|
||||||
pub content: RedactedRedactionEventContent,
|
pub content: RedactedRoomRedactionEventContent,
|
||||||
|
|
||||||
/// The ID of the event that was redacted.
|
/// The ID of the event that was redacted.
|
||||||
pub redacts: Option<EventId>,
|
pub redacts: Option<EventId>,
|
||||||
@ -83,9 +83,9 @@ pub struct RedactedRedactionEvent {
|
|||||||
/// Redaction event without a `room_id`.
|
/// Redaction event without a `room_id`.
|
||||||
#[derive(Clone, Debug, Event)]
|
#[derive(Clone, Debug, Event)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
pub struct SyncRedactionEvent {
|
pub struct SyncRoomRedactionEvent {
|
||||||
/// Data specific to the event type.
|
/// Data specific to the event type.
|
||||||
pub content: RedactionEventContent,
|
pub content: RoomRedactionEventContent,
|
||||||
|
|
||||||
/// The ID of the event that was redacted.
|
/// The ID of the event that was redacted.
|
||||||
pub redacts: EventId,
|
pub redacts: EventId,
|
||||||
@ -103,15 +103,15 @@ pub struct SyncRedactionEvent {
|
|||||||
pub unsigned: Unsigned,
|
pub unsigned: Unsigned,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Redact for SyncRedactionEvent {
|
impl Redact for SyncRoomRedactionEvent {
|
||||||
type Redacted = RedactedSyncRedactionEvent;
|
type Redacted = RedactedSyncRoomRedactionEvent;
|
||||||
|
|
||||||
fn redact(
|
fn redact(
|
||||||
self,
|
self,
|
||||||
redaction: SyncRedactionEvent,
|
redaction: SyncRoomRedactionEvent,
|
||||||
version: &ruma_identifiers::RoomVersionId,
|
version: &ruma_identifiers::RoomVersionId,
|
||||||
) -> Self::Redacted {
|
) -> Self::Redacted {
|
||||||
RedactedSyncRedactionEvent {
|
RedactedSyncRoomRedactionEvent {
|
||||||
content: self.content.redact(version),
|
content: self.content.redact(version),
|
||||||
// There is no released room version where this isn't redacted yet
|
// There is no released room version where this isn't redacted yet
|
||||||
redacts: None,
|
redacts: None,
|
||||||
@ -126,9 +126,9 @@ impl Redact for SyncRedactionEvent {
|
|||||||
/// Redacted redaction event without a `room_id`.
|
/// Redacted redaction event without a `room_id`.
|
||||||
#[derive(Clone, Debug, Event)]
|
#[derive(Clone, Debug, Event)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
pub struct RedactedSyncRedactionEvent {
|
pub struct RedactedSyncRoomRedactionEvent {
|
||||||
/// Data specific to the event type.
|
/// Data specific to the event type.
|
||||||
pub content: RedactedRedactionEventContent,
|
pub content: RedactedRoomRedactionEventContent,
|
||||||
|
|
||||||
/// The ID of the event that was redacted.
|
/// The ID of the event that was redacted.
|
||||||
pub redacts: Option<EventId>,
|
pub redacts: Option<EventId>,
|
||||||
@ -150,19 +150,19 @@ pub struct RedactedSyncRedactionEvent {
|
|||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.redaction", kind = Message)]
|
#[ruma_event(type = "m.room.redaction", kind = Message)]
|
||||||
pub struct RedactionEventContent {
|
pub struct RoomRedactionEventContent {
|
||||||
/// The reason for the redaction, if any.
|
/// The reason for the redaction, if any.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RedactionEventContent {
|
impl RoomRedactionEventContent {
|
||||||
/// Creates an empty `RedactionEventContent`.
|
/// Creates an empty `RoomRedactionEventContent`.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `RedactionEventContent` with the given reason.
|
/// Creates a new `RoomRedactionEventContent` with the given reason.
|
||||||
pub fn with_reason(reason: String) -> Self {
|
pub fn with_reason(reason: String) -> Self {
|
||||||
Self { reason: Some(reason) }
|
Self { reason: Some(reason) }
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.server_acl", kind = State)]
|
#[ruma_event(type = "m.room.server_acl", kind = State)]
|
||||||
pub struct ServerAclEventContent {
|
pub struct RoomServerAclEventContent {
|
||||||
/// Whether to allow server names that are IP address literals.
|
/// Whether to allow server names that are IP address literals.
|
||||||
///
|
///
|
||||||
/// This is strongly recommended to be set to false as servers running with IP literal names
|
/// This is strongly recommended to be set to false as servers running with IP literal names
|
||||||
@ -37,9 +37,9 @@ pub struct ServerAclEventContent {
|
|||||||
pub deny: Vec<String>,
|
pub deny: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServerAclEventContent {
|
impl RoomServerAclEventContent {
|
||||||
/// Creates a new `ServerAclEventContent` with the given IP literal allowance flag, allowed and
|
/// Creates a new `RoomServerAclEventContent` with the given IP literal allowance flag, allowed
|
||||||
/// denied servers.
|
/// and denied servers.
|
||||||
pub fn new(allow_ip_literals: bool, allow: Vec<String>, deny: Vec<String>) -> Self {
|
pub fn new(allow_ip_literals: bool, allow: Vec<String>, deny: Vec<String>) -> Self {
|
||||||
Self { allow_ip_literals, allow, deny }
|
Self { allow_ip_literals, allow, deny }
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ impl ServerAclEventContent {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use serde_json::{from_value as from_json_value, json};
|
use serde_json::{from_value as from_json_value, json};
|
||||||
|
|
||||||
use super::ServerAclEventContent;
|
use super::RoomServerAclEventContent;
|
||||||
use crate::StateEvent;
|
use crate::StateEvent;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -64,7 +64,7 @@ mod tests {
|
|||||||
"type": "m.room.server_acl"
|
"type": "m.room.server_acl"
|
||||||
});
|
});
|
||||||
|
|
||||||
let server_acl_event: StateEvent<ServerAclEventContent> =
|
let server_acl_event: StateEvent<RoomServerAclEventContent> =
|
||||||
from_json_value(json_data).unwrap();
|
from_json_value(json_data).unwrap();
|
||||||
|
|
||||||
assert!(server_acl_event.content.allow_ip_literals);
|
assert!(server_acl_event.content.allow_ip_literals);
|
||||||
|
@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.third_party_invite", kind = State)]
|
#[ruma_event(type = "m.room.third_party_invite", kind = State)]
|
||||||
pub struct ThirdPartyInviteEventContent {
|
pub struct RoomThirdPartyInviteEventContent {
|
||||||
/// A user-readable string which represents the user who has been invited.
|
/// A user-readable string which represents the user who has been invited.
|
||||||
///
|
///
|
||||||
/// If you activate the `compat` feature, this field being absent in JSON will give you an
|
/// If you activate the `compat` feature, this field being absent in JSON will give you an
|
||||||
@ -40,9 +40,9 @@ pub struct ThirdPartyInviteEventContent {
|
|||||||
pub public_keys: Option<Vec<PublicKey>>,
|
pub public_keys: Option<Vec<PublicKey>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThirdPartyInviteEventContent {
|
impl RoomThirdPartyInviteEventContent {
|
||||||
/// Creates a new `ThirdPartyInviteEventContent` with the given display name, key validity url
|
/// Creates a new `RoomThirdPartyInviteEventContent` with the given display name, key validity
|
||||||
/// and public key.
|
/// url and public key.
|
||||||
pub fn new(display_name: String, key_validity_url: String, public_key: String) -> Self {
|
pub fn new(display_name: String, key_validity_url: String, public_key: String) -> Self {
|
||||||
Self { display_name, key_validity_url, public_key, public_keys: None }
|
Self { display_name, key_validity_url, public_key, public_keys: None }
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[ruma_event(type = "m.room.tombstone", kind = State)]
|
#[ruma_event(type = "m.room.tombstone", kind = State)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct TombstoneEventContent {
|
pub struct RoomTombstoneEventContent {
|
||||||
/// A server-defined message.
|
/// A server-defined message.
|
||||||
///
|
///
|
||||||
/// If you activate the `compat` feature, this field being absent in JSON will give you an
|
/// If you activate the `compat` feature, this field being absent in JSON will give you an
|
||||||
@ -23,8 +23,8 @@ pub struct TombstoneEventContent {
|
|||||||
pub replacement_room: RoomId,
|
pub replacement_room: RoomId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TombstoneEventContent {
|
impl RoomTombstoneEventContent {
|
||||||
/// Creates a new `TombstoneEventContent` with the given body and replacement room ID.
|
/// Creates a new `RoomTombstoneEventContent` with the given body and replacement room ID.
|
||||||
pub fn new(body: String, replacement_room: RoomId) -> Self {
|
pub fn new(body: String, replacement_room: RoomId) -> Self {
|
||||||
Self { body, replacement_room }
|
Self { body, replacement_room }
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,13 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.topic", kind = State)]
|
#[ruma_event(type = "m.room.topic", kind = State)]
|
||||||
pub struct TopicEventContent {
|
pub struct RoomTopicEventContent {
|
||||||
/// The topic text.
|
/// The topic text.
|
||||||
pub topic: String,
|
pub topic: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopicEventContent {
|
impl RoomTopicEventContent {
|
||||||
/// Creates a new `TopicEventContent` with the given topic.
|
/// Creates a new `RoomTopicEventContent` with the given topic.
|
||||||
pub fn new(topic: String) -> Self {
|
pub fn new(topic: String) -> Self {
|
||||||
Self { topic }
|
Self { topic }
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ use serde::{ser::SerializeStruct, Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
|
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.secret.request", kind = ToDevice)]
|
#[ruma_event(type = "m.secret.request", kind = ToDevice)]
|
||||||
pub struct ToDeviceRequestEventContent {
|
pub struct ToDeviceSecretRequestEventContent {
|
||||||
/// The action for the request.
|
/// The action for the request.
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub action: RequestAction,
|
pub action: RequestAction,
|
||||||
@ -31,7 +31,7 @@ pub struct ToDeviceRequestEventContent {
|
|||||||
pub request_id: String,
|
pub request_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToDeviceRequestEventContent {
|
impl ToDeviceSecretRequestEventContent {
|
||||||
/// Creates a new `ToDeviceRequestEventContent` with the given action, requesting device ID and
|
/// Creates a new `ToDeviceRequestEventContent` with the given action, requesting device ID and
|
||||||
/// request ID.
|
/// request ID.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
@ -133,13 +133,13 @@ pub enum SecretName {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::{RequestAction, SecretName, ToDeviceRequestEventContent};
|
use super::{RequestAction, SecretName, ToDeviceSecretRequestEventContent};
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn secret_request_serialization() {
|
fn secret_request_serialization() {
|
||||||
let content = ToDeviceRequestEventContent::new(
|
let content = ToDeviceSecretRequestEventContent::new(
|
||||||
RequestAction::Request("org.example.some.secret".into()),
|
RequestAction::Request("org.example.some.secret".into()),
|
||||||
"ABCDEFG".into(),
|
"ABCDEFG".into(),
|
||||||
"randomly_generated_id_9573".into(),
|
"randomly_generated_id_9573".into(),
|
||||||
@ -157,7 +157,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn secret_request_recovery_key_serialization() {
|
fn secret_request_recovery_key_serialization() {
|
||||||
let content = ToDeviceRequestEventContent::new(
|
let content = ToDeviceSecretRequestEventContent::new(
|
||||||
RequestAction::Request(SecretName::RecoveryKey),
|
RequestAction::Request(SecretName::RecoveryKey),
|
||||||
"XYZxyz".into(),
|
"XYZxyz".into(),
|
||||||
"this_is_a_request_id".into(),
|
"this_is_a_request_id".into(),
|
||||||
@ -175,7 +175,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn secret_custom_action_serialization() {
|
fn secret_custom_action_serialization() {
|
||||||
let content = ToDeviceRequestEventContent::new(
|
let content = ToDeviceSecretRequestEventContent::new(
|
||||||
RequestAction::_Custom("my_custom_action".into()),
|
RequestAction::_Custom("my_custom_action".into()),
|
||||||
"XYZxyz".into(),
|
"XYZxyz".into(),
|
||||||
"this_is_a_request_id".into(),
|
"this_is_a_request_id".into(),
|
||||||
@ -192,7 +192,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn secret_request_cancellation_serialization() {
|
fn secret_request_cancellation_serialization() {
|
||||||
let content = ToDeviceRequestEventContent::new(
|
let content = ToDeviceSecretRequestEventContent::new(
|
||||||
RequestAction::RequestCancellation,
|
RequestAction::RequestCancellation,
|
||||||
"ABCDEFG".into(),
|
"ABCDEFG".into(),
|
||||||
"randomly_generated_id_9573".into(),
|
"randomly_generated_id_9573".into(),
|
||||||
@ -218,7 +218,7 @@ mod test {
|
|||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value(json).unwrap(),
|
from_json_value(json).unwrap(),
|
||||||
ToDeviceRequestEventContent {
|
ToDeviceSecretRequestEventContent {
|
||||||
action: RequestAction::Request(
|
action: RequestAction::Request(
|
||||||
secret
|
secret
|
||||||
),
|
),
|
||||||
@ -241,7 +241,7 @@ mod test {
|
|||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value(json).unwrap(),
|
from_json_value(json).unwrap(),
|
||||||
ToDeviceRequestEventContent {
|
ToDeviceSecretRequestEventContent {
|
||||||
action: RequestAction::RequestCancellation,
|
action: RequestAction::RequestCancellation,
|
||||||
requesting_device_id,
|
requesting_device_id,
|
||||||
request_id,
|
request_id,
|
||||||
@ -262,7 +262,7 @@ mod test {
|
|||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value(json).unwrap(),
|
from_json_value(json).unwrap(),
|
||||||
ToDeviceRequestEventContent {
|
ToDeviceSecretRequestEventContent {
|
||||||
action: RequestAction::Request(
|
action: RequestAction::Request(
|
||||||
SecretName::RecoveryKey
|
SecretName::RecoveryKey
|
||||||
),
|
),
|
||||||
@ -283,8 +283,8 @@ mod test {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<ToDeviceRequestEventContent>(json).unwrap(),
|
from_json_value::<ToDeviceSecretRequestEventContent>(json).unwrap(),
|
||||||
ToDeviceRequestEventContent {
|
ToDeviceSecretRequestEventContent {
|
||||||
action,
|
action,
|
||||||
requesting_device_id,
|
requesting_device_id,
|
||||||
request_id,
|
request_id,
|
||||||
|
@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.secret.send", kind = ToDevice)]
|
#[ruma_event(type = "m.secret.send", kind = ToDevice)]
|
||||||
pub struct ToDeviceSendEventContent {
|
pub struct ToDeviceSecretSendEventContent {
|
||||||
/// The ID of the request that this is a response to.
|
/// The ID of the request that this is a response to.
|
||||||
pub request_id: String,
|
pub request_id: String,
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ pub struct ToDeviceSendEventContent {
|
|||||||
pub secret: String,
|
pub secret: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToDeviceSendEventContent {
|
impl ToDeviceSecretSendEventContent {
|
||||||
/// Creates a new `SecretSendEventContent` with the given request ID and secret.
|
/// Creates a new `SecretSendEventContent` with the given request ID and secret.
|
||||||
pub fn new(request_id: String, secret: String) -> Self {
|
pub fn new(request_id: String, secret: String) -> Self {
|
||||||
Self { request_id, secret }
|
Self { request_id, secret }
|
||||||
|
@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.space.child", kind = State)]
|
#[ruma_event(type = "m.space.child", kind = State)]
|
||||||
pub struct ChildEventContent {
|
pub struct SpaceChildEventContent {
|
||||||
/// List of candidate servers that can be used to join the room.
|
/// List of candidate servers that can be used to join the room.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub via: Option<Vec<ServerNameBox>>,
|
pub via: Option<Vec<ServerNameBox>>,
|
||||||
@ -41,7 +41,7 @@ pub struct ChildEventContent {
|
|||||||
pub suggested: Option<bool>,
|
pub suggested: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChildEventContent {
|
impl SpaceChildEventContent {
|
||||||
/// Creates a new `ChildEventContent`.
|
/// Creates a new `ChildEventContent`.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Self::default()
|
||||||
@ -50,13 +50,13 @@ impl ChildEventContent {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::ChildEventContent;
|
use super::SpaceChildEventContent;
|
||||||
use ruma_identifiers::server_name;
|
use ruma_identifiers::server_name;
|
||||||
use serde_json::{json, to_value as to_json_value};
|
use serde_json::{json, to_value as to_json_value};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn space_child_serialization() {
|
fn space_child_serialization() {
|
||||||
let content = ChildEventContent {
|
let content = SpaceChildEventContent {
|
||||||
via: Some(vec![server_name!("example.com")]),
|
via: Some(vec![server_name!("example.com")]),
|
||||||
order: Some("uwu".to_owned()),
|
order: Some("uwu".to_owned()),
|
||||||
suggested: Some(false),
|
suggested: Some(false),
|
||||||
@ -73,7 +73,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn space_child_empty_serialization() {
|
fn space_child_empty_serialization() {
|
||||||
let content = ChildEventContent { via: None, order: None, suggested: None };
|
let content = SpaceChildEventContent { via: None, order: None, suggested: None };
|
||||||
|
|
||||||
let json = json!({});
|
let json = json!({});
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.space.parent", kind = State)]
|
#[ruma_event(type = "m.space.parent", kind = State)]
|
||||||
pub struct ParentEventContent {
|
pub struct SpaceParentEventContent {
|
||||||
/// List of candidate servers that can be used to join the room.
|
/// List of candidate servers that can be used to join the room.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub via: Option<Vec<ServerNameBox>>,
|
pub via: Option<Vec<ServerNameBox>>,
|
||||||
@ -29,7 +29,7 @@ pub struct ParentEventContent {
|
|||||||
pub canonical: bool,
|
pub canonical: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParentEventContent {
|
impl SpaceParentEventContent {
|
||||||
/// Creates a new `ParentEventContent` with the given canonical flag.
|
/// Creates a new `ParentEventContent` with the given canonical flag.
|
||||||
pub fn new(canonical: bool) -> Self {
|
pub fn new(canonical: bool) -> Self {
|
||||||
Self { via: None, canonical }
|
Self { via: None, canonical }
|
||||||
@ -38,14 +38,16 @@ impl ParentEventContent {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::ParentEventContent;
|
use super::SpaceParentEventContent;
|
||||||
use ruma_identifiers::server_name;
|
use ruma_identifiers::server_name;
|
||||||
use serde_json::{json, to_value as to_json_value};
|
use serde_json::{json, to_value as to_json_value};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn space_parent_serialization() {
|
fn space_parent_serialization() {
|
||||||
let content =
|
let content = SpaceParentEventContent {
|
||||||
ParentEventContent { via: Some(vec![server_name!("example.com")]), canonical: true };
|
via: Some(vec![server_name!("example.com")]),
|
||||||
|
canonical: true,
|
||||||
|
};
|
||||||
|
|
||||||
let json = json!({
|
let json = json!({
|
||||||
"via": ["example.com"],
|
"via": ["example.com"],
|
||||||
@ -57,7 +59,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn space_parent_empty_serialization() {
|
fn space_parent_empty_serialization() {
|
||||||
let content = ParentEventContent { via: None, canonical: true };
|
let content = SpaceParentEventContent { via: None, canonical: true };
|
||||||
|
|
||||||
let json = json!({
|
let json = json!({
|
||||||
"canonical": true,
|
"canonical": true,
|
||||||
|
@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use crate::relation::Relations;
|
use crate::relation::Relations;
|
||||||
use crate::room::redaction::SyncRedactionEvent;
|
use crate::room::redaction::SyncRoomRedactionEvent;
|
||||||
|
|
||||||
/// Extra information about an event that is not incorporated into the event's hash.
|
/// Extra information about an event that is not incorporated into the event's hash.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
@ -51,7 +51,7 @@ impl Unsigned {
|
|||||||
pub struct RedactedUnsigned {
|
pub struct RedactedUnsigned {
|
||||||
/// The event that redacted this event, if any.
|
/// The event that redacted this event, if any.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub redacted_because: Option<Box<SyncRedactionEvent>>,
|
pub redacted_because: Option<Box<SyncRoomRedactionEvent>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RedactedUnsigned {
|
impl RedactedUnsigned {
|
||||||
@ -61,7 +61,7 @@ impl RedactedUnsigned {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new `RedactedUnsigned` with the given redacted because.
|
/// Create a new `RedactedUnsigned` with the given redacted because.
|
||||||
pub fn new_because(redacted_because: Box<SyncRedactionEvent>) -> Self {
|
pub fn new_because(redacted_because: Box<SyncRoomRedactionEvent>) -> Self {
|
||||||
Self { redacted_because: Some(redacted_because) }
|
Self { redacted_because: Some(redacted_because) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ impl From<UnsignedWithPrevContent> for Unsigned {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct RedactedUnsignedWithPrevContent {
|
pub struct RedactedUnsignedWithPrevContent {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
redacted_because: Option<Box<SyncRedactionEvent>>,
|
redacted_because: Option<Box<SyncRoomRedactionEvent>>,
|
||||||
|
|
||||||
pub prev_content: Option<Box<serde_json::value::RawValue>>,
|
pub prev_content: Option<Box<serde_json::value::RawValue>>,
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#![cfg(feature = "compat")]
|
#![cfg(feature = "compat")]
|
||||||
|
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
use ruma_events::room::topic::{TopicEvent, TopicEventContent};
|
use ruma_events::room::topic::{RoomTopicEvent, RoomTopicEventContent};
|
||||||
use serde_json::{from_value as from_json_value, json};
|
use serde_json::{from_value as from_json_value, json};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_unsigned_prev_content() {
|
fn deserialize_unsigned_prev_content() {
|
||||||
let res = from_json_value::<TopicEvent>(json!({
|
let res = from_json_value::<RoomTopicEvent>(json!({
|
||||||
"content": {
|
"content": {
|
||||||
"topic": "New room topic",
|
"topic": "New room topic",
|
||||||
},
|
},
|
||||||
@ -26,9 +26,9 @@ fn deserialize_unsigned_prev_content() {
|
|||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
res,
|
res,
|
||||||
Ok(TopicEvent {
|
Ok(RoomTopicEvent {
|
||||||
content: TopicEventContent { topic: new_topic, .. },
|
content: RoomTopicEventContent { topic: new_topic, .. },
|
||||||
prev_content: Some(TopicEventContent { topic: old_topic, .. }),
|
prev_content: Some(RoomTopicEventContent { topic: old_topic, .. }),
|
||||||
..
|
..
|
||||||
}) if new_topic == "New room topic"
|
}) if new_topic == "New room topic"
|
||||||
&& old_topic == "Old room topic"
|
&& old_topic == "Old room topic"
|
||||||
|
@ -7,9 +7,9 @@ use serde_json::{from_value as from_json_value, json, Value as JsonValue};
|
|||||||
|
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::{
|
room::{
|
||||||
aliases::AliasesEventContent,
|
aliases::RoomAliasesEventContent,
|
||||||
message::{MessageEventContent, MessageType, TextMessageEventContent},
|
message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
|
||||||
power_levels::PowerLevelsEventContent,
|
power_levels::RoomPowerLevelsEventContent,
|
||||||
},
|
},
|
||||||
AnyEphemeralRoomEvent, AnyMessageEvent, AnyRoomEvent, AnyStateEvent, AnyStateEventContent,
|
AnyEphemeralRoomEvent, AnyMessageEvent, AnyRoomEvent, AnyStateEvent, AnyStateEventContent,
|
||||||
AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent, EphemeralRoomEventType, EventType,
|
AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent, EphemeralRoomEventType, EventType,
|
||||||
@ -123,7 +123,7 @@ fn power_event_sync_deserialization() {
|
|||||||
from_json_value::<AnySyncRoomEvent>(json_data),
|
from_json_value::<AnySyncRoomEvent>(json_data),
|
||||||
Ok(AnySyncRoomEvent::State(
|
Ok(AnySyncRoomEvent::State(
|
||||||
AnySyncStateEvent::RoomPowerLevels(SyncStateEvent {
|
AnySyncStateEvent::RoomPowerLevels(SyncStateEvent {
|
||||||
content: PowerLevelsEventContent {
|
content: RoomPowerLevelsEventContent {
|
||||||
ban, ..
|
ban, ..
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
@ -141,7 +141,7 @@ fn message_event_sync_deserialization() {
|
|||||||
from_json_value::<AnySyncRoomEvent>(json_data),
|
from_json_value::<AnySyncRoomEvent>(json_data),
|
||||||
Ok(AnySyncRoomEvent::Message(
|
Ok(AnySyncRoomEvent::Message(
|
||||||
AnySyncMessageEvent::RoomMessage(SyncMessageEvent {
|
AnySyncMessageEvent::RoomMessage(SyncMessageEvent {
|
||||||
content: MessageEventContent {
|
content: RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(TextMessageEventContent {
|
msgtype: MessageType::Text(TextMessageEventContent {
|
||||||
body,
|
body,
|
||||||
formatted: Some(formatted),
|
formatted: Some(formatted),
|
||||||
@ -164,7 +164,7 @@ fn aliases_event_sync_deserialization() {
|
|||||||
from_json_value::<AnySyncRoomEvent>(json_data),
|
from_json_value::<AnySyncRoomEvent>(json_data),
|
||||||
Ok(AnySyncRoomEvent::State(
|
Ok(AnySyncRoomEvent::State(
|
||||||
AnySyncStateEvent::RoomAliases(SyncStateEvent {
|
AnySyncStateEvent::RoomAliases(SyncStateEvent {
|
||||||
content: AliasesEventContent {
|
content: RoomAliasesEventContent {
|
||||||
aliases,
|
aliases,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
@ -183,7 +183,7 @@ fn message_room_event_deserialization() {
|
|||||||
from_json_value::<AnyRoomEvent>(json_data),
|
from_json_value::<AnyRoomEvent>(json_data),
|
||||||
Ok(AnyRoomEvent::Message(
|
Ok(AnyRoomEvent::Message(
|
||||||
AnyMessageEvent::RoomMessage(MessageEvent {
|
AnyMessageEvent::RoomMessage(MessageEvent {
|
||||||
content: MessageEventContent {
|
content: RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(TextMessageEventContent {
|
msgtype: MessageType::Text(TextMessageEventContent {
|
||||||
body,
|
body,
|
||||||
formatted: Some(formatted),
|
formatted: Some(formatted),
|
||||||
@ -201,7 +201,7 @@ fn message_room_event_deserialization() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn message_event_serialization() {
|
fn message_event_serialization() {
|
||||||
let event = MessageEvent {
|
let event = MessageEvent {
|
||||||
content: MessageEventContent::text_plain("test"),
|
content: RoomMessageEventContent::text_plain("test"),
|
||||||
event_id: event_id!("$1234:example.com"),
|
event_id: event_id!("$1234:example.com"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(0)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(0)),
|
||||||
room_id: room_id!("!roomid:example.com"),
|
room_id: room_id!("!roomid:example.com"),
|
||||||
@ -223,7 +223,7 @@ fn alias_room_event_deserialization() {
|
|||||||
from_json_value::<AnyRoomEvent>(json_data),
|
from_json_value::<AnyRoomEvent>(json_data),
|
||||||
Ok(AnyRoomEvent::State(
|
Ok(AnyRoomEvent::State(
|
||||||
AnyStateEvent::RoomAliases(StateEvent {
|
AnyStateEvent::RoomAliases(StateEvent {
|
||||||
content: AliasesEventContent {
|
content: RoomAliasesEventContent {
|
||||||
aliases,
|
aliases,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
@ -242,7 +242,7 @@ fn message_event_deserialization() {
|
|||||||
from_json_value::<AnyRoomEvent>(json_data),
|
from_json_value::<AnyRoomEvent>(json_data),
|
||||||
Ok(AnyRoomEvent::Message(
|
Ok(AnyRoomEvent::Message(
|
||||||
AnyMessageEvent::RoomMessage(MessageEvent {
|
AnyMessageEvent::RoomMessage(MessageEvent {
|
||||||
content: MessageEventContent {
|
content: RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(TextMessageEventContent {
|
msgtype: MessageType::Text(TextMessageEventContent {
|
||||||
body,
|
body,
|
||||||
formatted: Some(formatted),
|
formatted: Some(formatted),
|
||||||
@ -265,7 +265,7 @@ fn alias_event_deserialization() {
|
|||||||
from_json_value::<AnyRoomEvent>(json_data),
|
from_json_value::<AnyRoomEvent>(json_data),
|
||||||
Ok(AnyRoomEvent::State(
|
Ok(AnyRoomEvent::State(
|
||||||
AnyStateEvent::RoomAliases(StateEvent {
|
AnyStateEvent::RoomAliases(StateEvent {
|
||||||
content: AliasesEventContent {
|
content: RoomAliasesEventContent {
|
||||||
aliases,
|
aliases,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
@ -290,7 +290,8 @@ fn alias_event_field_access() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let deser = from_json_value::<AnyStateEvent>(json_data).unwrap();
|
let deser = from_json_value::<AnyStateEvent>(json_data).unwrap();
|
||||||
if let AnyStateEventContent::RoomAliases(AliasesEventContent { aliases, .. }) = deser.content()
|
if let AnyStateEventContent::RoomAliases(RoomAliasesEventContent { aliases, .. }) =
|
||||||
|
deser.content()
|
||||||
{
|
{
|
||||||
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")])
|
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")])
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,7 +6,7 @@ use ruma_identifiers::{event_id, mxc_uri, room_id, user_id};
|
|||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
call::{answer::AnswerEventContent, SessionDescription, SessionDescriptionType},
|
call::{answer::CallAnswerEventContent, SessionDescription, SessionDescriptionType},
|
||||||
room::{ImageInfo, ThumbnailInfo},
|
room::{ImageInfo, ThumbnailInfo},
|
||||||
sticker::StickerEventContent,
|
sticker::StickerEventContent,
|
||||||
AnyMessageEvent, MessageEvent, Unsigned,
|
AnyMessageEvent, MessageEvent, Unsigned,
|
||||||
@ -42,7 +42,7 @@ fn deserialize_message_event() {
|
|||||||
from_json_value::<AnyMessageEvent>(json_data)
|
from_json_value::<AnyMessageEvent>(json_data)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
AnyMessageEvent::CallAnswer(MessageEvent {
|
AnyMessageEvent::CallAnswer(MessageEvent {
|
||||||
content: AnswerEventContent {
|
content: CallAnswerEventContent {
|
||||||
answer: SessionDescription {
|
answer: SessionDescription {
|
||||||
session_type: SessionDescriptionType::Answer,
|
session_type: SessionDescriptionType::Answer,
|
||||||
sdp,
|
sdp,
|
||||||
|
@ -3,7 +3,7 @@ use js_int::{uint, UInt};
|
|||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
use ruma_common::MilliSecondsSinceUnixEpoch;
|
use ruma_common::MilliSecondsSinceUnixEpoch;
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
call::{answer::AnswerEventContent, SessionDescription, SessionDescriptionType},
|
call::{answer::CallAnswerEventContent, SessionDescription, SessionDescriptionType},
|
||||||
room::{ImageInfo, ThumbnailInfo},
|
room::{ImageInfo, ThumbnailInfo},
|
||||||
sticker::StickerEventContent,
|
sticker::StickerEventContent,
|
||||||
AnyMessageEvent, AnyMessageEventContent, AnySyncMessageEvent, MessageEvent, RawExt, Unsigned,
|
AnyMessageEvent, AnyMessageEventContent, AnySyncMessageEvent, MessageEvent, RawExt, Unsigned,
|
||||||
@ -84,7 +84,7 @@ fn deserialize_message_call_answer_content() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.deserialize_content("m.call.answer")
|
.deserialize_content("m.call.answer")
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
AnyMessageEventContent::CallAnswer(AnswerEventContent {
|
AnyMessageEventContent::CallAnswer(CallAnswerEventContent {
|
||||||
answer: SessionDescription {
|
answer: SessionDescription {
|
||||||
session_type: SessionDescriptionType::Answer,
|
session_type: SessionDescriptionType::Answer,
|
||||||
sdp,
|
sdp,
|
||||||
@ -118,7 +118,7 @@ fn deserialize_message_call_answer() {
|
|||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageEvent>(json_data).unwrap(),
|
from_json_value::<AnyMessageEvent>(json_data).unwrap(),
|
||||||
AnyMessageEvent::CallAnswer(MessageEvent {
|
AnyMessageEvent::CallAnswer(MessageEvent {
|
||||||
content: AnswerEventContent {
|
content: CallAnswerEventContent {
|
||||||
answer: SessionDescription {
|
answer: SessionDescription {
|
||||||
session_type: SessionDescriptionType::Answer,
|
session_type: SessionDescriptionType::Answer,
|
||||||
sdp,
|
sdp,
|
||||||
@ -249,7 +249,7 @@ fn deserialize_message_then_convert_to_full() {
|
|||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageEvent>(full_json).unwrap(),
|
from_json_value::<AnyMessageEvent>(full_json).unwrap(),
|
||||||
AnyMessageEvent::CallAnswer(MessageEvent {
|
AnyMessageEvent::CallAnswer(MessageEvent {
|
||||||
content: AnswerEventContent {
|
content: CallAnswerEventContent {
|
||||||
answer: SessionDescription {
|
answer: SessionDescription {
|
||||||
session_type: SessionDescriptionType::Answer,
|
session_type: SessionDescriptionType::Answer,
|
||||||
sdp,
|
sdp,
|
||||||
|
@ -4,10 +4,10 @@ use ruma_common::MilliSecondsSinceUnixEpoch;
|
|||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
custom::RedactedCustomEventContent,
|
custom::RedactedCustomEventContent,
|
||||||
room::{
|
room::{
|
||||||
aliases::RedactedAliasesEventContent,
|
aliases::RedactedRoomAliasesEventContent,
|
||||||
create::RedactedCreateEventContent,
|
create::RedactedRoomCreateEventContent,
|
||||||
message::RedactedMessageEventContent,
|
message::RedactedRoomMessageEventContent,
|
||||||
redaction::{RedactionEventContent, SyncRedactionEvent},
|
redaction::{RoomRedactionEventContent, SyncRoomRedactionEvent},
|
||||||
},
|
},
|
||||||
AnyMessageEvent, AnyMessageEventContent, AnyRedactedMessageEvent,
|
AnyMessageEvent, AnyMessageEventContent, AnyRedactedMessageEvent,
|
||||||
AnyRedactedMessageEventContent, AnyRedactedStateEventContent, AnyRedactedSyncMessageEvent,
|
AnyRedactedMessageEventContent, AnyRedactedStateEventContent, AnyRedactedSyncMessageEvent,
|
||||||
@ -22,8 +22,8 @@ use serde_json::{
|
|||||||
|
|
||||||
fn unsigned() -> RedactedUnsigned {
|
fn unsigned() -> RedactedUnsigned {
|
||||||
let mut unsigned = RedactedUnsigned::default();
|
let mut unsigned = RedactedUnsigned::default();
|
||||||
unsigned.redacted_because = Some(Box::new(SyncRedactionEvent {
|
unsigned.redacted_because = Some(Box::new(SyncRoomRedactionEvent {
|
||||||
content: RedactionEventContent::with_reason("redacted because".into()),
|
content: RoomRedactionEventContent::with_reason("redacted because".into()),
|
||||||
redacts: event_id!("$h29iv0s8:example.com"),
|
redacts: event_id!("$h29iv0s8:example.com"),
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
@ -37,7 +37,7 @@ fn unsigned() -> RedactedUnsigned {
|
|||||||
#[test]
|
#[test]
|
||||||
fn redacted_message_event_serialize() {
|
fn redacted_message_event_serialize() {
|
||||||
let redacted = RedactedSyncMessageEvent {
|
let redacted = RedactedSyncMessageEvent {
|
||||||
content: RedactedMessageEventContent::new(),
|
content: RedactedRoomMessageEventContent::new(),
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
sender: user_id!("@carl:example.com"),
|
sender: user_id!("@carl:example.com"),
|
||||||
@ -58,7 +58,7 @@ fn redacted_message_event_serialize() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn redacted_aliases_event_serialize_no_content() {
|
fn redacted_aliases_event_serialize_no_content() {
|
||||||
let redacted = RedactedSyncStateEvent {
|
let redacted = RedactedSyncStateEvent {
|
||||||
content: RedactedAliasesEventContent::default(),
|
content: RedactedRoomAliasesEventContent::default(),
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
state_key: "".into(),
|
state_key: "".into(),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
@ -81,7 +81,7 @@ fn redacted_aliases_event_serialize_no_content() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn redacted_aliases_event_serialize_with_content() {
|
fn redacted_aliases_event_serialize_with_content() {
|
||||||
let redacted = RedactedSyncStateEvent {
|
let redacted = RedactedSyncStateEvent {
|
||||||
content: RedactedAliasesEventContent::new_v1(vec![]),
|
content: RedactedRoomAliasesEventContent::new_v1(vec![]),
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
state_key: "".to_owned(),
|
state_key: "".to_owned(),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
@ -121,7 +121,7 @@ fn redacted_aliases_deserialize() {
|
|||||||
from_json_value::<AnySyncRoomEvent>(actual).unwrap(),
|
from_json_value::<AnySyncRoomEvent>(actual).unwrap(),
|
||||||
AnySyncRoomEvent::RedactedState(AnyRedactedSyncStateEvent::RoomAliases(
|
AnySyncRoomEvent::RedactedState(AnyRedactedSyncStateEvent::RoomAliases(
|
||||||
RedactedSyncStateEvent {
|
RedactedSyncStateEvent {
|
||||||
content: RedactedAliasesEventContent { aliases, .. },
|
content: RedactedRoomAliasesEventContent { aliases, .. },
|
||||||
event_id,
|
event_id,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
@ -146,7 +146,7 @@ fn redacted_deserialize_any_room() {
|
|||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyRoomEvent>(actual).unwrap(),
|
from_json_value::<AnyRoomEvent>(actual).unwrap(),
|
||||||
AnyRoomEvent::RedactedMessage(AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent {
|
AnyRoomEvent::RedactedMessage(AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent {
|
||||||
content: RedactedMessageEventContent { .. },
|
content: RedactedRoomMessageEventContent { .. },
|
||||||
event_id, room_id, ..
|
event_id, room_id, ..
|
||||||
})) if event_id == event_id!("$h29iv0s8:example.com")
|
})) if event_id == event_id!("$h29iv0s8:example.com")
|
||||||
&& room_id == room_id!("!roomid:room.com")
|
&& room_id == room_id!("!roomid:room.com")
|
||||||
@ -159,8 +159,8 @@ fn redacted_deserialize_any_room_sync() {
|
|||||||
// The presence of `redacted_because` triggers the event enum (AnySyncRoomEvent in this case)
|
// The presence of `redacted_because` triggers the event enum (AnySyncRoomEvent in this case)
|
||||||
// to return early with `RedactedContent` instead of failing to deserialize according
|
// to return early with `RedactedContent` instead of failing to deserialize according
|
||||||
// to the event type string.
|
// to the event type string.
|
||||||
unsigned.redacted_because = Some(Box::new(SyncRedactionEvent {
|
unsigned.redacted_because = Some(Box::new(SyncRoomRedactionEvent {
|
||||||
content: RedactionEventContent::with_reason("redacted because".into()),
|
content: RoomRedactionEventContent::with_reason("redacted because".into()),
|
||||||
redacts: event_id!("$h29iv0s8:example.com"),
|
redacts: event_id!("$h29iv0s8:example.com"),
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
@ -182,7 +182,7 @@ fn redacted_deserialize_any_room_sync() {
|
|||||||
from_json_value::<AnySyncRoomEvent>(actual).unwrap(),
|
from_json_value::<AnySyncRoomEvent>(actual).unwrap(),
|
||||||
AnySyncRoomEvent::RedactedMessage(AnyRedactedSyncMessageEvent::RoomMessage(
|
AnySyncRoomEvent::RedactedMessage(AnyRedactedSyncMessageEvent::RoomMessage(
|
||||||
RedactedSyncMessageEvent {
|
RedactedSyncMessageEvent {
|
||||||
content: RedactedMessageEventContent { .. },
|
content: RedactedRoomMessageEventContent { .. },
|
||||||
event_id,
|
event_id,
|
||||||
..
|
..
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ fn redacted_state_event_deserialize() {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
AnySyncRoomEvent::RedactedState(AnyRedactedSyncStateEvent::RoomCreate(
|
AnySyncRoomEvent::RedactedState(AnyRedactedSyncStateEvent::RoomCreate(
|
||||||
RedactedSyncStateEvent {
|
RedactedSyncStateEvent {
|
||||||
content: RedactedCreateEventContent {
|
content: RedactedRoomCreateEventContent {
|
||||||
creator, ..
|
creator, ..
|
||||||
},
|
},
|
||||||
event_id,
|
event_id,
|
||||||
@ -285,8 +285,8 @@ fn redact_method_properly_redacts() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let redaction = SyncRedactionEvent {
|
let redaction = SyncRoomRedactionEvent {
|
||||||
content: RedactionEventContent::with_reason("redacted because".into()),
|
content: RoomRedactionEventContent::with_reason("redacted because".into()),
|
||||||
redacts: event_id!("$143273582443PhrSn:example.com"),
|
redacts: event_id!("$143273582443PhrSn:example.com"),
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
@ -299,7 +299,7 @@ fn redact_method_properly_redacts() {
|
|||||||
assert_matches!(
|
assert_matches!(
|
||||||
event.redact(redaction, &RoomVersionId::Version6),
|
event.redact(redaction, &RoomVersionId::Version6),
|
||||||
AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent {
|
AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent {
|
||||||
content: RedactedMessageEventContent { .. },
|
content: RedactedRoomMessageEventContent { .. },
|
||||||
event_id,
|
event_id,
|
||||||
room_id,
|
room_id,
|
||||||
sender,
|
sender,
|
||||||
@ -326,7 +326,7 @@ fn redact_message_content() {
|
|||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
content.redact(&RoomVersionId::Version6),
|
content.redact(&RoomVersionId::Version6),
|
||||||
AnyRedactedMessageEventContent::RoomMessage(RedactedMessageEventContent { .. })
|
AnyRedactedMessageEventContent::RoomMessage(RedactedRoomMessageEventContent { .. })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,7 +343,7 @@ fn redact_state_content() {
|
|||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
content.redact(&RoomVersionId::Version6),
|
content.redact(&RoomVersionId::Version6),
|
||||||
AnyRedactedStateEventContent::RoomCreate(RedactedCreateEventContent {
|
AnyRedactedStateEventContent::RoomCreate(RedactedRoomCreateEventContent {
|
||||||
creator,
|
creator,
|
||||||
..
|
..
|
||||||
}) if creator == user_id!("@carl:example.com")
|
}) if creator == user_id!("@carl:example.com")
|
||||||
|
@ -2,7 +2,7 @@ use js_int::uint;
|
|||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
use ruma_common::MilliSecondsSinceUnixEpoch;
|
use ruma_common::MilliSecondsSinceUnixEpoch;
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::redaction::{RedactionEvent, RedactionEventContent},
|
room::redaction::{RoomRedactionEvent, RoomRedactionEventContent},
|
||||||
AnyMessageEvent, Unsigned,
|
AnyMessageEvent, Unsigned,
|
||||||
};
|
};
|
||||||
use ruma_identifiers::{event_id, room_id, user_id};
|
use ruma_identifiers::{event_id, room_id, user_id};
|
||||||
@ -26,8 +26,8 @@ fn redaction() -> JsonValue {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_redaction() {
|
fn serialize_redaction() {
|
||||||
let aliases_event = RedactionEvent {
|
let aliases_event = RoomRedactionEvent {
|
||||||
content: RedactionEventContent::with_reason("being a turd".into()),
|
content: RoomRedactionEventContent::with_reason("being a turd".into()),
|
||||||
redacts: event_id!("$nomore:example.com"),
|
redacts: event_id!("$nomore:example.com"),
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
@ -48,8 +48,8 @@ fn deserialize_redaction() {
|
|||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageEvent>(json_data).unwrap(),
|
from_json_value::<AnyMessageEvent>(json_data).unwrap(),
|
||||||
AnyMessageEvent::RoomRedaction(RedactionEvent {
|
AnyMessageEvent::RoomRedaction(RoomRedactionEvent {
|
||||||
content: RedactionEventContent { reason: Some(reas), .. },
|
content: RoomRedactionEventContent { reason: Some(reas), .. },
|
||||||
redacts,
|
redacts,
|
||||||
event_id,
|
event_id,
|
||||||
origin_server_ts,
|
origin_server_ts,
|
||||||
|
@ -10,8 +10,8 @@ use ruma_events::{
|
|||||||
};
|
};
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::message::{
|
room::message::{
|
||||||
AudioMessageEventContent, InReplyTo, MessageEvent, MessageEventContent, MessageType,
|
AudioMessageEventContent, InReplyTo, MessageType, Relation, RoomMessageEvent,
|
||||||
Relation, TextMessageEventContent,
|
RoomMessageEventContent, TextMessageEventContent,
|
||||||
},
|
},
|
||||||
Unsigned,
|
Unsigned,
|
||||||
};
|
};
|
||||||
@ -34,8 +34,8 @@ macro_rules! json_object {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization() {
|
fn serialization() {
|
||||||
let ev = MessageEvent {
|
let ev = RoomMessageEvent {
|
||||||
content: MessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain(
|
content: RoomMessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain(
|
||||||
"test".into(),
|
"test".into(),
|
||||||
mxc_uri!("mxc://example.org/ffed755USFFxlgbQYZGtryd"),
|
mxc_uri!("mxc://example.org/ffed755USFFxlgbQYZGtryd"),
|
||||||
None,
|
None,
|
||||||
@ -67,7 +67,7 @@ fn serialization() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn content_serialization() {
|
fn content_serialization() {
|
||||||
let message_event_content =
|
let message_event_content =
|
||||||
MessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain(
|
RoomMessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain(
|
||||||
"test".into(),
|
"test".into(),
|
||||||
mxc_uri!("mxc://example.org/ffed755USFFxlgbQYZGtryd"),
|
mxc_uri!("mxc://example.org/ffed755USFFxlgbQYZGtryd"),
|
||||||
None,
|
None,
|
||||||
@ -127,7 +127,7 @@ fn custom_content_deserialization() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn formatted_body_serialization() {
|
fn formatted_body_serialization() {
|
||||||
let message_event_content =
|
let message_event_content =
|
||||||
MessageEventContent::text_html("Hello, World!", "Hello, <em>World</em>!");
|
RoomMessageEventContent::text_html("Hello, World!", "Hello, <em>World</em>!");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
to_json_value(&message_event_content).unwrap(),
|
to_json_value(&message_event_content).unwrap(),
|
||||||
@ -143,7 +143,7 @@ fn formatted_body_serialization() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn plain_text_content_serialization() {
|
fn plain_text_content_serialization() {
|
||||||
let message_event_content =
|
let message_event_content =
|
||||||
MessageEventContent::text_plain("> <@test:example.com> test\n\ntest reply");
|
RoomMessageEventContent::text_plain("> <@test:example.com> test\n\ntest reply");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
to_json_value(&message_event_content).unwrap(),
|
to_json_value(&message_event_content).unwrap(),
|
||||||
@ -157,7 +157,7 @@ fn plain_text_content_serialization() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "markdown")]
|
#[cfg(feature = "markdown")]
|
||||||
fn markdown_content_serialization() {
|
fn markdown_content_serialization() {
|
||||||
let formatted_message = MessageEventContent::new(MessageType::Text(
|
let formatted_message = RoomMessageEventContent::new(MessageType::Text(
|
||||||
TextMessageEventContent::markdown("Testing **bold** and _italic_!"),
|
TextMessageEventContent::markdown("Testing **bold** and _italic_!"),
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ fn markdown_content_serialization() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
let plain_message_simple = MessageEventContent::new(MessageType::Text(
|
let plain_message_simple = RoomMessageEventContent::new(MessageType::Text(
|
||||||
TextMessageEventContent::markdown("Testing a simple phrase…"),
|
TextMessageEventContent::markdown("Testing a simple phrase…"),
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ fn markdown_content_serialization() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
let plain_message_paragraphs = MessageEventContent::new(MessageType::Text(
|
let plain_message_paragraphs = RoomMessageEventContent::new(MessageType::Text(
|
||||||
TextMessageEventContent::markdown("Testing\n\nSeveral\n\nParagraphs."),
|
TextMessageEventContent::markdown("Testing\n\nSeveral\n\nParagraphs."),
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ fn markdown_content_serialization() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn relates_to_content_serialization() {
|
fn relates_to_content_serialization() {
|
||||||
let message_event_content =
|
let message_event_content =
|
||||||
assign!(MessageEventContent::text_plain("> <@test:example.com> test\n\ntest reply"), {
|
assign!(RoomMessageEventContent::text_plain("> <@test:example.com> test\n\ntest reply"), {
|
||||||
relates_to: Some(Relation::Reply {
|
relates_to: Some(Relation::Reply {
|
||||||
in_reply_to: InReplyTo::new(event_id!("$15827405538098VGFWH:example.com")),
|
in_reply_to: InReplyTo::new(event_id!("$15827405538098VGFWH:example.com")),
|
||||||
}),
|
}),
|
||||||
@ -236,8 +236,8 @@ fn edit_deserialization_061() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<MessageEventContent>(json_data).unwrap(),
|
from_json_value::<RoomMessageEventContent>(json_data).unwrap(),
|
||||||
MessageEventContent {
|
RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(TextMessageEventContent {
|
msgtype: MessageType::Text(TextMessageEventContent {
|
||||||
body,
|
body,
|
||||||
formatted: None,
|
formatted: None,
|
||||||
@ -269,8 +269,8 @@ fn edit_deserialization_future() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<MessageEventContent>(json_data).unwrap(),
|
from_json_value::<RoomMessageEventContent>(json_data).unwrap(),
|
||||||
MessageEventContent {
|
RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(TextMessageEventContent {
|
msgtype: MessageType::Text(TextMessageEventContent {
|
||||||
body,
|
body,
|
||||||
formatted: None,
|
formatted: None,
|
||||||
@ -282,7 +282,7 @@ fn edit_deserialization_future() {
|
|||||||
&& event_id == ev_id
|
&& event_id == ev_id
|
||||||
&& matches!(
|
&& matches!(
|
||||||
&*new_content,
|
&*new_content,
|
||||||
MessageEventContent {
|
RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(TextMessageEventContent {
|
msgtype: MessageType::Text(TextMessageEventContent {
|
||||||
body,
|
body,
|
||||||
formatted: None,
|
formatted: None,
|
||||||
@ -313,8 +313,8 @@ fn verification_request_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<MessageEventContent>(json_data).unwrap(),
|
from_json_value::<RoomMessageEventContent>(json_data).unwrap(),
|
||||||
MessageEventContent {
|
RoomMessageEventContent {
|
||||||
msgtype: MessageType::VerificationRequest(KeyVerificationRequestEventContent {
|
msgtype: MessageType::VerificationRequest(KeyVerificationRequestEventContent {
|
||||||
body,
|
body,
|
||||||
to,
|
to,
|
||||||
@ -367,9 +367,9 @@ fn content_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<MessageEventContent>(json_data)
|
from_json_value::<RoomMessageEventContent>(json_data)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
MessageEventContent {
|
RoomMessageEventContent {
|
||||||
msgtype: MessageType::Audio(AudioMessageEventContent {
|
msgtype: MessageType::Audio(AudioMessageEventContent {
|
||||||
body,
|
body,
|
||||||
info: None,
|
info: None,
|
||||||
@ -388,5 +388,5 @@ fn content_deserialization_failure() {
|
|||||||
"body": "test","msgtype": "m.location",
|
"body": "test","msgtype": "m.location",
|
||||||
"url": "http://example.com/audio.mp3"
|
"url": "http://example.com/audio.mp3"
|
||||||
});
|
});
|
||||||
assert!(from_json_value::<MessageEventContent>(json_data).is_err());
|
assert!(from_json_value::<RoomMessageEventContent>(json_data).is_err());
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ use matches::assert_matches;
|
|||||||
use ruma_common::MilliSecondsSinceUnixEpoch;
|
use ruma_common::MilliSecondsSinceUnixEpoch;
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::{
|
room::{
|
||||||
aliases::AliasesEventContent,
|
aliases::RoomAliasesEventContent,
|
||||||
avatar::{AvatarEventContent, ImageInfo},
|
avatar::{ImageInfo, RoomAvatarEventContent},
|
||||||
ThumbnailInfo,
|
ThumbnailInfo,
|
||||||
},
|
},
|
||||||
AnyRoomEvent, AnyStateEvent, AnyStateEventContent, AnySyncStateEvent, RawExt, StateEvent,
|
AnyRoomEvent, AnyStateEvent, AnyStateEventContent, AnySyncStateEvent, RawExt, StateEvent,
|
||||||
@ -36,10 +36,10 @@ fn aliases_event_with_prev_content() -> JsonValue {
|
|||||||
#[test]
|
#[test]
|
||||||
fn serialize_aliases_with_prev_content() {
|
fn serialize_aliases_with_prev_content() {
|
||||||
let aliases_event = StateEvent {
|
let aliases_event = StateEvent {
|
||||||
content: AliasesEventContent::new(vec![room_alias_id!("#somewhere:localhost")]),
|
content: RoomAliasesEventContent::new(vec![room_alias_id!("#somewhere:localhost")]),
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
prev_content: Some(AliasesEventContent::new(vec![room_alias_id!("#inner:localhost")])),
|
prev_content: Some(RoomAliasesEventContent::new(vec![room_alias_id!("#inner:localhost")])),
|
||||||
room_id: room_id!("!roomid:room.com"),
|
room_id: room_id!("!roomid:room.com"),
|
||||||
sender: user_id!("@carl:example.com"),
|
sender: user_id!("@carl:example.com"),
|
||||||
state_key: "".into(),
|
state_key: "".into(),
|
||||||
@ -55,7 +55,7 @@ fn serialize_aliases_with_prev_content() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn serialize_aliases_without_prev_content() {
|
fn serialize_aliases_without_prev_content() {
|
||||||
let aliases_event = StateEvent {
|
let aliases_event = StateEvent {
|
||||||
content: AliasesEventContent::new(vec![room_alias_id!("#somewhere:localhost")]),
|
content: RoomAliasesEventContent::new(vec![room_alias_id!("#somewhere:localhost")]),
|
||||||
event_id: event_id!("$h29iv0s8:example.com"),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||||
prev_content: None,
|
prev_content: None,
|
||||||
@ -184,7 +184,7 @@ fn deserialize_avatar_without_prev_content() {
|
|||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyStateEvent>(json_data).unwrap(),
|
from_json_value::<AnyStateEvent>(json_data).unwrap(),
|
||||||
AnyStateEvent::RoomAvatar(StateEvent {
|
AnyStateEvent::RoomAvatar(StateEvent {
|
||||||
content: AvatarEventContent {
|
content: RoomAvatarEventContent {
|
||||||
info: Some(info),
|
info: Some(info),
|
||||||
url,
|
url,
|
||||||
..
|
..
|
||||||
|
@ -2,7 +2,7 @@ use std::convert::TryFrom;
|
|||||||
|
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::{join_rules::JoinRule, topic::TopicEventContent},
|
room::{join_rules::JoinRule, topic::RoomTopicEventContent},
|
||||||
AnyStrippedStateEvent, StrippedStateEvent,
|
AnyStrippedStateEvent, StrippedStateEvent,
|
||||||
};
|
};
|
||||||
use ruma_identifiers::{mxc_uri, user_id, RoomNameBox};
|
use ruma_identifiers::{mxc_uri, user_id, RoomNameBox};
|
||||||
@ -11,7 +11,7 @@ use serde_json::{from_value as from_json_value, json, to_value as to_json_value}
|
|||||||
#[test]
|
#[test]
|
||||||
fn serialize_stripped_state_event_any_content() {
|
fn serialize_stripped_state_event_any_content() {
|
||||||
let event = StrippedStateEvent {
|
let event = StrippedStateEvent {
|
||||||
content: TopicEventContent::new("Testing room".into()),
|
content: RoomTopicEventContent::new("Testing room".into()),
|
||||||
state_key: "".into(),
|
state_key: "".into(),
|
||||||
sender: user_id!("@example:localhost"),
|
sender: user_id!("@example:localhost"),
|
||||||
};
|
};
|
||||||
@ -31,7 +31,7 @@ fn serialize_stripped_state_event_any_content() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn serialize_stripped_state_event_any_event() {
|
fn serialize_stripped_state_event_any_event() {
|
||||||
let event = AnyStrippedStateEvent::RoomTopic(StrippedStateEvent {
|
let event = AnyStrippedStateEvent::RoomTopic(StrippedStateEvent {
|
||||||
content: TopicEventContent::new("Testing room".into()),
|
content: RoomTopicEventContent::new("Testing room".into()),
|
||||||
state_key: "".into(),
|
state_key: "".into(),
|
||||||
sender: user_id!("@example:localhost"),
|
sender: user_id!("@example:localhost"),
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! [PUT /_matrix/federation/v1/send_knock/{roomId}/{eventId}](https://spec.matrix.org/unstable/server-server-api/#put_matrixfederationv1send_knockroomideventid)
|
//! [PUT /_matrix/federation/v1/send_knock/{roomId}/{eventId}](https://spec.matrix.org/unstable/server-server-api/#put_matrixfederationv1send_knockroomideventid)
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_events::{room::member::MemberEvent, AnyStrippedStateEvent};
|
use ruma_events::{room::member::RoomMemberEvent, AnyStrippedStateEvent};
|
||||||
use ruma_identifiers::{EventId, RoomId};
|
use ruma_identifiers::{EventId, RoomId};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
@ -25,7 +25,7 @@ ruma_api! {
|
|||||||
|
|
||||||
/// The full knock event.
|
/// The full knock event.
|
||||||
#[ruma_api(body)]
|
#[ruma_api(body)]
|
||||||
pub knock_event: &'a MemberEvent,
|
pub knock_event: &'a RoomMemberEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
response: {
|
response: {
|
||||||
@ -36,7 +36,11 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given room ID, event ID and knock event.
|
/// Creates a new `Request` with the given room ID, event ID and knock event.
|
||||||
pub fn new(room_id: &'a RoomId, event_id: &'a EventId, knock_event: &'a MemberEvent) -> Self {
|
pub fn new(
|
||||||
|
room_id: &'a RoomId,
|
||||||
|
event_id: &'a EventId,
|
||||||
|
knock_event: &'a RoomMemberEvent,
|
||||||
|
) -> Self {
|
||||||
Self { room_id, event_id, knock_event }
|
Self { room_id, event_id, knock_event }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_common::MilliSecondsSinceUnixEpoch;
|
use ruma_common::MilliSecondsSinceUnixEpoch;
|
||||||
use ruma_events::{room::member::MemberEventContent, AnyStrippedStateEvent, EventType};
|
use ruma_events::{room::member::RoomMemberEventContent, AnyStrippedStateEvent, EventType};
|
||||||
use ruma_identifiers::{EventId, RoomId, ServerName, UserId};
|
use ruma_identifiers::{EventId, RoomId, ServerName, UserId};
|
||||||
use ruma_serde::Raw;
|
use ruma_serde::Raw;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -44,7 +44,7 @@ ruma_api! {
|
|||||||
pub state_key: &'a UserId,
|
pub state_key: &'a UserId,
|
||||||
|
|
||||||
/// The content of the event.
|
/// The content of the event.
|
||||||
pub content: MemberEventContent,
|
pub content: RoomMemberEventContent,
|
||||||
|
|
||||||
/// Information included alongside the event that is not signed.
|
/// Information included alongside the event that is not signed.
|
||||||
#[serde(default, skip_serializing_if = "UnsignedEventContent::is_empty")]
|
#[serde(default, skip_serializing_if = "UnsignedEventContent::is_empty")]
|
||||||
@ -105,7 +105,7 @@ pub struct RequestInit<'a> {
|
|||||||
pub state_key: &'a UserId,
|
pub state_key: &'a UserId,
|
||||||
|
|
||||||
/// The content of the event.
|
/// The content of the event.
|
||||||
pub content: MemberEventContent,
|
pub content: RoomMemberEventContent,
|
||||||
|
|
||||||
/// Information included alongside the event that is not signed.
|
/// Information included alongside the event that is not signed.
|
||||||
pub unsigned: UnsignedEventContent,
|
pub unsigned: UnsignedEventContent,
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_common::MilliSecondsSinceUnixEpoch;
|
use ruma_common::MilliSecondsSinceUnixEpoch;
|
||||||
use ruma_events::{room::member::MemberEventContent, EventType};
|
use ruma_events::{room::member::RoomMemberEventContent, EventType};
|
||||||
use ruma_identifiers::{EventId, RoomId, ServerName, UserId};
|
use ruma_identifiers::{EventId, RoomId, ServerName, UserId};
|
||||||
use ruma_serde::Raw;
|
use ruma_serde::Raw;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -50,7 +50,7 @@ ruma_api! {
|
|||||||
|
|
||||||
/// The content of the event.
|
/// The content of the event.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
pub content: Raw<MemberEventContent>,
|
pub content: Raw<RoomMemberEventContent>,
|
||||||
|
|
||||||
/// This field must be present but is ignored; it may be 0.
|
/// This field must be present but is ignored; it may be 0.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
@ -97,7 +97,7 @@ pub struct RequestInit<'a> {
|
|||||||
pub state_key: &'a str,
|
pub state_key: &'a str,
|
||||||
|
|
||||||
/// The content of the event.
|
/// The content of the event.
|
||||||
pub content: Raw<MemberEventContent>,
|
pub content: Raw<RoomMemberEventContent>,
|
||||||
|
|
||||||
/// This field must be present but is ignored; it may be 0.
|
/// This field must be present but is ignored; it may be 0.
|
||||||
pub depth: UInt,
|
pub depth: UInt,
|
||||||
|
@ -24,8 +24,8 @@ use ruma_common::MilliSecondsSinceUnixEpoch;
|
|||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
pdu::{EventHash, Pdu, RoomV3Pdu},
|
pdu::{EventHash, Pdu, RoomV3Pdu},
|
||||||
room::{
|
room::{
|
||||||
join_rules::{JoinRule, JoinRulesEventContent},
|
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||||
member::{MemberEventContent, MembershipState},
|
member::{MembershipState, RoomMemberEventContent},
|
||||||
},
|
},
|
||||||
EventType,
|
EventType,
|
||||||
};
|
};
|
||||||
@ -264,7 +264,7 @@ impl TestStore<StateEvent> {
|
|||||||
alice(),
|
alice(),
|
||||||
EventType::RoomJoinRules,
|
EventType::RoomJoinRules,
|
||||||
Some(""),
|
Some(""),
|
||||||
to_raw_json_value(&JoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
||||||
&[cre.clone(), alice_mem.event_id().clone()],
|
&[cre.clone(), alice_mem.event_id().clone()],
|
||||||
&[alice_mem.event_id().clone()],
|
&[alice_mem.event_id().clone()],
|
||||||
);
|
);
|
||||||
@ -356,11 +356,11 @@ fn room_id() -> RoomId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn member_content_ban() -> Box<RawJsonValue> {
|
fn member_content_ban() -> Box<RawJsonValue> {
|
||||||
to_raw_json_value(&MemberEventContent::new(MembershipState::Ban)).unwrap()
|
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Ban)).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn member_content_join() -> Box<RawJsonValue> {
|
fn member_content_join() -> Box<RawJsonValue> {
|
||||||
to_raw_json_value(&MemberEventContent::new(MembershipState::Join)).unwrap()
|
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Join)).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_pdu_event<S>(
|
fn to_pdu_event<S>(
|
||||||
@ -441,7 +441,7 @@ fn INITIAL_EVENTS() -> HashMap<EventId, Arc<StateEvent>> {
|
|||||||
alice(),
|
alice(),
|
||||||
EventType::RoomJoinRules,
|
EventType::RoomJoinRules,
|
||||||
Some(""),
|
Some(""),
|
||||||
to_raw_json_value(&JoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
||||||
&["CREATE", "IMA", "IPOWER"],
|
&["CREATE", "IMA", "IPOWER"],
|
||||||
&["IPOWER"],
|
&["IPOWER"],
|
||||||
),
|
),
|
||||||
|
@ -3,11 +3,11 @@ use std::{collections::BTreeSet, convert::TryFrom};
|
|||||||
use js_int::{int, Int};
|
use js_int::{int, Int};
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::{
|
room::{
|
||||||
create::CreateEventContent,
|
create::RoomCreateEventContent,
|
||||||
join_rules::{JoinRule, JoinRulesEventContent},
|
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||||
member::{MembershipState, ThirdPartyInvite},
|
member::{MembershipState, ThirdPartyInvite},
|
||||||
power_levels::PowerLevelsEventContent,
|
power_levels::RoomPowerLevelsEventContent,
|
||||||
third_party_invite::ThirdPartyInviteEventContent,
|
third_party_invite::RoomThirdPartyInviteEventContent,
|
||||||
},
|
},
|
||||||
EventType,
|
EventType,
|
||||||
};
|
};
|
||||||
@ -281,7 +281,7 @@ pub fn auth_check<E: Event>(
|
|||||||
} else {
|
} else {
|
||||||
// If no power level event found the creator gets 100 everyone else gets 0
|
// If no power level event found the creator gets 100 everyone else gets 0
|
||||||
room_create_event
|
room_create_event
|
||||||
.and_then(|create| from_json_str::<CreateEventContent>(create.content().get()).ok())
|
.and_then(|create| from_json_str::<RoomCreateEventContent>(create.content().get()).ok())
|
||||||
.and_then(|create| (create.creator == *sender).then(|| int!(100)))
|
.and_then(|create| (create.creator == *sender).then(|| int!(100)))
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
};
|
};
|
||||||
@ -414,9 +414,9 @@ fn valid_membership_change(
|
|||||||
None => MembershipState::Leave,
|
None => MembershipState::Leave,
|
||||||
};
|
};
|
||||||
|
|
||||||
let power_levels: PowerLevelsEventContent = match &power_levels_event {
|
let power_levels: RoomPowerLevelsEventContent = match &power_levels_event {
|
||||||
Some(ev) => from_json_str(ev.content().get())?,
|
Some(ev) => from_json_str(ev.content().get())?,
|
||||||
None => PowerLevelsEventContent::default(),
|
None => RoomPowerLevelsEventContent::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let sender_power = power_levels
|
let sender_power = power_levels
|
||||||
@ -430,7 +430,7 @@ fn valid_membership_change(
|
|||||||
|
|
||||||
let mut join_rules = JoinRule::Invite;
|
let mut join_rules = JoinRule::Invite;
|
||||||
if let Some(jr) = &join_rules_event {
|
if let Some(jr) = &join_rules_event {
|
||||||
join_rules = from_json_str::<JoinRulesEventContent>(jr.content().get())?.join_rule;
|
join_rules = from_json_str::<RoomJoinRulesEventContent>(jr.content().get())?.join_rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(prev) = prev_event {
|
if let Some(prev) = prev_event {
|
||||||
@ -613,10 +613,10 @@ fn check_power_levels(
|
|||||||
// If users key in content is not a dictionary with keys that are valid user IDs
|
// If users key in content is not a dictionary with keys that are valid user IDs
|
||||||
// with values that are integers (or a string that is an integer), reject.
|
// with values that are integers (or a string that is an integer), reject.
|
||||||
let user_content =
|
let user_content =
|
||||||
from_json_str::<PowerLevelsEventContent>(power_event.content().get()).unwrap();
|
from_json_str::<RoomPowerLevelsEventContent>(power_event.content().get()).unwrap();
|
||||||
|
|
||||||
let current_content =
|
let current_content =
|
||||||
from_json_str::<PowerLevelsEventContent>(current_state.content().get()).unwrap();
|
from_json_str::<RoomPowerLevelsEventContent>(current_state.content().get()).unwrap();
|
||||||
|
|
||||||
// Validation of users is done in Ruma, synapse for loops validating user_ids and integers here
|
// Validation of users is done in Ruma, synapse for loops validating user_ids and integers here
|
||||||
info!("validation of power event finished");
|
info!("validation of power event finished");
|
||||||
@ -768,7 +768,7 @@ fn get_send_level(
|
|||||||
) -> Int {
|
) -> Int {
|
||||||
power_lvl
|
power_lvl
|
||||||
.and_then(|ple| {
|
.and_then(|ple| {
|
||||||
from_json_str::<PowerLevelsEventContent>(ple.content().get())
|
from_json_str::<RoomPowerLevelsEventContent>(ple.content().get())
|
||||||
.map(|content| {
|
.map(|content| {
|
||||||
content.events.get(e_type).copied().unwrap_or_else(|| {
|
content.events.get(e_type).copied().unwrap_or_else(|| {
|
||||||
if state_key.is_some() {
|
if state_key.is_some() {
|
||||||
@ -811,7 +811,7 @@ fn verify_third_party_invite(
|
|||||||
// If any signature in signed matches any public key in the m.room.third_party_invite event,
|
// If any signature in signed matches any public key in the m.room.third_party_invite event,
|
||||||
// allow
|
// allow
|
||||||
if let Ok(tpid_ev) =
|
if let Ok(tpid_ev) =
|
||||||
from_json_str::<ThirdPartyInviteEventContent>(current_tpid.content().get())
|
from_json_str::<RoomThirdPartyInviteEventContent>(current_tpid.content().get())
|
||||||
{
|
{
|
||||||
// A list of public keys in the public_keys field
|
// A list of public keys in the public_keys field
|
||||||
for key in tpid_ev.public_keys.unwrap_or_default() {
|
for key in tpid_ev.public_keys.unwrap_or_default() {
|
||||||
|
@ -7,7 +7,7 @@ use itertools::Itertools;
|
|||||||
use js_int::{int, Int};
|
use js_int::{int, Int};
|
||||||
use ruma_common::MilliSecondsSinceUnixEpoch;
|
use ruma_common::MilliSecondsSinceUnixEpoch;
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::member::{MemberEventContent, MembershipState},
|
room::member::{MembershipState, RoomMemberEventContent},
|
||||||
EventType,
|
EventType,
|
||||||
};
|
};
|
||||||
use ruma_identifiers::{EventId, RoomVersionId, UserId};
|
use ruma_identifiers::{EventId, RoomVersionId, UserId};
|
||||||
@ -601,7 +601,7 @@ fn is_power_event(event: impl Event) -> bool {
|
|||||||
event.state_key() == Some("")
|
event.state_key() == Some("")
|
||||||
}
|
}
|
||||||
EventType::RoomMember => {
|
EventType::RoomMember => {
|
||||||
if let Ok(content) = from_json_str::<MemberEventContent>(event.content().get()) {
|
if let Ok(content) = from_json_str::<RoomMemberEventContent>(event.content().get()) {
|
||||||
if [MembershipState::Leave, MembershipState::Ban].contains(&content.membership) {
|
if [MembershipState::Leave, MembershipState::Ban].contains(&content.membership) {
|
||||||
return Some(event.sender().as_str()) != event.state_key();
|
return Some(event.sender().as_str()) != event.state_key();
|
||||||
}
|
}
|
||||||
@ -625,7 +625,7 @@ mod tests {
|
|||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use ruma_common::MilliSecondsSinceUnixEpoch;
|
use ruma_common::MilliSecondsSinceUnixEpoch;
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::join_rules::{JoinRule, JoinRulesEventContent},
|
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||||
EventType,
|
EventType,
|
||||||
};
|
};
|
||||||
use ruma_identifiers::{EventId, RoomVersionId};
|
use ruma_identifiers::{EventId, RoomVersionId};
|
||||||
@ -877,7 +877,7 @@ mod tests {
|
|||||||
alice(),
|
alice(),
|
||||||
EventType::RoomJoinRules,
|
EventType::RoomJoinRules,
|
||||||
Some(""),
|
Some(""),
|
||||||
to_raw_json_value(&JoinRulesEventContent::new(JoinRule::Private)).unwrap(),
|
to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Private)).unwrap(),
|
||||||
),
|
),
|
||||||
to_init_pdu_event(
|
to_init_pdu_event(
|
||||||
"ME",
|
"ME",
|
||||||
|
@ -12,8 +12,8 @@ use ruma_common::MilliSecondsSinceUnixEpoch;
|
|||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
pdu::{EventHash, Pdu, RoomV3Pdu},
|
pdu::{EventHash, Pdu, RoomV3Pdu},
|
||||||
room::{
|
room::{
|
||||||
join_rules::{JoinRule, JoinRulesEventContent},
|
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||||
member::{MemberEventContent, MembershipState},
|
member::{MembershipState, RoomMemberEventContent},
|
||||||
},
|
},
|
||||||
EventType,
|
EventType,
|
||||||
};
|
};
|
||||||
@ -269,7 +269,7 @@ impl TestStore<StateEvent> {
|
|||||||
alice(),
|
alice(),
|
||||||
EventType::RoomJoinRules,
|
EventType::RoomJoinRules,
|
||||||
Some(""),
|
Some(""),
|
||||||
to_raw_json_value(&JoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
||||||
&[cre.clone(), alice_mem.event_id().clone()],
|
&[cre.clone(), alice_mem.event_id().clone()],
|
||||||
&[alice_mem.event_id().clone()],
|
&[alice_mem.event_id().clone()],
|
||||||
);
|
);
|
||||||
@ -365,11 +365,11 @@ pub fn room_id() -> RoomId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn member_content_ban() -> Box<RawJsonValue> {
|
pub fn member_content_ban() -> Box<RawJsonValue> {
|
||||||
to_raw_json_value(&MemberEventContent::new(MembershipState::Ban)).unwrap()
|
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Ban)).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn member_content_join() -> Box<RawJsonValue> {
|
pub fn member_content_join() -> Box<RawJsonValue> {
|
||||||
to_raw_json_value(&MemberEventContent::new(MembershipState::Join)).unwrap()
|
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Join)).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_init_pdu_event(
|
pub fn to_init_pdu_event(
|
||||||
@ -481,7 +481,7 @@ pub fn INITIAL_EVENTS() -> HashMap<EventId, Arc<StateEvent>> {
|
|||||||
alice(),
|
alice(),
|
||||||
EventType::RoomJoinRules,
|
EventType::RoomJoinRules,
|
||||||
Some(""),
|
Some(""),
|
||||||
to_raw_json_value(&JoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
||||||
&["CREATE", "IMA", "IPOWER"],
|
&["CREATE", "IMA", "IPOWER"],
|
||||||
&["IPOWER"],
|
&["IPOWER"],
|
||||||
),
|
),
|
||||||
|
@ -5,7 +5,7 @@ use std::{convert::TryFrom, env, process::exit};
|
|||||||
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::r0::{alias::get_alias, membership::join_room_by_id, message::send_message_event},
|
api::client::r0::{alias::get_alias, membership::join_room_by_id, message::send_message_event},
|
||||||
events::room::message::MessageEventContent,
|
events::room::message::RoomMessageEventContent,
|
||||||
RoomAliasId,
|
RoomAliasId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ async fn hello_world(
|
|||||||
.send_request(send_message_event::Request::new(
|
.send_request(send_message_event::Request::new(
|
||||||
&room_id,
|
&room_id,
|
||||||
"1",
|
"1",
|
||||||
&MessageEventContent::text_plain("Hello World!"),
|
&RoomMessageEventContent::text_plain("Hello World!"),
|
||||||
)?)
|
)?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use std::{convert::TryFrom, env, process::exit};
|
|||||||
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::r0::{alias::get_alias, membership::join_room_by_id, message::send_message_event},
|
api::client::r0::{alias::get_alias, membership::join_room_by_id, message::send_message_event},
|
||||||
events::room::message::MessageEventContent,
|
events::room::message::RoomMessageEventContent,
|
||||||
RoomAliasId,
|
RoomAliasId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ async fn hello_world(
|
|||||||
.send_request(send_message_event::Request::new(
|
.send_request(send_message_event::Request::new(
|
||||||
&room_id,
|
&room_id,
|
||||||
"1",
|
"1",
|
||||||
&MessageEventContent::text_plain("Hello World!"),
|
&RoomMessageEventContent::text_plain("Hello World!"),
|
||||||
)?)
|
)?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ use assign::assign;
|
|||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::r0::{filter::FilterDefinition, sync::sync_events},
|
api::client::r0::{filter::FilterDefinition, sync::sync_events},
|
||||||
events::{
|
events::{
|
||||||
room::message::{MessageEventContent, MessageType, TextMessageEventContent},
|
room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
|
||||||
AnySyncMessageEvent, AnySyncRoomEvent, SyncMessageEvent,
|
AnySyncMessageEvent, AnySyncRoomEvent, SyncMessageEvent,
|
||||||
},
|
},
|
||||||
presence::PresenceState,
|
presence::PresenceState,
|
||||||
@ -44,7 +44,7 @@ async fn log_messages(
|
|||||||
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(
|
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(
|
||||||
SyncMessageEvent {
|
SyncMessageEvent {
|
||||||
content:
|
content:
|
||||||
MessageEventContent {
|
RoomMessageEventContent {
|
||||||
msgtype:
|
msgtype:
|
||||||
MessageType::Text(TextMessageEventContent {
|
MessageType::Text(TextMessageEventContent {
|
||||||
body: msg_body, ..
|
body: msg_body, ..
|
||||||
|
Loading…
x
Reference in New Issue
Block a user