diff --git a/crates/ruma-client-api/src/r0/membership/get_member_events.rs b/crates/ruma-client-api/src/r0/membership/get_member_events.rs index d7daf86a..e5b8cdb1 100644 --- a/crates/ruma-client-api/src/r0/membership/get_member_events.rs +++ b/crates/ruma-client-api/src/r0/membership/get_member_events.rs @@ -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) use ruma_api::ruma_api; -use ruma_events::room::member::MemberEvent; +use ruma_events::room::member::RoomMemberEvent; use ruma_identifiers::RoomId; use ruma_serde::{Raw, StringEnum}; @@ -42,7 +42,7 @@ ruma_api! { response: { /// A list of member events. - pub chunk: Vec>, + pub chunk: Vec>, } error: crate::Error @@ -57,7 +57,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given member event chunk. - pub fn new(chunk: Vec>) -> Self { + pub fn new(chunk: Vec>) -> Self { Self { chunk } } } diff --git a/crates/ruma-client-api/src/r0/room/create_room.rs b/crates/ruma-client-api/src/r0/room/create_room.rs index b1af27eb..2f12e992 100644 --- a/crates/ruma-client-api/src/r0/room/create_room.rs +++ b/crates/ruma-client-api/src/r0/room/create_room.rs @@ -6,8 +6,8 @@ use ruma_api::ruma_api; use ruma_events::room::create::RoomType; use ruma_events::{ room::{ - create::{CreateEventContent, PreviousRoom}, - power_levels::PowerLevelsEventContent, + create::{PreviousRoom, RoomCreateEventContent}, + power_levels::RoomPowerLevelsEventContent, }, AnyInitialStateEvent, }; @@ -61,7 +61,7 @@ ruma_api! { /// Power level content to override in the default power level event. #[serde(skip_serializing_if = "Option::is_none")] - pub power_level_content_override: Option>, + pub power_level_content_override: Option>, /// Convenience parameter for setting various default state events based on a preset. #[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 - /// a `CreateEventContent`. + /// a `RoomCreateEventContent`. pub fn into_event_content( self, creator: UserId, room_version: RoomVersionId, - ) -> CreateEventContent { + ) -> RoomCreateEventContent { #[allow(unused_mut)] - let mut content = assign!(CreateEventContent::new(creator), { + let mut content = assign!(RoomCreateEventContent::new(creator), { federate: self.federate, room_version: room_version, predecessor: self.predecessor, diff --git a/crates/ruma-events-macros/src/event.rs b/crates/ruma-events-macros/src/event.rs index 1fbb31d2..4f11472b 100644 --- a/crates/ruma-events-macros/src/event.rs +++ b/crates/ruma-events-macros/src/event.rs @@ -458,7 +458,7 @@ fn expand_redact_event( fn redact( self, - redaction: #ruma_events::room::redaction::SyncRedactionEvent, + redaction: #ruma_events::room::redaction::SyncRoomRedactionEvent, version: &#ruma_identifiers::RoomVersionId, ) -> Self::Redacted { let content = #ruma_events::RedactContent::redact(self.content, version); diff --git a/crates/ruma-events-macros/src/event_content.rs b/crates/ruma-events-macros/src/event_content.rs index a4777306..6b49739f 100644 --- a/crates/ruma-events-macros/src/event_content.rs +++ b/crates/ruma-events-macros/src/event_content.rs @@ -332,7 +332,7 @@ fn generate_event_type_aliases( ruma_events: &TokenStream, ) -> syn::Result { // The redaction module has its own event types. - if ident == "RedactionEventContent" { + if ident == "RoomRedactionEventContent" { return Ok(quote! {}); } @@ -394,7 +394,7 @@ fn generate_marker_trait_impl( EventKind::Message => quote! { MessageEventContent }, EventKind::State => quote! { StateEventContent }, EventKind::ToDevice => quote! { ToDeviceEventContent }, - EventKind::Redaction | EventKind::Presence | EventKind::Decrypted => { + EventKind::RoomRedaction | EventKind::Presence | EventKind::Decrypted => { return Err(syn::Error::new_spanned( ident, "valid event kinds are GlobalAccountData, RoomAccountData, \ @@ -454,7 +454,7 @@ fn generate_static_event_content_impl( EventKind::Message => quote! { Message { redacted: #redacted } }, EventKind::State => quote! { State { redacted: #redacted } }, EventKind::ToDevice => quote! { ToDevice }, - EventKind::Redaction | EventKind::Presence | EventKind::Decrypted => { + EventKind::RoomRedaction | EventKind::Presence | EventKind::Decrypted => { unreachable!("not a valid event content kind") } }; diff --git a/crates/ruma-events-macros/src/event_enum.rs b/crates/ruma-events-macros/src/event_enum.rs index c8ae3d16..cc74fcae 100644 --- a/crates/ruma-events-macros/src/event_enum.rs +++ b/crates/ruma-events-macros/src/event_enum.rs @@ -475,7 +475,7 @@ fn expand_redact( fn redact( self, - redaction: #ruma_events::room::redaction::SyncRedactionEvent, + redaction: #ruma_events::room::redaction::SyncRoomRedactionEvent, version: &#ruma_identifiers::RoomVersionId, ) -> #redacted_enum { match self { @@ -729,9 +729,8 @@ fn to_event_path( let path: Vec<_> = name[2..].split('.').collect(); - let event_str = path.last().unwrap(); - let event: String = event_str - .split('_') + let event: String = name[2..] + .split(&['.', '_'] as &[char]) .map(|s| s.chars().next().unwrap().to_uppercase().to_string() + &s[1..]) .collect(); @@ -760,9 +759,8 @@ fn to_event_content_path( let path: Vec<_> = name[2..].split('.').collect(); - let event_str = path.last().unwrap(); - let event: String = event_str - .split('_') + let event: String = name[2..] + .split(&['.', '_'] as &[char]) .map(|s| s.chars().next().unwrap().to_uppercase().to_string() + &s[1..]) .collect(); diff --git a/crates/ruma-events-macros/src/event_parse.rs b/crates/ruma-events-macros/src/event_parse.rs index d381d27c..67f4eea5 100644 --- a/crates/ruma-events-macros/src/event_parse.rs +++ b/crates/ruma-events-macros/src/event_parse.rs @@ -79,7 +79,7 @@ pub enum EventKind { Message, State, ToDevice, - Redaction, + RoomRedaction, Presence, Decrypted, } @@ -93,7 +93,7 @@ impl fmt::Display for EventKind { EventKind::Message => write!(f, "MessageEvent"), EventKind::State => write!(f, "StateEvent"), EventKind::ToDevice => write!(f, "ToDeviceEvent"), - EventKind::Redaction => write!(f, "RedactionEvent"), + EventKind::RoomRedaction => write!(f, "RoomRedactionEvent"), EventKind::Presence => write!(f, "PresenceEvent"), EventKind::Decrypted => unreachable!(), } @@ -133,10 +133,10 @@ impl EventKind { | (Self::State, V::Stripped) | (Self::State, V::Initial) | (Self::Message, V::Redacted) - | (Self::Redaction, V::Redacted) + | (Self::RoomRedaction, V::Redacted) | (Self::State, V::Redacted) | (Self::Message, V::RedactedSync) - | (Self::Redaction, V::RedactedSync) + | (Self::RoomRedaction, V::RedactedSync) | (Self::State, V::RedactedSync) => Some(format_ident!("{}{}", var, self)), _ => None, } @@ -203,11 +203,13 @@ pub fn to_kind_variation(ident: &Ident) -> Option<(EventKind, EventKindVariation "RedactedSyncStateEvent" => Some((EventKind::State, EventKindVariation::RedactedSync)), "ToDeviceEvent" => Some((EventKind::ToDevice, EventKindVariation::Full)), "PresenceEvent" => Some((EventKind::Presence, EventKindVariation::Full)), - "RedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Full)), - "SyncRedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Sync)), - "RedactedRedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Redacted)), - "RedactedSyncRedactionEvent" => { - Some((EventKind::Redaction, EventKindVariation::RedactedSync)) + "RoomRedactionEvent" => Some((EventKind::RoomRedaction, EventKindVariation::Full)), + "SyncRoomRedactionEvent" => Some((EventKind::RoomRedaction, EventKindVariation::Sync)), + "RedactedRoomRedactionEvent" => { + Some((EventKind::RoomRedaction, EventKindVariation::Redacted)) + } + "RedactedSyncRoomRedactionEvent" => { + Some((EventKind::RoomRedaction, EventKindVariation::RedactedSync)) } "DecryptedOlmV1Event" | "DecryptedMegolmV1Event" => { Some((EventKind::Decrypted, EventKindVariation::Full)) diff --git a/crates/ruma-events-macros/src/event_type.rs b/crates/ruma-events-macros/src/event_type.rs index 0d4fc63d..b0d6ea83 100644 --- a/crates/ruma-events-macros/src/event_type.rs +++ b/crates/ruma-events-macros/src/event_type.rs @@ -31,7 +31,7 @@ pub fn expand_event_type_enum( room.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 { diff --git a/crates/ruma-events/benches/event_deserialize.rs b/crates/ruma-events/benches/event_deserialize.rs index 82bdadfb..d3aae88d 100644 --- a/crates/ruma-events/benches/event_deserialize.rs +++ b/crates/ruma-events/benches/event_deserialize.rs @@ -9,7 +9,7 @@ #[cfg(feature = "criterion")] use criterion::{criterion_group, criterion_main, Criterion}; use ruma_events::{ - room::power_levels::PowerLevelsEventContent, AnyRoomEvent, AnyStateEvent, StateEvent, + room::power_levels::RoomPowerLevelsEventContent, AnyRoomEvent, AnyStateEvent, StateEvent, }; use ruma_serde::Raw; use serde_json::json; @@ -75,9 +75,10 @@ fn deserialize_specific_event(c: &mut Criterion) { c.bench_function("deserialize to `StateEvent`", |b| { b.iter(|| { - let _ = - serde_json::from_value::>(json_data.clone()) - .unwrap(); + let _ = serde_json::from_value::>( + json_data.clone(), + ) + .unwrap(); }) }); } diff --git a/crates/ruma-events/src/call/answer.rs b/crates/ruma-events/src/call/answer.rs index 1ec19d67..ecb0640e 100644 --- a/crates/ruma-events/src/call/answer.rs +++ b/crates/ruma-events/src/call/answer.rs @@ -12,7 +12,7 @@ use super::SessionDescription; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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*. pub answer: SessionDescription, @@ -23,7 +23,7 @@ pub struct AnswerEventContent { pub version: UInt, } -impl AnswerEventContent { +impl CallAnswerEventContent { /// Creates an `AnswerEventContent` with the given answer, call ID and VoIP version. pub fn new(answer: SessionDescription, call_id: String, version: UInt) -> Self { Self { answer, call_id, version } diff --git a/crates/ruma-events/src/call/candidates.rs b/crates/ruma-events/src/call/candidates.rs index 15c385d6..c795fd74 100644 --- a/crates/ruma-events/src/call/candidates.rs +++ b/crates/ruma-events/src/call/candidates.rs @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.call.candidates", kind = Message)] -pub struct CandidatesEventContent { +pub struct CallCandidatesEventContent { /// The ID of the call this event relates to. pub call_id: String, @@ -22,7 +22,7 @@ pub struct CandidatesEventContent { pub version: UInt, } -impl CandidatesEventContent { +impl CallCandidatesEventContent { /// Creates a new `CandidatesEventContent` with the given call id, candidate list and VoIP /// version. pub fn new(call_id: String, candidates: Vec, version: UInt) -> Self { diff --git a/crates/ruma-events/src/call/hangup.rs b/crates/ruma-events/src/call/hangup.rs index 3fdacf9d..79e1f289 100644 --- a/crates/ruma-events/src/call/hangup.rs +++ b/crates/ruma-events/src/call/hangup.rs @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.call.hangup", kind = Message)] -pub struct HangupEventContent { +pub struct CallHangupEventContent { /// The ID of the call this event relates to. pub call_id: String, @@ -24,7 +24,7 @@ pub struct HangupEventContent { pub reason: Option, } -impl HangupEventContent { +impl CallHangupEventContent { /// Creates a new `HangupEventContent` with the given call ID and VoIP version. pub fn new(call_id: String, version: UInt) -> Self { Self { call_id, version, reason: None } diff --git a/crates/ruma-events/src/call/invite.rs b/crates/ruma-events/src/call/invite.rs index 08a2ac13..27ed8df1 100644 --- a/crates/ruma-events/src/call/invite.rs +++ b/crates/ruma-events/src/call/invite.rs @@ -12,7 +12,7 @@ use super::SessionDescription; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.call.invite", kind = Message)] -pub struct InviteEventContent { +pub struct CallInviteEventContent { /// A unique identifier for the call. pub call_id: String, @@ -28,7 +28,7 @@ pub struct InviteEventContent { pub version: UInt, } -impl InviteEventContent { +impl CallInviteEventContent { /// 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 { Self { call_id, lifetime, offer, version } diff --git a/crates/ruma-events/src/enums.rs b/crates/ruma-events/src/enums.rs index a65da240..c3bffac7 100644 --- a/crates/ruma-events/src/enums.rs +++ b/crates/ruma-events/src/enums.rs @@ -4,7 +4,9 @@ use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId}; use serde::{de, Deserialize, Serialize}; 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! { /// Any global account data event. @@ -281,7 +283,7 @@ impl Redact for AnyRoomEvent { /// Redacts `self`, referencing the given event in `unsigned.redacted_because`. /// /// 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 { Self::Message(ev) => Self::Redacted::Message(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`. /// /// 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 { Self::Message(ev) => Self::Redacted::Message(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 { #[cfg(feature = "unstable-pre-spec")] use crate::key::verification::{ - accept::AcceptEventContent, cancel::CancelEventContent, done::DoneEventContent, - key::KeyEventContent, mac::MacEventContent, ready::ReadyEventContent, - start::StartEventContent, + accept::KeyVerificationAcceptEventContent, cancel::KeyVerificationCancelEventContent, + done::KeyVerificationDoneEventContent, key::KeyVerificationKeyEventContent, + mac::KeyVerificationMacEventContent, ready::KeyVerificationReadyEventContent, + start::KeyVerificationStartEventContent, }; match self { #[cfg(feature = "unstable-pre-spec")] #[rustfmt::skip] - AnyMessageEventContent::KeyVerificationReady(ReadyEventContent { relates_to, .. }) - | AnyMessageEventContent::KeyVerificationStart(StartEventContent { relates_to, .. }) - | AnyMessageEventContent::KeyVerificationCancel(CancelEventContent { relates_to, .. }) - | AnyMessageEventContent::KeyVerificationAccept(AcceptEventContent { relates_to, .. }) - | AnyMessageEventContent::KeyVerificationKey(KeyEventContent { relates_to, .. }) - | AnyMessageEventContent::KeyVerificationMac(MacEventContent { relates_to, .. }) - | AnyMessageEventContent::KeyVerificationDone(DoneEventContent { relates_to, .. }) => { + AnyMessageEventContent::KeyVerificationReady(KeyVerificationReadyEventContent { relates_to, .. }) + | AnyMessageEventContent::KeyVerificationStart(KeyVerificationStartEventContent { relates_to, .. }) + | AnyMessageEventContent::KeyVerificationCancel(KeyVerificationCancelEventContent { relates_to, .. }) + | AnyMessageEventContent::KeyVerificationAccept(KeyVerificationAcceptEventContent { relates_to, .. }) + | AnyMessageEventContent::KeyVerificationKey(KeyVerificationKeyEventContent { relates_to, .. }) + | AnyMessageEventContent::KeyVerificationMac(KeyVerificationMacEventContent { relates_to, .. }) + | AnyMessageEventContent::KeyVerificationDone(KeyVerificationDoneEventContent { relates_to, .. }) => { Some(relates_to.clone().into()) }, #[cfg(feature = "unstable-pre-spec")] diff --git a/crates/ruma-events/src/key/verification/accept.rs b/crates/ruma-events/src/key/verification/accept.rs index 0e9515b8..59e02dc1 100644 --- a/crates/ruma-events/src/key/verification/accept.rs +++ b/crates/ruma-events/src/key/verification/accept.rs @@ -18,7 +18,7 @@ use super::{ #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.key.verification.accept", kind = ToDevice)] -pub struct ToDeviceAcceptEventContent { +pub struct ToDeviceKeyVerificationAcceptEventContent { /// An opaque identifier for the verification process. /// /// 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, } -impl ToDeviceAcceptEventContent { - /// Creates a new `ToDeviceAcceptEventContent` with the given transaction ID and method-specific - /// content. +impl ToDeviceKeyVerificationAcceptEventContent { + /// Creates a new `ToDeviceKeyVerificationAcceptEventContent` with the given transaction ID and + /// method-specific content. pub fn new(transaction_id: String, method: AcceptMethod) -> Self { Self { transaction_id, method } } @@ -45,7 +45,7 @@ impl ToDeviceAcceptEventContent { #[cfg(feature = "unstable-pre-spec")] #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct AcceptEventContent { +pub struct KeyVerificationAcceptEventContent { /// The method specific content. #[serde(flatten)] pub method: AcceptMethod, @@ -56,9 +56,9 @@ pub struct AcceptEventContent { } #[cfg(feature = "unstable-pre-spec")] -impl AcceptEventContent { - /// Creates a new `ToDeviceAcceptEventContent` with the given method-specific content and - /// relation. +impl KeyVerificationAcceptEventContent { + /// Creates a new `ToDeviceKeyVerificationAcceptEventContent` with the given method-specific + /// content and relation. pub fn new(method: AcceptMethod, relates_to: Relation) -> Self { Self { method, relates_to } } @@ -174,10 +174,10 @@ mod tests { }; #[cfg(feature = "unstable-pre-spec")] - use super::AcceptEventContent; + use super::KeyVerificationAcceptEventContent; use super::{ AcceptMethod, HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, SasV1Content, - ShortAuthenticationString, ToDeviceAcceptEventContent, _CustomContent, + ShortAuthenticationString, ToDeviceKeyVerificationAcceptEventContent, _CustomContent, }; #[cfg(feature = "unstable-pre-spec")] use crate::key::verification::Relation; @@ -185,7 +185,7 @@ mod tests { #[test] fn serialization() { - let key_verification_accept_content = ToDeviceAcceptEventContent { + let key_verification_accept_content = ToDeviceKeyVerificationAcceptEventContent { transaction_id: "456".into(), method: AcceptMethod::SasV1(SasV1Content { hash: HashAlgorithm::Sha256, @@ -229,7 +229,7 @@ mod tests { "type": "m.key.verification.accept" }); - let key_verification_accept_content = ToDeviceAcceptEventContent { + let key_verification_accept_content = ToDeviceKeyVerificationAcceptEventContent { transaction_id: "456".into(), method: AcceptMethod::_Custom(_CustomContent { method: "m.sas.custom".to_owned(), @@ -250,7 +250,7 @@ mod tests { fn in_room_serialization() { 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() }, method: AcceptMethod::SasV1(SasV1Content { hash: HashAlgorithm::Sha256, @@ -291,8 +291,8 @@ mod tests { // Deserialize the content struct separately to verify `TryFromRaw` is implemented for it. assert_matches!( - from_json_value::(json).unwrap(), - ToDeviceAcceptEventContent { + from_json_value::(json).unwrap(), + ToDeviceKeyVerificationAcceptEventContent { transaction_id, method: AcceptMethod::SasV1(SasV1Content { commitment, @@ -326,10 +326,10 @@ mod tests { }); assert_matches!( - from_json_value::>(json).unwrap(), + from_json_value::>(json).unwrap(), ToDeviceEvent { sender, - content: ToDeviceAcceptEventContent { + content: ToDeviceKeyVerificationAcceptEventContent { transaction_id, method: AcceptMethod::SasV1(SasV1Content { commitment, @@ -362,10 +362,10 @@ mod tests { }); assert_matches!( - from_json_value::>(json).unwrap(), + from_json_value::>(json).unwrap(), ToDeviceEvent { sender, - content: ToDeviceAcceptEventContent { + content: ToDeviceKeyVerificationAcceptEventContent { transaction_id, method: AcceptMethod::_Custom(_CustomContent { method, @@ -399,8 +399,8 @@ mod tests { // Deserialize the content struct separately to verify `TryFromRaw` is implemented for it. assert_matches!( - from_json_value::(json).unwrap(), - AcceptEventContent { + from_json_value::(json).unwrap(), + KeyVerificationAcceptEventContent { relates_to: Relation { event_id }, diff --git a/crates/ruma-events/src/key/verification/cancel.rs b/crates/ruma-events/src/key/verification/cancel.rs index 445d6acf..7d9547cf 100644 --- a/crates/ruma-events/src/key/verification/cancel.rs +++ b/crates/ruma-events/src/key/verification/cancel.rs @@ -13,7 +13,7 @@ use super::Relation; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.key.verification.cancel", kind = ToDevice)] -pub struct ToDeviceCancelEventContent { +pub struct ToDeviceKeyVerificationCancelEventContent { /// The opaque identifier for the verification process/request. pub transaction_id: String, @@ -26,8 +26,9 @@ pub struct ToDeviceCancelEventContent { pub code: CancelCode, } -impl ToDeviceCancelEventContent { - /// Creates a new `ToDeviceCancelEventContent` with the given transaction ID, reason and code. +impl ToDeviceKeyVerificationCancelEventContent { + /// Creates a new `ToDeviceKeyVerificationCancelEventContent` with the given transaction ID, + /// reason and code. pub fn new(transaction_id: String, reason: String, code: CancelCode) -> Self { Self { transaction_id, reason, code } } @@ -41,7 +42,7 @@ impl ToDeviceCancelEventContent { #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.key.verification.cancel", kind = Message)] -pub struct CancelEventContent { +pub struct KeyVerificationCancelEventContent { /// A human readable description of 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")] -impl CancelEventContent { - /// Creates a new `CancelEventContent` with the given reason, code and relation. +impl KeyVerificationCancelEventContent { + /// Creates a new `KeyVerificationCancelEventContent` with the given reason, code and relation. pub fn new(reason: String, code: CancelCode, relates_to: Relation) -> Self { Self { reason, code, relates_to } } diff --git a/crates/ruma-events/src/key/verification/done.rs b/crates/ruma-events/src/key/verification/done.rs index b435b972..1ab7563e 100644 --- a/crates/ruma-events/src/key/verification/done.rs +++ b/crates/ruma-events/src/key/verification/done.rs @@ -11,15 +11,15 @@ use super::Relation; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.key.verification.done", kind = ToDevice)] -pub struct ToDeviceDoneEventContent { +pub struct ToDeviceKeyVerificationDoneEventContent { /// An opaque identifier for the verification process. /// /// Must be the same as the one used for the `m.key.verification.start` message. pub transaction_id: String, } -impl ToDeviceDoneEventContent { - /// Creates a new `ToDeviceDoneEventContent` with the given transaction ID. +impl ToDeviceKeyVerificationDoneEventContent { + /// Creates a new `ToDeviceKeyVerificationDoneEventContent` with the given transaction ID. pub fn new(transaction_id: String) -> Self { Self { transaction_id } } @@ -31,14 +31,14 @@ impl ToDeviceDoneEventContent { #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. #[serde(rename = "m.relates_to")] pub relates_to: Relation, } -impl DoneEventContent { - /// Creates a new `DoneEventContent` with the given relation. +impl KeyVerificationDoneEventContent { + /// Creates a new `KeyVerificationDoneEventContent` with the given relation. pub fn new(relates_to: Relation) -> Self { Self { relates_to } } @@ -50,7 +50,7 @@ mod tests { use ruma_identifiers::event_id; 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; #[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); } @@ -81,8 +81,8 @@ mod tests { }); assert_matches!( - from_json_value::(json_data).unwrap(), - DoneEventContent { + from_json_value::(json_data).unwrap(), + KeyVerificationDoneEventContent { relates_to: Relation { event_id }, diff --git a/crates/ruma-events/src/key/verification/key.rs b/crates/ruma-events/src/key/verification/key.rs index 0a1a1762..01813800 100644 --- a/crates/ruma-events/src/key/verification/key.rs +++ b/crates/ruma-events/src/key/verification/key.rs @@ -12,7 +12,7 @@ use super::Relation; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.key.verification.key", kind = ToDevice)] -pub struct ToDeviceKeyEventContent { +pub struct ToDeviceKeyVerificationKeyEventContent { /// An opaque identifier for the verification process. /// /// 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, } -impl ToDeviceKeyEventContent { - /// Creates a new `ToDeviceKeyEventContent` with the given transaction ID and key. +impl ToDeviceKeyVerificationKeyEventContent { + /// Creates a new `ToDeviceKeyVerificationKeyEventContent` with the given transaction ID and + /// key. pub fn new(transaction_id: String, key: String) -> Self { Self { transaction_id, key } } @@ -37,7 +38,7 @@ impl ToDeviceKeyEventContent { #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. pub key: String, @@ -47,8 +48,8 @@ pub struct KeyEventContent { } #[cfg(feature = "unstable-pre-spec")] -impl KeyEventContent { - /// Creates a new `KeyEventContent` with the given key and relation. +impl KeyVerificationKeyEventContent { + /// Creates a new `KeyVerificationKeyEventContent` with the given key and relation. pub fn new(key: String, relates_to: Relation) -> Self { Self { key, relates_to } } diff --git a/crates/ruma-events/src/key/verification/mac.rs b/crates/ruma-events/src/key/verification/mac.rs index 5ed1a3eb..c9b147ad 100644 --- a/crates/ruma-events/src/key/verification/mac.rs +++ b/crates/ruma-events/src/key/verification/mac.rs @@ -14,7 +14,7 @@ use super::Relation; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.key.verification.mac", kind = ToDevice)] -pub struct ToDeviceMacEventContent { +pub struct ToDeviceKeyVerificationMacEventContent { /// An opaque identifier for the verification process. /// /// 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, } -impl ToDeviceMacEventContent { - /// Creates a new `ToDeviceMacEventContent` with the given transaction ID, key ID to MAC map and - /// key MAC. +impl ToDeviceKeyVerificationMacEventContent { + /// Creates a new `ToDeviceKeyVerificationMacEventContent` with the given transaction ID, key ID + /// to MAC map and key MAC. pub fn new(transaction_id: String, mac: BTreeMap, keys: String) -> Self { Self { transaction_id, mac, keys } } @@ -46,7 +46,7 @@ impl ToDeviceMacEventContent { #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. /// /// The MAC is encoded as unpadded Base64. @@ -62,8 +62,9 @@ pub struct MacEventContent { } #[cfg(feature = "unstable-pre-spec")] -impl MacEventContent { - /// Creates a new `MacEventContent` with the given key ID to MAC map, key MAC and relation. +impl KeyVerificationMacEventContent { + /// Creates a new `KeyVerificationMacEventContent` with the given key ID to MAC map, key MAC and + /// relation. pub fn new(mac: BTreeMap, keys: String, relates_to: Relation) -> Self { Self { mac, keys, relates_to } } diff --git a/crates/ruma-events/src/key/verification/ready.rs b/crates/ruma-events/src/key/verification/ready.rs index 16f3d309..3ffba06a 100644 --- a/crates/ruma-events/src/key/verification/ready.rs +++ b/crates/ruma-events/src/key/verification/ready.rs @@ -12,7 +12,7 @@ use super::{Relation, VerificationMethod}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.key.verification.ready", kind = ToDevice)] -pub struct ToDeviceReadyEventContent { +pub struct ToDeviceKeyVerificationReadyEventContent { /// The device ID which is initiating the request. pub from_device: DeviceIdBox, @@ -27,9 +27,9 @@ pub struct ToDeviceReadyEventContent { pub transaction_id: String, } -impl ToDeviceReadyEventContent { - /// Creates a new `ToDeviceReadyEventContent` with the given device ID, verification methods and - /// transaction ID. +impl ToDeviceKeyVerificationReadyEventContent { + /// Creates a new `ToDeviceKeyVerificationReadyEventContent` with the given device ID, + /// verification methods and transaction ID. pub fn new( from_device: DeviceIdBox, methods: Vec, @@ -45,7 +45,7 @@ impl ToDeviceReadyEventContent { #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.key.verification.ready", kind = Message)] -pub struct ReadyEventContent { +pub struct KeyVerificationReadyEventContent { /// The device ID which is initiating the request. pub from_device: DeviceIdBox, @@ -58,8 +58,9 @@ pub struct ReadyEventContent { pub relates_to: Relation, } -impl ReadyEventContent { - /// Creates a new `ReadyEventContent` with the given device ID, methods and relation. +impl KeyVerificationReadyEventContent { + /// Creates a new `KeyVerificationReadyEventContent` with the given device ID, methods and + /// relation. pub fn new( from_device: DeviceIdBox, methods: Vec, @@ -75,7 +76,7 @@ mod tests { use ruma_identifiers::{event_id, DeviceIdBox}; 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}; #[test] @@ -92,7 +93,7 @@ mod tests { } }); - let content = ReadyEventContent { + let content = KeyVerificationReadyEventContent { from_device: device.clone(), relates_to: Relation { event_id }, methods: vec![VerificationMethod::SasV1], @@ -106,7 +107,7 @@ mod tests { "transaction_id": "456", }); - let content = ToDeviceReadyEventContent { + let content = ToDeviceKeyVerificationReadyEventContent { from_device: device, transaction_id: "456".to_owned(), methods: vec![VerificationMethod::SasV1], @@ -130,8 +131,8 @@ mod tests { }); assert_matches!( - from_json_value::(json_data).unwrap(), - ReadyEventContent { + from_json_value::(json_data).unwrap(), + KeyVerificationReadyEventContent { from_device, relates_to: Relation { event_id @@ -149,8 +150,8 @@ mod tests { }); assert_matches!( - from_json_value::(json_data).unwrap(), - ToDeviceReadyEventContent { + from_json_value::(json_data).unwrap(), + ToDeviceKeyVerificationReadyEventContent { from_device, transaction_id, methods, diff --git a/crates/ruma-events/src/key/verification/request.rs b/crates/ruma-events/src/key/verification/request.rs index c26b13c3..06f7da91 100644 --- a/crates/ruma-events/src/key/verification/request.rs +++ b/crates/ruma-events/src/key/verification/request.rs @@ -11,7 +11,7 @@ use super::VerificationMethod; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.key.verification.request", kind = ToDevice)] -pub struct ToDeviceRequestEventContent { +pub struct ToDeviceKeyVerificationRequestEventContent { /// The device ID which is initiating the request. pub from_device: DeviceIdBox, @@ -30,9 +30,9 @@ pub struct ToDeviceRequestEventContent { pub timestamp: MilliSecondsSinceUnixEpoch, } -impl ToDeviceRequestEventContent { - /// Creates a new `ToDeviceRequestEventContent` with the given device ID, transaction ID, - /// methods and timestamp. +impl ToDeviceKeyVerificationRequestEventContent { + /// Creates a new `ToDeviceKeyVerificationRequestEventContent` with the given device ID, + /// transaction ID, methods and timestamp. pub fn new( from_device: DeviceIdBox, transaction_id: String, diff --git a/crates/ruma-events/src/key/verification/start.rs b/crates/ruma-events/src/key/verification/start.rs index cfb59abf..3152e960 100644 --- a/crates/ruma-events/src/key/verification/start.rs +++ b/crates/ruma-events/src/key/verification/start.rs @@ -19,7 +19,7 @@ use super::{ #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.key.verification.start", kind = ToDevice)] -pub struct ToDeviceStartEventContent { +pub struct ToDeviceKeyVerificationStartEventContent { /// The device ID which is initiating the process. pub from_device: DeviceIdBox, @@ -35,9 +35,9 @@ pub struct ToDeviceStartEventContent { pub method: StartMethod, } -impl ToDeviceStartEventContent { - /// Creates a new `ToDeviceStartEventContent` with the given device ID, transaction ID and - /// method specific content. +impl ToDeviceKeyVerificationStartEventContent { + /// Creates a new `ToDeviceKeyVerificationStartEventContent` with the given device ID, + /// transaction ID and method specific content. pub fn new(from_device: DeviceIdBox, transaction_id: String, method: StartMethod) -> Self { Self { from_device, transaction_id, method } } @@ -51,7 +51,7 @@ impl ToDeviceStartEventContent { #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.key.verification.start", kind = Message)] -pub struct StartEventContent { +pub struct KeyVerificationStartEventContent { /// The device ID which is initiating the process. pub from_device: DeviceIdBox, @@ -65,8 +65,9 @@ pub struct StartEventContent { } #[cfg(feature = "unstable-pre-spec")] -impl StartEventContent { - /// Creates a new `StartEventContent` with the given device ID, method and relation. +impl KeyVerificationStartEventContent { + /// Creates a new `KeyVerificationStartEventContent` with the given device ID, method and + /// relation. pub fn new(from_device: DeviceIdBox, method: StartMethod, relates_to: Relation) -> Self { Self { from_device, method, relates_to } } @@ -209,18 +210,18 @@ mod tests { use super::{ HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, SasV1Content, - SasV1ContentInit, ShortAuthenticationString, StartMethod, ToDeviceStartEventContent, - _CustomContent, + SasV1ContentInit, ShortAuthenticationString, StartMethod, + ToDeviceKeyVerificationStartEventContent, _CustomContent, }; #[cfg(feature = "unstable-pre-spec")] - use super::{ReciprocateV1Content, StartEventContent}; + use super::{KeyVerificationStartEventContent, ReciprocateV1Content}; #[cfg(feature = "unstable-pre-spec")] use crate::key::verification::Relation; use crate::ToDeviceEvent; #[test] fn serialization() { - let key_verification_start_content = ToDeviceStartEventContent { + let key_verification_start_content = ToDeviceKeyVerificationStartEventContent { from_device: "123".into(), transaction_id: "456".into(), method: StartMethod::SasV1( @@ -268,7 +269,7 @@ mod tests { "sender": sender }); - let key_verification_start_content = ToDeviceStartEventContent { + let key_verification_start_content = ToDeviceKeyVerificationStartEventContent { from_device: "123".into(), transaction_id: "456".into(), method: StartMethod::_Custom(_CustomContent { @@ -288,7 +289,7 @@ mod tests { { 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(), transaction_id: "456".into(), method: StartMethod::ReciprocateV1(ReciprocateV1Content::new(secret.clone())), @@ -310,7 +311,7 @@ mod tests { fn in_room_serialization() { let event_id = event_id!("$1598361704261elfgc:localhost"); - let key_verification_start_content = StartEventContent { + let key_verification_start_content = KeyVerificationStartEventContent { from_device: "123".into(), relates_to: Relation { event_id: event_id.clone() }, method: StartMethod::SasV1( @@ -341,7 +342,7 @@ mod tests { 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(), relates_to: Relation { event_id: event_id.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. assert_matches!( - from_json_value::(json).unwrap(), - ToDeviceStartEventContent { + from_json_value::(json).unwrap(), + ToDeviceKeyVerificationStartEventContent { from_device, transaction_id, method: StartMethod::SasV1(SasV1Content { @@ -409,10 +410,10 @@ mod tests { }); assert_matches!( - from_json_value::>(json).unwrap(), + from_json_value::>(json).unwrap(), ToDeviceEvent { sender, - content: ToDeviceStartEventContent { + content: ToDeviceKeyVerificationStartEventContent { from_device, transaction_id, method: StartMethod::SasV1(SasV1Content { @@ -445,10 +446,10 @@ mod tests { }); assert_matches!( - from_json_value::>(json).unwrap(), + from_json_value::>(json).unwrap(), ToDeviceEvent { sender, - content: ToDeviceStartEventContent { + content: ToDeviceKeyVerificationStartEventContent { from_device, transaction_id, method: StartMethod::_Custom(_CustomContent { method, data }) @@ -474,10 +475,10 @@ mod tests { }); assert_matches!( - from_json_value::>(json).unwrap(), + from_json_value::>(json).unwrap(), ToDeviceEvent { sender, - content: ToDeviceStartEventContent { + content: ToDeviceKeyVerificationStartEventContent { from_device, transaction_id, method: StartMethod::ReciprocateV1(ReciprocateV1Content { secret }), @@ -510,8 +511,8 @@ mod tests { // Deserialize the content struct separately to verify `TryFromRaw` is implemented for it. assert_matches!( - from_json_value::(json).unwrap(), - StartEventContent { + from_json_value::(json).unwrap(), + KeyVerificationStartEventContent { from_device, relates_to: Relation { event_id }, method: StartMethod::SasV1(SasV1Content { @@ -539,8 +540,8 @@ mod tests { }); assert_matches!( - from_json_value::(json).unwrap(), - StartEventContent { + from_json_value::(json).unwrap(), + KeyVerificationStartEventContent { from_device, relates_to: Relation { event_id }, method: StartMethod::ReciprocateV1(ReciprocateV1Content { secret }), diff --git a/crates/ruma-events/src/lib.rs b/crates/ruma-events/src/lib.rs index a1cfc1a8..06d1e218 100644 --- a/crates/ruma-events/src/lib.rs +++ b/crates/ruma-events/src/lib.rs @@ -125,7 +125,7 @@ use serde::{ }; use serde_json::value::RawValue as RawJsonValue; -use self::room::redaction::SyncRedactionEvent; +use self::room::redaction::SyncRoomRedactionEvent; mod enums; 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 /// 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. diff --git a/crates/ruma-events/src/policy/rule/room.rs b/crates/ruma-events/src/policy/rule/room.rs index 4273d9da..4c145d01 100644 --- a/crates/ruma-events/src/policy/rule/room.rs +++ b/crates/ruma-events/src/policy/rule/room.rs @@ -11,7 +11,7 @@ use crate::policy::rule::PolicyRuleEventContent; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[allow(clippy::exhaustive_structs)] #[ruma_event(type = "m.policy.rule.room", kind = State)] -pub struct RoomEventContent(pub PolicyRuleEventContent); +pub struct PolicyRuleRoomEventContent(pub PolicyRuleEventContent); #[cfg(test)] mod tests { @@ -23,7 +23,7 @@ mod tests { use ruma_serde::Raw; 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::{ policy::rule::{PolicyRuleEventContent, Recommendation}, Unsigned, @@ -31,7 +31,7 @@ mod tests { #[test] fn serialization() { - let room_event = RoomEvent { + let room_event = PolicyRuleRoomEvent { event_id: event_id!("$143273582443PhrSn:example.org"), sender: user_id!("@example:example.org"), origin_server_ts: MilliSecondsSinceUnixEpoch(1_432_735_824_653_u64.try_into().unwrap()), @@ -44,7 +44,7 @@ mod tests { #[cfg(feature = "unstable-pre-spec")] relations: None, }, - content: RoomEventContent(PolicyRuleEventContent { + content: PolicyRuleRoomEventContent(PolicyRuleEventContent { entity: "#*:example.org".into(), reason: "undesirable content".into(), recommendation: Recommendation::Ban, @@ -90,6 +90,6 @@ mod tests { } }); - assert!(from_json_value::>(json).unwrap().deserialize().is_ok()); + assert!(from_json_value::>(json).unwrap().deserialize().is_ok()); } } diff --git a/crates/ruma-events/src/policy/rule/server.rs b/crates/ruma-events/src/policy/rule/server.rs index 81509d8d..75a80f8a 100644 --- a/crates/ruma-events/src/policy/rule/server.rs +++ b/crates/ruma-events/src/policy/rule/server.rs @@ -11,4 +11,4 @@ use crate::policy::rule::PolicyRuleEventContent; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[allow(clippy::exhaustive_structs)] #[ruma_event(type = "m.policy.rule.server", kind = State)] -pub struct ServerEventContent(pub PolicyRuleEventContent); +pub struct PolicyRuleServerEventContent(pub PolicyRuleEventContent); diff --git a/crates/ruma-events/src/policy/rule/user.rs b/crates/ruma-events/src/policy/rule/user.rs index 8d09fe91..94768868 100644 --- a/crates/ruma-events/src/policy/rule/user.rs +++ b/crates/ruma-events/src/policy/rule/user.rs @@ -11,4 +11,4 @@ use crate::policy::rule::PolicyRuleEventContent; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[allow(clippy::exhaustive_structs)] #[ruma_event(type = "m.policy.rule.user", kind = State)] -pub struct UserEventContent(pub PolicyRuleEventContent); +pub struct PolicyRuleUserEventContent(pub PolicyRuleEventContent); diff --git a/crates/ruma-events/src/room/aliases.rs b/crates/ruma-events/src/room/aliases.rs index 47d23d1b..65b0ca55 100644 --- a/crates/ruma-events/src/room/aliases.rs +++ b/crates/ruma-events/src/room/aliases.rs @@ -16,22 +16,22 @@ use crate::{ #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.aliases", kind = State, custom_redacted)] -pub struct AliasesEventContent { +pub struct RoomAliasesEventContent { /// A list of room aliases. pub aliases: Vec, } -impl AliasesEventContent { - /// Create an `AliasesEventContent` from the given aliases. +impl RoomAliasesEventContent { + /// Create an `RoomAliasesEventContent` from the given aliases. pub fn new(aliases: Vec) -> Self { Self { aliases } } } -impl RedactContent for AliasesEventContent { - type Redacted = RedactedAliasesEventContent; +impl RedactContent for RoomAliasesEventContent { + 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 // a new room version is introduced. let aliases = match version { @@ -43,14 +43,14 @@ impl RedactContent for AliasesEventContent { _ => None, }; - RedactedAliasesEventContent { aliases } + RedactedRoomAliasesEventContent { aliases } } } /// An aliases event that has been redacted. #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct RedactedAliasesEventContent { +pub struct RedactedRoomAliasesEventContent { /// A list of room aliases. /// /// According to the Matrix spec version 1 redaction rules allowed this field to be @@ -58,7 +58,7 @@ pub struct RedactedAliasesEventContent { pub aliases: Option>, } -impl RedactedAliasesEventContent { +impl RedactedRoomAliasesEventContent { /// Create a `RedactedAliasesEventContent` with the given aliases. /// /// 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 { "m.room.aliases" } @@ -93,7 +93,7 @@ impl EventContent for RedactedAliasesEventContent { // Since this redacted event has fields we leave the default `empty` method // that will error if called. -impl RedactedEventContent for RedactedAliasesEventContent { +impl RedactedEventContent for RedactedRoomAliasesEventContent { fn has_serialize_fields(&self) -> bool { self.aliases.is_some() } @@ -103,4 +103,4 @@ impl RedactedEventContent for RedactedAliasesEventContent { } } -impl RedactedStateEventContent for RedactedAliasesEventContent {} +impl RedactedStateEventContent for RedactedRoomAliasesEventContent {} diff --git a/crates/ruma-events/src/room/avatar.rs b/crates/ruma-events/src/room/avatar.rs index ee142591..1a73dc68 100644 --- a/crates/ruma-events/src/room/avatar.rs +++ b/crates/ruma-events/src/room/avatar.rs @@ -16,7 +16,7 @@ use super::ThumbnailInfo; #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(feature = "unstable-pre-spec", derive(Default))] #[ruma_event(type = "m.room.avatar", kind = State)] -pub struct AvatarEventContent { +pub struct RoomAvatarEventContent { /// Information about the avatar image. #[serde(skip_serializing_if = "Option::is_none")] pub info: Option>, @@ -34,8 +34,8 @@ pub struct AvatarEventContent { pub url: Option, } -impl AvatarEventContent { - /// Create an `AvatarEventContent` from the given image URL. +impl RoomAvatarEventContent { + /// Create an `RoomAvatarEventContent` from the given image URL. /// /// With the `unstable-pre-spec` feature, this method takes no parameters. #[cfg(not(feature = "unstable-pre-spec"))] @@ -43,7 +43,7 @@ impl AvatarEventContent { Self { info: None, url } } - /// Create an empty `AvatarEventContent`. + /// Create an empty `RoomAvatarEventContent`. /// /// With the `unstable-pre-spec` feature, this method takes an `MxcUri`. #[cfg(feature = "unstable-pre-spec")] diff --git a/crates/ruma-events/src/room/canonical_alias.rs b/crates/ruma-events/src/room/canonical_alias.rs index ea97e45d..76ce8bef 100644 --- a/crates/ruma-events/src/room/canonical_alias.rs +++ b/crates/ruma-events/src/room/canonical_alias.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.canonical_alias", kind = State)] -pub struct CanonicalAliasEventContent { +pub struct RoomCanonicalAliasEventContent { /// The canonical alias. /// /// Rooms with `alias: None` should be treated the same as a room @@ -27,8 +27,8 @@ pub struct CanonicalAliasEventContent { pub alt_aliases: Vec, } -impl CanonicalAliasEventContent { - /// Creates an empty `CanonicalAliasEventContent`. +impl RoomCanonicalAliasEventContent { + /// Creates an empty `RoomCanonicalAliasEventContent`. pub fn new() -> Self { 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 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}; #[test] fn serialization_with_optional_fields_as_none() { let canonical_alias_event = StateEvent { - content: CanonicalAliasEventContent { + content: RoomCanonicalAliasEventContent { alias: Some(room_alias_id!("#somewhere:localhost")), alt_aliases: Vec::new(), }, @@ -89,7 +89,7 @@ mod tests { }); assert_eq!( - from_json_value::>(json_data) + from_json_value::>(json_data) .unwrap() .content .alias, @@ -111,7 +111,7 @@ mod tests { "type": "m.room.canonical_alias" }); assert_eq!( - from_json_value::>(json_data) + from_json_value::>(json_data) .unwrap() .content .alias, @@ -133,7 +133,7 @@ mod tests { "type": "m.room.canonical_alias" }); assert_eq!( - from_json_value::>(json_data) + from_json_value::>(json_data) .unwrap() .content .alias, @@ -156,7 +156,7 @@ mod tests { "type": "m.room.canonical_alias" }); assert_eq!( - from_json_value::>(json_data) + from_json_value::>(json_data) .unwrap() .content .alias, diff --git a/crates/ruma-events/src/room/create.rs b/crates/ruma-events/src/room/create.rs index 27aeac50..2e6cfe44 100644 --- a/crates/ruma-events/src/room/create.rs +++ b/crates/ruma-events/src/room/create.rs @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. #[ruma_event(skip_redaction)] pub creator: UserId, @@ -42,8 +42,8 @@ pub struct CreateEventContent { pub room_type: Option, } -impl CreateEventContent { - /// Creates a new `CreateEventContent` with the given creator. +impl RoomCreateEventContent { + /// Creates a new `RoomCreateEventContent` with the given creator. pub fn new(creator: UserId) -> Self { Self { creator, @@ -107,14 +107,14 @@ mod tests { use ruma_identifiers::{user_id, RoomVersionId}; 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")] use super::RoomType; #[test] fn serialization() { - let content = CreateEventContent { + let content = RoomCreateEventContent { creator: user_id!("@carl:example.com"), federate: false, room_version: RoomVersionId::Version4, @@ -135,7 +135,7 @@ mod tests { #[cfg(feature = "unstable-pre-spec")] #[test] fn space_serialization() { - let content = CreateEventContent { + let content = RoomCreateEventContent { creator: user_id!("@carl:example.com"), federate: false, room_version: RoomVersionId::Version4, @@ -162,8 +162,8 @@ mod tests { }); assert_matches!( - from_json_value::(json).unwrap(), - CreateEventContent { + from_json_value::(json).unwrap(), + RoomCreateEventContent { creator, federate: true, room_version: RoomVersionId::Version4, @@ -185,8 +185,8 @@ mod tests { }); assert_matches!( - from_json_value::(json).unwrap(), - CreateEventContent { + from_json_value::(json).unwrap(), + RoomCreateEventContent { creator, federate: true, room_version: RoomVersionId::Version4, diff --git a/crates/ruma-events/src/room/encrypted.rs b/crates/ruma-events/src/room/encrypted.rs index 28f966b2..140ecba3 100644 --- a/crates/ruma-events/src/room/encrypted.rs +++ b/crates/ruma-events/src/room/encrypted.rs @@ -19,7 +19,7 @@ mod relation_serde; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.encrypted", kind = Message, kind = ToDevice)] -pub struct EncryptedEventContent { +pub struct RoomEncryptedEventContent { /// Algorithm-specific fields. #[serde(flatten)] pub scheme: EncryptedEventScheme, @@ -31,14 +31,14 @@ pub struct EncryptedEventContent { pub relates_to: Option, } -impl EncryptedEventContent { - /// Creates a new `EncryptedEventContent` with the given scheme and relation. +impl RoomEncryptedEventContent { + /// Creates a new `RoomEncryptedEventContent` with the given scheme and relation. pub fn new(scheme: EncryptedEventScheme, relates_to: Option) -> Self { Self { scheme, relates_to } } } -impl From for EncryptedEventContent { +impl From for RoomEncryptedEventContent { fn from(scheme: EncryptedEventScheme) -> Self { Self { scheme, relates_to: None } } @@ -48,26 +48,26 @@ impl From for EncryptedEventContent { #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.encrypted", kind = ToDevice)] -pub struct ToDeviceEncryptedEventContent { +pub struct ToDeviceRoomEncryptedEventContent { /// Algorithm-specific fields. #[serde(flatten)] pub scheme: EncryptedEventScheme, } -impl ToDeviceEncryptedEventContent { - /// Creates a new `ToDeviceEncryptedEventContent` with the given scheme. +impl ToDeviceRoomEncryptedEventContent { + /// Creates a new `ToDeviceRoomEncryptedEventContent` with the given scheme. pub fn new(scheme: EncryptedEventScheme) -> Self { Self { scheme } } } -impl From for ToDeviceEncryptedEventContent { +impl From for ToDeviceRoomEncryptedEventContent { fn from(scheme: EncryptedEventScheme) -> Self { Self { scheme } } } -/// The encryption scheme for `EncryptedEventContent`. +/// The encryption scheme for `RoomEncryptedEventContent`. #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "algorithm")] @@ -288,13 +288,15 @@ mod tests { use ruma_serde::Raw; 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 ruma_identifiers::event_id; #[test] fn serialization() { - let key_verification_start_content = EncryptedEventContent { + let key_verification_start_content = RoomEncryptedEventContent { scheme: EncryptedEventScheme::MegolmV1AesSha2(MegolmV1AesSha2Content { ciphertext: "ciphertext".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!( content.scheme, @@ -371,7 +373,7 @@ mod tests { }, "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 { EncryptedEventScheme::OlmV1Curve25519AesSha2(c) => { @@ -386,7 +388,7 @@ mod tests { #[test] fn deserialization_failure() { - assert!(from_json_value::>( + assert!(from_json_value::>( json!({ "algorithm": "m.megolm.v1.aes-sha2" }) ) .unwrap() diff --git a/crates/ruma-events/src/room/encryption.rs b/crates/ruma-events/src/room/encryption.rs index 68a47bd8..6d7d796e 100644 --- a/crates/ruma-events/src/room/encryption.rs +++ b/crates/ruma-events/src/room/encryption.rs @@ -12,7 +12,7 @@ use crate::EventEncryptionAlgorithm; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. /// /// Must be `m.megolm.v1.aes-sha2`. @@ -31,8 +31,8 @@ pub struct EncryptionEventContent { pub rotation_period_msgs: Option, } -impl EncryptionEventContent { - /// Creates a new `EncryptionEventContent` with the given algorithm. +impl RoomEncryptionEventContent { + /// Creates a new `RoomEncryptionEventContent` with the given algorithm. pub fn new(algorithm: EventEncryptionAlgorithm) -> Self { Self { algorithm, rotation_period_ms: None, rotation_period_msgs: None } } diff --git a/crates/ruma-events/src/room/guest_access.rs b/crates/ruma-events/src/room/guest_access.rs index 623310d6..4d5fbd94 100644 --- a/crates/ruma-events/src/room/guest_access.rs +++ b/crates/ruma-events/src/room/guest_access.rs @@ -13,13 +13,13 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.guest_access", kind = State)] -pub struct GuestAccessEventContent { +pub struct RoomGuestAccessEventContent { /// A policy for guest user access to a room. pub guest_access: GuestAccess, } -impl GuestAccessEventContent { - /// Creates a new `GuestAccessEventContent` with the given policy. +impl RoomGuestAccessEventContent { + /// Creates a new `RoomGuestAccessEventContent` with the given policy. pub fn new(guest_access: GuestAccess) -> Self { Self { guest_access } } diff --git a/crates/ruma-events/src/room/history_visibility.rs b/crates/ruma-events/src/room/history_visibility.rs index f7869cb7..033ce84d 100644 --- a/crates/ruma-events/src/room/history_visibility.rs +++ b/crates/ruma-events/src/room/history_visibility.rs @@ -11,14 +11,14 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.history_visibility", kind = State)] -pub struct HistoryVisibilityEventContent { +pub struct RoomHistoryVisibilityEventContent { /// Who can see the room history. #[ruma_event(skip_redaction)] pub history_visibility: HistoryVisibility, } -impl HistoryVisibilityEventContent { - /// Creates a new `HistoryVisibilityEventContent` with the given policy. +impl RoomHistoryVisibilityEventContent { + /// Creates a new `RoomHistoryVisibilityEventContent` with the given policy. pub fn new(history_visibility: HistoryVisibility) -> Self { Self { history_visibility } } diff --git a/crates/ruma-events/src/room/join_rules.rs b/crates/ruma-events/src/room/join_rules.rs index c3251bdb..97d942f9 100644 --- a/crates/ruma-events/src/room/join_rules.rs +++ b/crates/ruma-events/src/room/join_rules.rs @@ -22,34 +22,34 @@ use std::collections::BTreeMap; #[derive(Clone, Debug, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. #[ruma_event(skip_redaction)] #[serde(flatten)] pub join_rule: JoinRule, } -impl JoinRulesEventContent { - /// Creates a new `JoinRulesEventContent` with the given rule. +impl RoomJoinRulesEventContent { + /// Creates a new `RoomJoinRulesEventContent` with the given rule. pub fn new(join_rule: JoinRule) -> Self { Self { join_rule } } - /// Creates a new `JoinRulesEventContent` with the restricted rule and the given set of allow - /// rules. + /// Creates a new `RoomJoinRulesEventContent` with the restricted rule and the given set of + /// allow rules. #[cfg(feature = "unstable-pre-spec")] pub fn restricted(allow: Vec) -> Self { Self { join_rule: JoinRule::Restricted(Restricted::new(allow)) } } } -impl<'de> Deserialize<'de> for JoinRulesEventContent { +impl<'de> Deserialize<'de> for RoomJoinRulesEventContent { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { 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 { #[cfg(feature = "unstable-pre-spec")] use super::AllowRule; - use super::{JoinRule, JoinRulesEventContent}; + use super::{JoinRule, RoomJoinRulesEventContent}; #[cfg(feature = "unstable-pre-spec")] use ruma_identifiers::room_id; #[test] fn deserialize() { let json = r#"{"join_rule": "public"}"#; - let event: JoinRulesEventContent = serde_json::from_str(json).unwrap(); - assert!(matches!(event, JoinRulesEventContent { join_rule: JoinRule::Public })); + let event: RoomJoinRulesEventContent = serde_json::from_str(json).unwrap(); + assert!(matches!(event, RoomJoinRulesEventContent { join_rule: JoinRule::Public })); } #[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 { JoinRule::Restricted(restricted) => assert_eq!( restricted.allow, diff --git a/crates/ruma-events/src/room/member.rs b/crates/ruma-events/src/room/member.rs index 706881d0..b406791c 100644 --- a/crates/ruma-events/src/room/member.rs +++ b/crates/ruma-events/src/room/member.rs @@ -39,7 +39,7 @@ use crate::{StrippedStateEvent, SyncStateEvent}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. /// /// 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, } -impl MemberEventContent { - /// Creates a new `MemberEventContent` with the given membership state. +impl RoomMemberEventContent { + /// Creates a new `RoomMemberEventContent` with the given membership state. pub fn new(membership: MembershipState) -> Self { Self { membership, @@ -246,11 +246,11 @@ pub enum MembershipChange { 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. fn membership_change( - content: &MemberEventContent, - prev_content: Option<&MemberEventContent>, + content: &RoomMemberEventContent, + prev_content: Option<&RoomMemberEventContent>, sender: &UserId, state_key: &str, ) -> MembershipChange { @@ -260,7 +260,7 @@ fn membership_change( let prev_content = if let Some(prev_content) = &prev_content { prev_content } else { - &MemberEventContent { + &RoomMemberEventContent { avatar_url: None, displayname: 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. /// /// [spec]: https://matrix.org/docs/spec/client_server/r0.6.1#m-room-member @@ -312,7 +312,7 @@ impl MemberEvent { } } -impl SyncStateEvent { +impl SyncStateEvent { /// 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 @@ -321,7 +321,7 @@ impl SyncStateEvent { } } -impl StrippedStateEvent { +impl StrippedStateEvent { /// 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 @@ -339,7 +339,7 @@ mod tests { use ruma_identifiers::{server_name, server_signing_key_id}; 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; #[test] @@ -357,9 +357,9 @@ mod tests { }); assert_matches!( - from_json_value::>(json).unwrap(), + from_json_value::>(json).unwrap(), StateEvent { - content: MemberEventContent { + content: RoomMemberEventContent { avatar_url: None, displayname: None, is_direct: None, @@ -401,9 +401,9 @@ mod tests { }); assert_matches!( - from_json_value::>(json).unwrap(), + from_json_value::>(json).unwrap(), StateEvent { - content: MemberEventContent { + content: RoomMemberEventContent { avatar_url: None, displayname: None, is_direct: None, @@ -417,7 +417,7 @@ mod tests { sender, state_key, unsigned, - prev_content: Some(MemberEventContent { + prev_content: Some(RoomMemberEventContent { avatar_url: None, displayname: None, is_direct: None, @@ -464,9 +464,9 @@ mod tests { }); assert_matches!( - from_json_value::>(json).unwrap(), + from_json_value::>(json).unwrap(), StateEvent { - content: MemberEventContent { + content: RoomMemberEventContent { avatar_url: Some(avatar_url), displayname: Some(displayname), is_direct: Some(true), @@ -536,9 +536,9 @@ mod tests { }); assert_matches!( - from_json_value::>(json).unwrap(), + from_json_value::>(json).unwrap(), StateEvent { - content: MemberEventContent { + content: RoomMemberEventContent { avatar_url: None, displayname: None, is_direct: None, @@ -552,7 +552,7 @@ mod tests { sender, state_key, unsigned, - prev_content: Some(MemberEventContent { + prev_content: Some(RoomMemberEventContent { avatar_url: Some(avatar_url), displayname: Some(displayname), is_direct: Some(true), @@ -583,7 +583,7 @@ mod tests { #[cfg(feature = "compat")] assert_matches!( - from_json_value::>(json!({ + from_json_value::>(json!({ "type": "m.room.member", "content": { "membership": "join" @@ -613,7 +613,7 @@ mod tests { "state_key": "@alice:example.org" })).unwrap(), StateEvent { - content: MemberEventContent { + content: RoomMemberEventContent { avatar_url: None, displayname: None, is_direct: None, @@ -627,7 +627,7 @@ mod tests { sender, state_key, unsigned, - prev_content: Some(MemberEventContent { + prev_content: Some(RoomMemberEventContent { avatar_url: None, displayname: Some(displayname), is_direct: Some(true), diff --git a/crates/ruma-events/src/room/message.rs b/crates/ruma-events/src/room/message.rs index a4d07e8b..a3df7776 100644 --- a/crates/ruma-events/src/room/message.rs +++ b/crates/ruma-events/src/room/message.rs @@ -28,7 +28,7 @@ mod relation_serde; #[derive(Clone, Debug, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.message", kind = Message)] -pub struct MessageEventContent { +pub struct RoomMessageEventContent { /// A key which identifies the type of message being sent. /// /// This also holds the specific content of each message. @@ -42,8 +42,8 @@ pub struct MessageEventContent { pub relates_to: Option, } -impl MessageEventContent { - /// Create a `MessageEventContent` with the given `MessageType`. +impl RoomMessageEventContent { + /// Create a `RoomMessageEventContent` with the given `MessageType`. pub fn new(msgtype: MessageType) -> Self { Self { msgtype, relates_to: None } } @@ -69,7 +69,7 @@ impl MessageEventContent { } /// Creates a plain text reply to a message. - pub fn text_reply_plain(reply: impl Into, original_message: &MessageEvent) -> Self { + pub fn text_reply_plain(reply: impl Into, original_message: &RoomMessageEvent) -> Self { let quoted = get_plain_quote_fallback(original_message); let body = format!("{}\n\n{}", quoted, reply.into()); @@ -86,7 +86,7 @@ impl MessageEventContent { pub fn text_reply_html( reply: impl Into, html_reply: impl Into, - original_message: &MessageEvent, + original_message: &RoomMessageEvent, ) -> Self { let quoted = get_plain_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. - pub fn notice_reply_plain(reply: impl Into, original_message: &MessageEvent) -> Self { + pub fn notice_reply_plain( + reply: impl Into, + original_message: &RoomMessageEvent, + ) -> Self { let quoted = get_plain_quote_fallback(original_message); let body = format!("{}\n\n{}", quoted, reply.into()); @@ -119,7 +122,7 @@ impl MessageEventContent { pub fn notice_reply_html( reply: impl Into, html_reply: impl Into, - original_message: &MessageEvent, + original_message: &RoomMessageEvent, ) -> Self { let quoted = get_plain_quote_fallback(original_message); let quoted_html = get_html_quote_fallback(original_message); @@ -287,7 +290,7 @@ impl MessageType { } } -impl From for MessageEventContent { +impl From for RoomMessageEventContent { fn from(msgtype: MessageType) -> Self { Self::new(msgtype) } @@ -340,13 +343,13 @@ pub struct Replacement { pub event_id: EventId, /// New content. - pub new_content: Box, + pub new_content: Box, } #[cfg(feature = "unstable-pre-spec")] impl Replacement { /// Creates a new `Replacement` with the given event ID and new content. - pub fn new(event_id: EventId, new_content: Box) -> Self { + pub fn new(event_id: EventId, new_content: Box) -> Self { Self { event_id, new_content } } } @@ -377,13 +380,14 @@ pub struct AudioMessageEventContent { } impl AudioMessageEventContent { - /// Creates a new non-encrypted `AudioMessageEventContent` with the given body, url and optional - /// extra info. + /// Creates a new non-encrypted `RoomAudioMessageEventContent` with the given body, url and + /// optional extra info. pub fn plain(body: String, url: MxcUri, info: Option>) -> Self { 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 { Self { body, url: None, info: None, file: Some(Box::new(file)) } } @@ -478,13 +482,14 @@ pub struct FileMessageEventContent { } impl FileMessageEventContent { - /// Creates a new non-encrypted `FileMessageEventContent` with the given body, url and optional - /// extra info. + /// Creates a new non-encrypted `RoomFileMessageEventContent` with the given body, url and + /// optional extra info. pub fn plain(body: String, url: MxcUri, info: Option>) -> Self { 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 { Self { body, filename: None, url: None, info: None, file: Some(Box::new(file)) } } @@ -553,13 +558,14 @@ pub struct ImageMessageEventContent { } impl ImageMessageEventContent { - /// Creates a new non-encrypted `ImageMessageEventContent` with the given body, url and optional - /// extra info. + /// Creates a new non-encrypted `RoomImageMessageEventContent` with the given body, url and + /// optional extra info. pub fn plain(body: String, url: MxcUri, info: Option>) -> Self { 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 { Self { body, url: None, info: None, file: Some(Box::new(file)) } } @@ -583,7 +589,7 @@ pub struct 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 { Self { body, geo_uri, info: None } } @@ -677,7 +683,7 @@ pub struct 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 { Self { body, server_notice_type, admin_contact: None, limit_type: None } } @@ -846,13 +852,14 @@ pub struct VideoMessageEventContent { } impl VideoMessageEventContent { - /// Creates a new non-encrypted `VideoMessageEventContent` with the given body, url and optional - /// extra info. + /// Creates a new non-encrypted `RoomVideoMessageEventContent` with the given body, url and + /// optional extra info. pub fn plain(body: String, url: MxcUri, info: Option>) -> Self { 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 { Self { body, url: None, info: None, file: Some(Box::new(file)) } } @@ -945,8 +952,8 @@ pub struct KeyVerificationRequestEventContent { #[cfg(feature = "unstable-pre-spec")] impl KeyVerificationRequestEventContent { - /// Creates a new `KeyVerificationRequestEventContent` with the given body, method, device and - /// user ID. + /// Creates a new `RoomKeyVerificationRequestEventContent` with the given body, method, device + /// and user ID. pub fn new( body: String, methods: Vec, @@ -972,7 +979,7 @@ pub struct CustomEventContent { 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 { MessageType::Audio(_) => { 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)] -fn get_html_quote_fallback(original_message: &MessageEvent) -> String { +fn get_html_quote_fallback(original_message: &RoomMessageEvent) -> String { match &original_message.content.msgtype { MessageType::Audio(_) => { formatdoc!( @@ -1228,7 +1235,7 @@ mod tests { use ruma_identifiers::{event_id, EventId, RoomId, UserId}; 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] fn deserialize_reply() { @@ -1245,8 +1252,8 @@ mod tests { }); assert_matches!( - from_json_value::(json).unwrap(), - MessageEventContent { + from_json_value::(json).unwrap(), + RoomMessageEventContent { msgtype: MessageType::Text(_), relates_to: Some(Relation::Reply { in_reply_to: InReplyTo { event_id } }), } if event_id == ev_id @@ -1257,8 +1264,8 @@ mod tests { fn plain_quote_fallback_multiline() { let sender = UserId::try_from("@alice:example.com").unwrap(); assert_eq!( - super::get_plain_quote_fallback(&MessageEvent { - content: MessageEventContent::text_plain("multi\nline"), + super::get_plain_quote_fallback(&RoomMessageEvent { + content: RoomMessageEventContent::text_plain("multi\nline"), event_id: EventId::new(sender.server_name()), sender, origin_server_ts: ruma_common::MilliSecondsSinceUnixEpoch::now(), diff --git a/crates/ruma-events/src/room/message/content_serde.rs b/crates/ruma-events/src/room/message/content_serde.rs index 2e5d0b28..b786da80 100644 --- a/crates/ruma-events/src/room/message/content_serde.rs +++ b/crates/ruma-events/src/room/message/content_serde.rs @@ -1,12 +1,12 @@ -//! `Deserialize` implementation for MessageEventContent and MessageType. +//! `Deserialize` implementation for RoomMessageEventContent and MessageType. use serde::{de, Deserialize}; use serde_json::value::RawValue as RawJsonValue; -use super::{MessageEventContent, MessageType, Relation}; +use super::{MessageType, Relation, RoomMessageEventContent}; use crate::from_raw_json_value; -impl<'de> Deserialize<'de> for MessageEventContent { +impl<'de> Deserialize<'de> for RoomMessageEventContent { fn deserialize(deserializer: D) -> Result where D: de::Deserializer<'de>, diff --git a/crates/ruma-events/src/room/message/feedback.rs b/crates/ruma-events/src/room/message/feedback.rs index ba23042d..55d97019 100644 --- a/crates/ruma-events/src/room/message/feedback.rs +++ b/crates/ruma-events/src/room/message/feedback.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.message.feedback", kind = Message)] -pub struct FeedbackEventContent { +pub struct RoomMessageFeedbackEventContent { /// The event that this feedback is related to. pub target_event_id: EventId, @@ -23,8 +23,8 @@ pub struct FeedbackEventContent { pub feedback_type: FeedbackType, } -impl FeedbackEventContent { - /// Create a `FeedbackEventContent` from the given target event id and feedback type. +impl RoomMessageFeedbackEventContent { + /// Create a `RoomFeedbackEventContent` from the given target event id and feedback type. pub fn new(target_event_id: EventId, feedback_type: FeedbackType) -> Self { Self { target_event_id, feedback_type } } diff --git a/crates/ruma-events/src/room/message/relation_serde.rs b/crates/ruma-events/src/room/message/relation_serde.rs index 3e05381d..58bf1450 100644 --- a/crates/ruma-events/src/room/message/relation_serde.rs +++ b/crates/ruma-events/src/room/message/relation_serde.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use super::Replacement; use super::{InReplyTo, Relation}; #[cfg(feature = "unstable-pre-spec")] -use crate::room::message::MessageEventContent; +use crate::room::message::RoomMessageEventContent; impl<'de> Deserialize<'de> for Relation { fn deserialize(deserializer: D) -> Result @@ -74,7 +74,7 @@ struct EventWithRelatesToJsonRepr { #[cfg(feature = "unstable-pre-spec")] #[serde(rename = "m.new_content", skip_serializing_if = "Option::is_none")] - new_content: Option>, + new_content: Option>, } impl EventWithRelatesToJsonRepr { diff --git a/crates/ruma-events/src/room/name.rs b/crates/ruma-events/src/room/name.rs index 6891560b..a556001d 100644 --- a/crates/ruma-events/src/room/name.rs +++ b/crates/ruma-events/src/room/name.rs @@ -10,14 +10,14 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.room.name", kind = State)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct NameEventContent { +pub struct RoomNameEventContent { /// The name of the room. #[serde(default, deserialize_with = "ruma_serde::empty_string_as_none")] pub name: Option, } -impl NameEventContent { - /// Create a new `NameEventContent` with the given name. +impl RoomNameEventContent { + /// Create a new `RoomNameEventContent` with the given name. pub fn new(name: Option) -> Self { Self { name } } @@ -34,13 +34,13 @@ mod tests { use ruma_serde::Raw; 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}; #[test] fn serialization_with_optional_fields_as_none() { 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"), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), prev_content: None, @@ -69,10 +69,10 @@ mod tests { #[test] fn serialization_with_all_fields() { 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"), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), - prev_content: Some(NameEventContent { + prev_content: Some(RoomNameEventContent { name: RoomNameBox::try_from("The old name").ok(), }), room_id: room_id!("!n8f893n9:example.com"), @@ -113,7 +113,7 @@ mod tests { "type": "m.room.name" }); assert_eq!( - from_json_value::>(json_data).unwrap().content.name, + from_json_value::>(json_data).unwrap().content.name, None ); } @@ -125,7 +125,7 @@ mod tests { assert_eq!(long_string.len(), 256); let long_content_json = json!({ "name": &long_string }); - let from_raw: Raw = from_json_value(long_content_json).unwrap(); + let from_raw: Raw = from_json_value(long_content_json).unwrap(); let result = from_raw.deserialize(); assert!(result.is_err(), "Result should be invalid: {:?}", result); @@ -134,15 +134,15 @@ mod tests { #[test] fn json_with_empty_name_creates_content_as_none() { let long_content_json = json!({ "name": "" }); - let from_raw: Raw = from_json_value(long_content_json).unwrap(); - assert_matches!(from_raw.deserialize().unwrap(), NameEventContent { name: None }); + let from_raw: Raw = from_json_value(long_content_json).unwrap(); + assert_matches!(from_raw.deserialize().unwrap(), RoomNameEventContent { name: None }); } #[test] fn new_with_empty_name_creates_content_as_none() { assert_matches!( - NameEventContent::new(RoomNameBox::try_from(String::new()).ok()), - NameEventContent { name: None } + RoomNameEventContent::new(RoomNameBox::try_from(String::new()).ok()), + RoomNameEventContent { name: None } ); } @@ -160,7 +160,7 @@ mod tests { "type": "m.room.name" }); assert_eq!( - from_json_value::>(json_data).unwrap().content.name, + from_json_value::>(json_data).unwrap().content.name, None ); } @@ -179,7 +179,7 @@ mod tests { "type": "m.room.name" }); assert_eq!( - from_json_value::>(json_data).unwrap().content.name, + from_json_value::>(json_data).unwrap().content.name, None ); } @@ -200,7 +200,7 @@ mod tests { }); assert_eq!( - from_json_value::>(json_data).unwrap().content.name, + from_json_value::>(json_data).unwrap().content.name, name ); } diff --git a/crates/ruma-events/src/room/pinned_events.rs b/crates/ruma-events/src/room/pinned_events.rs index 57e561cc..0c075fa0 100644 --- a/crates/ruma-events/src/room/pinned_events.rs +++ b/crates/ruma-events/src/room/pinned_events.rs @@ -10,13 +10,13 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.pinned_events", kind = State)] -pub struct PinnedEventsEventContent { +pub struct RoomPinnedEventsEventContent { /// An ordered list of event IDs to pin. pub pinned: Vec, } -impl PinnedEventsEventContent { - /// Creates a new `PinnedEventsEventContent` with the given events. +impl RoomPinnedEventsEventContent { + /// Creates a new `RoomPinnedEventsEventContent` with the given events. pub fn new(pinned: Vec) -> Self { Self { pinned } } @@ -29,12 +29,13 @@ mod tests { use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_identifiers::{server_name, EventId, RoomId, UserId}; - use super::PinnedEventsEventContent; + use super::RoomPinnedEventsEventContent; use crate::{StateEvent, Unsigned}; #[test] 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"); content.pinned.push(EventId::new(&server_name)); @@ -52,7 +53,7 @@ mod tests { }; let serialized_event = serde_json::to_string(&event).unwrap(); - let parsed_event: StateEvent = + let parsed_event: StateEvent = serde_json::from_str(&serialized_event).unwrap(); assert_eq!(parsed_event.event_id, event.event_id); diff --git a/crates/ruma-events/src/room/power_levels.rs b/crates/ruma-events/src/room/power_levels.rs index 5c2ac969..8f1ac29c 100644 --- a/crates/ruma-events/src/room/power_levels.rs +++ b/crates/ruma-events/src/room/power_levels.rs @@ -18,7 +18,7 @@ use ruma_common::power_levels::NotificationPowerLevels; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.power_levels", kind = State)] -pub struct PowerLevelsEventContent { +pub struct RoomPowerLevelsEventContent { /// The level required to ban a user. /// /// If you activate the `compat` feature, deserialization will work for stringified @@ -116,8 +116,8 @@ pub struct PowerLevelsEventContent { pub notifications: NotificationPowerLevels, } -impl PowerLevelsEventContent { - /// Creates a new `PowerLevelsEventContent` with all-default values. +impl RoomPowerLevelsEventContent { + /// Creates a new `RoomPowerLevelsEventContent` with all-default values. pub fn new() -> Self { // 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. @@ -136,7 +136,7 @@ impl PowerLevelsEventContent { } } -impl Default for PowerLevelsEventContent { +impl Default for RoomPowerLevelsEventContent { fn default() -> Self { Self::new() } @@ -159,7 +159,7 @@ mod tests { use ruma_identifiers::{event_id, room_id, user_id}; 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}; #[test] @@ -167,7 +167,7 @@ mod tests { let default = default_power_level(); let power_levels_event = StateEvent { - content: PowerLevelsEventContent { + content: RoomPowerLevelsEventContent { ban: default, events: BTreeMap::new(), events_default: int!(0), @@ -206,7 +206,7 @@ mod tests { fn serialization_with_all_fields() { let user = user_id!("@carl:example.com"); let power_levels_event = StateEvent { - content: PowerLevelsEventContent { + content: RoomPowerLevelsEventContent { ban: int!(23), events: btreemap! { EventType::Dummy => int!(23) @@ -224,7 +224,7 @@ mod tests { }, event_id: event_id!("$h29iv0s8:example.com"), 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. ban: int!(42), events: btreemap! { diff --git a/crates/ruma-events/src/room/redaction.rs b/crates/ruma-events/src/room/redaction.rs index a47d098c..e05255c5 100644 --- a/crates/ruma-events/src/room/redaction.rs +++ b/crates/ruma-events/src/room/redaction.rs @@ -10,9 +10,9 @@ use crate::{Redact, RedactContent, RedactedUnsigned, Unsigned}; /// Redaction event. #[derive(Clone, Debug, Event)] #[allow(clippy::exhaustive_structs)] -pub struct RedactionEvent { +pub struct RoomRedactionEvent { /// Data specific to the event type. - pub content: RedactionEventContent, + pub content: RoomRedactionEventContent, /// The ID of the event that was redacted. pub redacts: EventId, @@ -33,15 +33,15 @@ pub struct RedactionEvent { pub unsigned: Unsigned, } -impl Redact for RedactionEvent { - type Redacted = RedactedRedactionEvent; +impl Redact for RoomRedactionEvent { + type Redacted = RedactedRoomRedactionEvent; fn redact( self, - redaction: SyncRedactionEvent, + redaction: SyncRoomRedactionEvent, version: &ruma_identifiers::RoomVersionId, ) -> Self::Redacted { - RedactedRedactionEvent { + RedactedRoomRedactionEvent { content: self.content.redact(version), // There is no released room version where this isn't redacted yet redacts: None, @@ -57,9 +57,9 @@ impl Redact for RedactionEvent { /// Redacted redaction event. #[derive(Clone, Debug, Event)] #[allow(clippy::exhaustive_structs)] -pub struct RedactedRedactionEvent { +pub struct RedactedRoomRedactionEvent { /// Data specific to the event type. - pub content: RedactedRedactionEventContent, + pub content: RedactedRoomRedactionEventContent, /// The ID of the event that was redacted. pub redacts: Option, @@ -83,9 +83,9 @@ pub struct RedactedRedactionEvent { /// Redaction event without a `room_id`. #[derive(Clone, Debug, Event)] #[allow(clippy::exhaustive_structs)] -pub struct SyncRedactionEvent { +pub struct SyncRoomRedactionEvent { /// Data specific to the event type. - pub content: RedactionEventContent, + pub content: RoomRedactionEventContent, /// The ID of the event that was redacted. pub redacts: EventId, @@ -103,15 +103,15 @@ pub struct SyncRedactionEvent { pub unsigned: Unsigned, } -impl Redact for SyncRedactionEvent { - type Redacted = RedactedSyncRedactionEvent; +impl Redact for SyncRoomRedactionEvent { + type Redacted = RedactedSyncRoomRedactionEvent; fn redact( self, - redaction: SyncRedactionEvent, + redaction: SyncRoomRedactionEvent, version: &ruma_identifiers::RoomVersionId, ) -> Self::Redacted { - RedactedSyncRedactionEvent { + RedactedSyncRoomRedactionEvent { content: self.content.redact(version), // There is no released room version where this isn't redacted yet redacts: None, @@ -126,9 +126,9 @@ impl Redact for SyncRedactionEvent { /// Redacted redaction event without a `room_id`. #[derive(Clone, Debug, Event)] #[allow(clippy::exhaustive_structs)] -pub struct RedactedSyncRedactionEvent { +pub struct RedactedSyncRoomRedactionEvent { /// Data specific to the event type. - pub content: RedactedRedactionEventContent, + pub content: RedactedRoomRedactionEventContent, /// The ID of the event that was redacted. pub redacts: Option, @@ -150,19 +150,19 @@ pub struct RedactedSyncRedactionEvent { #[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.redaction", kind = Message)] -pub struct RedactionEventContent { +pub struct RoomRedactionEventContent { /// The reason for the redaction, if any. #[serde(skip_serializing_if = "Option::is_none")] pub reason: Option, } -impl RedactionEventContent { - /// Creates an empty `RedactionEventContent`. +impl RoomRedactionEventContent { + /// Creates an empty `RoomRedactionEventContent`. pub fn new() -> Self { 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 { Self { reason: Some(reason) } } diff --git a/crates/ruma-events/src/room/server_acl.rs b/crates/ruma-events/src/room/server_acl.rs index 9f7b9a4b..d59173af 100644 --- a/crates/ruma-events/src/room/server_acl.rs +++ b/crates/ruma-events/src/room/server_acl.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. /// /// 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, } -impl ServerAclEventContent { - /// Creates a new `ServerAclEventContent` with the given IP literal allowance flag, allowed and - /// denied servers. +impl RoomServerAclEventContent { + /// Creates a new `RoomServerAclEventContent` with the given IP literal allowance flag, allowed + /// and denied servers. pub fn new(allow_ip_literals: bool, allow: Vec, deny: Vec) -> Self { Self { allow_ip_literals, allow, deny } } @@ -49,7 +49,7 @@ impl ServerAclEventContent { mod tests { use serde_json::{from_value as from_json_value, json}; - use super::ServerAclEventContent; + use super::RoomServerAclEventContent; use crate::StateEvent; #[test] @@ -64,7 +64,7 @@ mod tests { "type": "m.room.server_acl" }); - let server_acl_event: StateEvent = + let server_acl_event: StateEvent = from_json_value(json_data).unwrap(); assert!(server_acl_event.content.allow_ip_literals); diff --git a/crates/ruma-events/src/room/third_party_invite.rs b/crates/ruma-events/src/room/third_party_invite.rs index 34d33bc4..dc2e654e 100644 --- a/crates/ruma-events/src/room/third_party_invite.rs +++ b/crates/ruma-events/src/room/third_party_invite.rs @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. /// /// 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>, } -impl ThirdPartyInviteEventContent { - /// Creates a new `ThirdPartyInviteEventContent` with the given display name, key validity url - /// and public key. +impl RoomThirdPartyInviteEventContent { + /// Creates a new `RoomThirdPartyInviteEventContent` with the given display name, key validity + /// url and public key. 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 } } diff --git a/crates/ruma-events/src/room/tombstone.rs b/crates/ruma-events/src/room/tombstone.rs index c232b73c..97028d4f 100644 --- a/crates/ruma-events/src/room/tombstone.rs +++ b/crates/ruma-events/src/room/tombstone.rs @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.room.tombstone", kind = State)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct TombstoneEventContent { +pub struct RoomTombstoneEventContent { /// A server-defined message. /// /// 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, } -impl TombstoneEventContent { - /// Creates a new `TombstoneEventContent` with the given body and replacement room ID. +impl RoomTombstoneEventContent { + /// Creates a new `RoomTombstoneEventContent` with the given body and replacement room ID. pub fn new(body: String, replacement_room: RoomId) -> Self { Self { body, replacement_room } } diff --git a/crates/ruma-events/src/room/topic.rs b/crates/ruma-events/src/room/topic.rs index a8a0ce12..b2fe7aed 100644 --- a/crates/ruma-events/src/room/topic.rs +++ b/crates/ruma-events/src/room/topic.rs @@ -9,13 +9,13 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.room.topic", kind = State)] -pub struct TopicEventContent { +pub struct RoomTopicEventContent { /// The topic text. pub topic: String, } -impl TopicEventContent { - /// Creates a new `TopicEventContent` with the given topic. +impl RoomTopicEventContent { + /// Creates a new `RoomTopicEventContent` with the given topic. pub fn new(topic: String) -> Self { Self { topic } } diff --git a/crates/ruma-events/src/secret/request.rs b/crates/ruma-events/src/secret/request.rs index f86f51a4..26511a51 100644 --- a/crates/ruma-events/src/secret/request.rs +++ b/crates/ruma-events/src/secret/request.rs @@ -15,7 +15,7 @@ use serde::{ser::SerializeStruct, Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.secret.request", kind = ToDevice)] -pub struct ToDeviceRequestEventContent { +pub struct ToDeviceSecretRequestEventContent { /// The action for the request. #[serde(flatten)] pub action: RequestAction, @@ -31,7 +31,7 @@ pub struct ToDeviceRequestEventContent { pub request_id: String, } -impl ToDeviceRequestEventContent { +impl ToDeviceSecretRequestEventContent { /// Creates a new `ToDeviceRequestEventContent` with the given action, requesting device ID and /// request ID. pub fn new( @@ -133,13 +133,13 @@ pub enum SecretName { #[cfg(test)] mod test { - use super::{RequestAction, SecretName, ToDeviceRequestEventContent}; + use super::{RequestAction, SecretName, ToDeviceSecretRequestEventContent}; use matches::assert_matches; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; #[test] fn secret_request_serialization() { - let content = ToDeviceRequestEventContent::new( + let content = ToDeviceSecretRequestEventContent::new( RequestAction::Request("org.example.some.secret".into()), "ABCDEFG".into(), "randomly_generated_id_9573".into(), @@ -157,7 +157,7 @@ mod test { #[test] fn secret_request_recovery_key_serialization() { - let content = ToDeviceRequestEventContent::new( + let content = ToDeviceSecretRequestEventContent::new( RequestAction::Request(SecretName::RecoveryKey), "XYZxyz".into(), "this_is_a_request_id".into(), @@ -175,7 +175,7 @@ mod test { #[test] fn secret_custom_action_serialization() { - let content = ToDeviceRequestEventContent::new( + let content = ToDeviceSecretRequestEventContent::new( RequestAction::_Custom("my_custom_action".into()), "XYZxyz".into(), "this_is_a_request_id".into(), @@ -192,7 +192,7 @@ mod test { #[test] fn secret_request_cancellation_serialization() { - let content = ToDeviceRequestEventContent::new( + let content = ToDeviceSecretRequestEventContent::new( RequestAction::RequestCancellation, "ABCDEFG".into(), "randomly_generated_id_9573".into(), @@ -218,7 +218,7 @@ mod test { assert_matches!( from_json_value(json).unwrap(), - ToDeviceRequestEventContent { + ToDeviceSecretRequestEventContent { action: RequestAction::Request( secret ), @@ -241,7 +241,7 @@ mod test { assert_matches!( from_json_value(json).unwrap(), - ToDeviceRequestEventContent { + ToDeviceSecretRequestEventContent { action: RequestAction::RequestCancellation, requesting_device_id, request_id, @@ -262,7 +262,7 @@ mod test { assert_matches!( from_json_value(json).unwrap(), - ToDeviceRequestEventContent { + ToDeviceSecretRequestEventContent { action: RequestAction::Request( SecretName::RecoveryKey ), @@ -283,8 +283,8 @@ mod test { }); assert_matches!( - from_json_value::(json).unwrap(), - ToDeviceRequestEventContent { + from_json_value::(json).unwrap(), + ToDeviceSecretRequestEventContent { action, requesting_device_id, request_id, diff --git a/crates/ruma-events/src/secret/send.rs b/crates/ruma-events/src/secret/send.rs index a06ee643..a969018e 100644 --- a/crates/ruma-events/src/secret/send.rs +++ b/crates/ruma-events/src/secret/send.rs @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. pub request_id: String, @@ -20,7 +20,7 @@ pub struct ToDeviceSendEventContent { pub secret: String, } -impl ToDeviceSendEventContent { +impl ToDeviceSecretSendEventContent { /// Creates a new `SecretSendEventContent` with the given request ID and secret. pub fn new(request_id: String, secret: String) -> Self { Self { request_id, secret } diff --git a/crates/ruma-events/src/space/child.rs b/crates/ruma-events/src/space/child.rs index dc35bff8..4154a1a5 100644 --- a/crates/ruma-events/src/space/child.rs +++ b/crates/ruma-events/src/space/child.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. #[serde(skip_serializing_if = "Option::is_none")] pub via: Option>, @@ -41,7 +41,7 @@ pub struct ChildEventContent { pub suggested: Option, } -impl ChildEventContent { +impl SpaceChildEventContent { /// Creates a new `ChildEventContent`. pub fn new() -> Self { Self::default() @@ -50,13 +50,13 @@ impl ChildEventContent { #[cfg(test)] mod tests { - use super::ChildEventContent; + use super::SpaceChildEventContent; use ruma_identifiers::server_name; use serde_json::{json, to_value as to_json_value}; #[test] fn space_child_serialization() { - let content = ChildEventContent { + let content = SpaceChildEventContent { via: Some(vec![server_name!("example.com")]), order: Some("uwu".to_owned()), suggested: Some(false), @@ -73,7 +73,7 @@ mod tests { #[test] 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!({}); diff --git a/crates/ruma-events/src/space/parent.rs b/crates/ruma-events/src/space/parent.rs index 361b4069..78388d75 100644 --- a/crates/ruma-events/src/space/parent.rs +++ b/crates/ruma-events/src/space/parent.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[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. #[serde(skip_serializing_if = "Option::is_none")] pub via: Option>, @@ -29,7 +29,7 @@ pub struct ParentEventContent { pub canonical: bool, } -impl ParentEventContent { +impl SpaceParentEventContent { /// Creates a new `ParentEventContent` with the given canonical flag. pub fn new(canonical: bool) -> Self { Self { via: None, canonical } @@ -38,14 +38,16 @@ impl ParentEventContent { #[cfg(test)] mod tests { - use super::ParentEventContent; + use super::SpaceParentEventContent; use ruma_identifiers::server_name; use serde_json::{json, to_value as to_json_value}; #[test] fn space_parent_serialization() { - let content = - ParentEventContent { via: Some(vec![server_name!("example.com")]), canonical: true }; + let content = SpaceParentEventContent { + via: Some(vec![server_name!("example.com")]), + canonical: true, + }; let json = json!({ "via": ["example.com"], @@ -57,7 +59,7 @@ mod tests { #[test] fn space_parent_empty_serialization() { - let content = ParentEventContent { via: None, canonical: true }; + let content = SpaceParentEventContent { via: None, canonical: true }; let json = json!({ "canonical": true, diff --git a/crates/ruma-events/src/unsigned.rs b/crates/ruma-events/src/unsigned.rs index 416f42d3..a815990f 100644 --- a/crates/ruma-events/src/unsigned.rs +++ b/crates/ruma-events/src/unsigned.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "unstable-pre-spec")] 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. #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -51,7 +51,7 @@ impl Unsigned { pub struct RedactedUnsigned { /// The event that redacted this event, if any. #[serde(skip_serializing_if = "Option::is_none")] - pub redacted_because: Option>, + pub redacted_because: Option>, } impl RedactedUnsigned { @@ -61,7 +61,7 @@ impl RedactedUnsigned { } /// Create a new `RedactedUnsigned` with the given redacted because. - pub fn new_because(redacted_because: Box) -> Self { + pub fn new_because(redacted_because: Box) -> Self { Self { redacted_because: Some(redacted_because) } } @@ -110,7 +110,7 @@ impl From for Unsigned { #[derive(Deserialize)] pub struct RedactedUnsignedWithPrevContent { #[serde(skip_serializing_if = "Option::is_none")] - redacted_because: Option>, + redacted_because: Option>, pub prev_content: Option>, } diff --git a/crates/ruma-events/tests/compat.rs b/crates/ruma-events/tests/compat.rs index 625bc0d1..3d523650 100644 --- a/crates/ruma-events/tests/compat.rs +++ b/crates/ruma-events/tests/compat.rs @@ -1,12 +1,12 @@ #![cfg(feature = "compat")] 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}; #[test] fn deserialize_unsigned_prev_content() { - let res = from_json_value::(json!({ + let res = from_json_value::(json!({ "content": { "topic": "New room topic", }, @@ -26,9 +26,9 @@ fn deserialize_unsigned_prev_content() { assert_matches!( res, - Ok(TopicEvent { - content: TopicEventContent { topic: new_topic, .. }, - prev_content: Some(TopicEventContent { topic: old_topic, .. }), + Ok(RoomTopicEvent { + content: RoomTopicEventContent { topic: new_topic, .. }, + prev_content: Some(RoomTopicEventContent { topic: old_topic, .. }), .. }) if new_topic == "New room topic" && old_topic == "Old room topic" diff --git a/crates/ruma-events/tests/enums.rs b/crates/ruma-events/tests/enums.rs index 94cc9eff..e94df9a1 100644 --- a/crates/ruma-events/tests/enums.rs +++ b/crates/ruma-events/tests/enums.rs @@ -7,9 +7,9 @@ use serde_json::{from_value as from_json_value, json, Value as JsonValue}; use ruma_events::{ room::{ - aliases::AliasesEventContent, - message::{MessageEventContent, MessageType, TextMessageEventContent}, - power_levels::PowerLevelsEventContent, + aliases::RoomAliasesEventContent, + message::{MessageType, RoomMessageEventContent, TextMessageEventContent}, + power_levels::RoomPowerLevelsEventContent, }, AnyEphemeralRoomEvent, AnyMessageEvent, AnyRoomEvent, AnyStateEvent, AnyStateEventContent, AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent, EphemeralRoomEventType, EventType, @@ -123,7 +123,7 @@ fn power_event_sync_deserialization() { from_json_value::(json_data), Ok(AnySyncRoomEvent::State( AnySyncStateEvent::RoomPowerLevels(SyncStateEvent { - content: PowerLevelsEventContent { + content: RoomPowerLevelsEventContent { ban, .. }, .. @@ -141,7 +141,7 @@ fn message_event_sync_deserialization() { from_json_value::(json_data), Ok(AnySyncRoomEvent::Message( AnySyncMessageEvent::RoomMessage(SyncMessageEvent { - content: MessageEventContent { + content: RoomMessageEventContent { msgtype: MessageType::Text(TextMessageEventContent { body, formatted: Some(formatted), @@ -164,7 +164,7 @@ fn aliases_event_sync_deserialization() { from_json_value::(json_data), Ok(AnySyncRoomEvent::State( AnySyncStateEvent::RoomAliases(SyncStateEvent { - content: AliasesEventContent { + content: RoomAliasesEventContent { aliases, .. }, @@ -183,7 +183,7 @@ fn message_room_event_deserialization() { from_json_value::(json_data), Ok(AnyRoomEvent::Message( AnyMessageEvent::RoomMessage(MessageEvent { - content: MessageEventContent { + content: RoomMessageEventContent { msgtype: MessageType::Text(TextMessageEventContent { body, formatted: Some(formatted), @@ -201,7 +201,7 @@ fn message_room_event_deserialization() { #[test] fn message_event_serialization() { let event = MessageEvent { - content: MessageEventContent::text_plain("test"), + content: RoomMessageEventContent::text_plain("test"), event_id: event_id!("$1234:example.com"), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(0)), room_id: room_id!("!roomid:example.com"), @@ -223,7 +223,7 @@ fn alias_room_event_deserialization() { from_json_value::(json_data), Ok(AnyRoomEvent::State( AnyStateEvent::RoomAliases(StateEvent { - content: AliasesEventContent { + content: RoomAliasesEventContent { aliases, .. }, @@ -242,7 +242,7 @@ fn message_event_deserialization() { from_json_value::(json_data), Ok(AnyRoomEvent::Message( AnyMessageEvent::RoomMessage(MessageEvent { - content: MessageEventContent { + content: RoomMessageEventContent { msgtype: MessageType::Text(TextMessageEventContent { body, formatted: Some(formatted), @@ -265,7 +265,7 @@ fn alias_event_deserialization() { from_json_value::(json_data), Ok(AnyRoomEvent::State( AnyStateEvent::RoomAliases(StateEvent { - content: AliasesEventContent { + content: RoomAliasesEventContent { aliases, .. }, @@ -290,7 +290,8 @@ fn alias_event_field_access() { ); let deser = from_json_value::(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")]) } else { diff --git a/crates/ruma-events/tests/event_enums.rs b/crates/ruma-events/tests/event_enums.rs index 0c434421..11bf09d2 100644 --- a/crates/ruma-events/tests/event_enums.rs +++ b/crates/ruma-events/tests/event_enums.rs @@ -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 ruma_events::{ - call::{answer::AnswerEventContent, SessionDescription, SessionDescriptionType}, + call::{answer::CallAnswerEventContent, SessionDescription, SessionDescriptionType}, room::{ImageInfo, ThumbnailInfo}, sticker::StickerEventContent, AnyMessageEvent, MessageEvent, Unsigned, @@ -42,7 +42,7 @@ fn deserialize_message_event() { from_json_value::(json_data) .unwrap(), AnyMessageEvent::CallAnswer(MessageEvent { - content: AnswerEventContent { + content: CallAnswerEventContent { answer: SessionDescription { session_type: SessionDescriptionType::Answer, sdp, diff --git a/crates/ruma-events/tests/message_event.rs b/crates/ruma-events/tests/message_event.rs index 1d3e1560..e2a487b5 100644 --- a/crates/ruma-events/tests/message_event.rs +++ b/crates/ruma-events/tests/message_event.rs @@ -3,7 +3,7 @@ use js_int::{uint, UInt}; use matches::assert_matches; use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_events::{ - call::{answer::AnswerEventContent, SessionDescription, SessionDescriptionType}, + call::{answer::CallAnswerEventContent, SessionDescription, SessionDescriptionType}, room::{ImageInfo, ThumbnailInfo}, sticker::StickerEventContent, AnyMessageEvent, AnyMessageEventContent, AnySyncMessageEvent, MessageEvent, RawExt, Unsigned, @@ -84,7 +84,7 @@ fn deserialize_message_call_answer_content() { .unwrap() .deserialize_content("m.call.answer") .unwrap(), - AnyMessageEventContent::CallAnswer(AnswerEventContent { + AnyMessageEventContent::CallAnswer(CallAnswerEventContent { answer: SessionDescription { session_type: SessionDescriptionType::Answer, sdp, @@ -118,7 +118,7 @@ fn deserialize_message_call_answer() { assert_matches!( from_json_value::(json_data).unwrap(), AnyMessageEvent::CallAnswer(MessageEvent { - content: AnswerEventContent { + content: CallAnswerEventContent { answer: SessionDescription { session_type: SessionDescriptionType::Answer, sdp, @@ -249,7 +249,7 @@ fn deserialize_message_then_convert_to_full() { assert_matches!( from_json_value::(full_json).unwrap(), AnyMessageEvent::CallAnswer(MessageEvent { - content: AnswerEventContent { + content: CallAnswerEventContent { answer: SessionDescription { session_type: SessionDescriptionType::Answer, sdp, diff --git a/crates/ruma-events/tests/redacted.rs b/crates/ruma-events/tests/redacted.rs index db266454..99e51bca 100644 --- a/crates/ruma-events/tests/redacted.rs +++ b/crates/ruma-events/tests/redacted.rs @@ -4,10 +4,10 @@ use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_events::{ custom::RedactedCustomEventContent, room::{ - aliases::RedactedAliasesEventContent, - create::RedactedCreateEventContent, - message::RedactedMessageEventContent, - redaction::{RedactionEventContent, SyncRedactionEvent}, + aliases::RedactedRoomAliasesEventContent, + create::RedactedRoomCreateEventContent, + message::RedactedRoomMessageEventContent, + redaction::{RoomRedactionEventContent, SyncRoomRedactionEvent}, }, AnyMessageEvent, AnyMessageEventContent, AnyRedactedMessageEvent, AnyRedactedMessageEventContent, AnyRedactedStateEventContent, AnyRedactedSyncMessageEvent, @@ -22,8 +22,8 @@ use serde_json::{ fn unsigned() -> RedactedUnsigned { let mut unsigned = RedactedUnsigned::default(); - unsigned.redacted_because = Some(Box::new(SyncRedactionEvent { - content: RedactionEventContent::with_reason("redacted because".into()), + unsigned.redacted_because = Some(Box::new(SyncRoomRedactionEvent { + content: RoomRedactionEventContent::with_reason("redacted because".into()), redacts: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), @@ -37,7 +37,7 @@ fn unsigned() -> RedactedUnsigned { #[test] fn redacted_message_event_serialize() { let redacted = RedactedSyncMessageEvent { - content: RedactedMessageEventContent::new(), + content: RedactedRoomMessageEventContent::new(), event_id: event_id!("$h29iv0s8:example.com"), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), sender: user_id!("@carl:example.com"), @@ -58,7 +58,7 @@ fn redacted_message_event_serialize() { #[test] fn redacted_aliases_event_serialize_no_content() { let redacted = RedactedSyncStateEvent { - content: RedactedAliasesEventContent::default(), + content: RedactedRoomAliasesEventContent::default(), event_id: event_id!("$h29iv0s8:example.com"), state_key: "".into(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), @@ -81,7 +81,7 @@ fn redacted_aliases_event_serialize_no_content() { #[test] fn redacted_aliases_event_serialize_with_content() { let redacted = RedactedSyncStateEvent { - content: RedactedAliasesEventContent::new_v1(vec![]), + content: RedactedRoomAliasesEventContent::new_v1(vec![]), event_id: event_id!("$h29iv0s8:example.com"), state_key: "".to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), @@ -121,7 +121,7 @@ fn redacted_aliases_deserialize() { from_json_value::(actual).unwrap(), AnySyncRoomEvent::RedactedState(AnyRedactedSyncStateEvent::RoomAliases( RedactedSyncStateEvent { - content: RedactedAliasesEventContent { aliases, .. }, + content: RedactedRoomAliasesEventContent { aliases, .. }, event_id, .. }, @@ -146,7 +146,7 @@ fn redacted_deserialize_any_room() { assert_matches!( from_json_value::(actual).unwrap(), AnyRoomEvent::RedactedMessage(AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent { - content: RedactedMessageEventContent { .. }, + content: RedactedRoomMessageEventContent { .. }, event_id, room_id, .. })) if event_id == event_id!("$h29iv0s8:example.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) // to return early with `RedactedContent` instead of failing to deserialize according // to the event type string. - unsigned.redacted_because = Some(Box::new(SyncRedactionEvent { - content: RedactionEventContent::with_reason("redacted because".into()), + unsigned.redacted_because = Some(Box::new(SyncRoomRedactionEvent { + content: RoomRedactionEventContent::with_reason("redacted because".into()), redacts: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), @@ -182,7 +182,7 @@ fn redacted_deserialize_any_room_sync() { from_json_value::(actual).unwrap(), AnySyncRoomEvent::RedactedMessage(AnyRedactedSyncMessageEvent::RoomMessage( RedactedSyncMessageEvent { - content: RedactedMessageEventContent { .. }, + content: RedactedRoomMessageEventContent { .. }, event_id, .. } @@ -209,7 +209,7 @@ fn redacted_state_event_deserialize() { .unwrap(), AnySyncRoomEvent::RedactedState(AnyRedactedSyncStateEvent::RoomCreate( RedactedSyncStateEvent { - content: RedactedCreateEventContent { + content: RedactedRoomCreateEventContent { creator, .. }, event_id, @@ -285,8 +285,8 @@ fn redact_method_properly_redacts() { } }); - let redaction = SyncRedactionEvent { - content: RedactionEventContent::with_reason("redacted because".into()), + let redaction = SyncRoomRedactionEvent { + content: RoomRedactionEventContent::with_reason("redacted because".into()), redacts: event_id!("$143273582443PhrSn:example.com"), event_id: event_id!("$h29iv0s8:example.com"), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), @@ -299,7 +299,7 @@ fn redact_method_properly_redacts() { assert_matches!( event.redact(redaction, &RoomVersionId::Version6), AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent { - content: RedactedMessageEventContent { .. }, + content: RedactedRoomMessageEventContent { .. }, event_id, room_id, sender, @@ -326,7 +326,7 @@ fn redact_message_content() { assert_matches!( content.redact(&RoomVersionId::Version6), - AnyRedactedMessageEventContent::RoomMessage(RedactedMessageEventContent { .. }) + AnyRedactedMessageEventContent::RoomMessage(RedactedRoomMessageEventContent { .. }) ); } @@ -343,7 +343,7 @@ fn redact_state_content() { assert_matches!( content.redact(&RoomVersionId::Version6), - AnyRedactedStateEventContent::RoomCreate(RedactedCreateEventContent { + AnyRedactedStateEventContent::RoomCreate(RedactedRoomCreateEventContent { creator, .. }) if creator == user_id!("@carl:example.com") diff --git a/crates/ruma-events/tests/redaction.rs b/crates/ruma-events/tests/redaction.rs index 4a97a6cf..13b84b5c 100644 --- a/crates/ruma-events/tests/redaction.rs +++ b/crates/ruma-events/tests/redaction.rs @@ -2,7 +2,7 @@ use js_int::uint; use matches::assert_matches; use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_events::{ - room::redaction::{RedactionEvent, RedactionEventContent}, + room::redaction::{RoomRedactionEvent, RoomRedactionEventContent}, AnyMessageEvent, Unsigned, }; use ruma_identifiers::{event_id, room_id, user_id}; @@ -26,8 +26,8 @@ fn redaction() -> JsonValue { #[test] fn serialize_redaction() { - let aliases_event = RedactionEvent { - content: RedactionEventContent::with_reason("being a turd".into()), + let aliases_event = RoomRedactionEvent { + content: RoomRedactionEventContent::with_reason("being a turd".into()), redacts: event_id!("$nomore:example.com"), event_id: event_id!("$h29iv0s8:example.com"), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), @@ -48,8 +48,8 @@ fn deserialize_redaction() { assert_matches!( from_json_value::(json_data).unwrap(), - AnyMessageEvent::RoomRedaction(RedactionEvent { - content: RedactionEventContent { reason: Some(reas), .. }, + AnyMessageEvent::RoomRedaction(RoomRedactionEvent { + content: RoomRedactionEventContent { reason: Some(reas), .. }, redacts, event_id, origin_server_ts, diff --git a/crates/ruma-events/tests/room_message.rs b/crates/ruma-events/tests/room_message.rs index 54376175..f362bbc1 100644 --- a/crates/ruma-events/tests/room_message.rs +++ b/crates/ruma-events/tests/room_message.rs @@ -10,8 +10,8 @@ use ruma_events::{ }; use ruma_events::{ room::message::{ - AudioMessageEventContent, InReplyTo, MessageEvent, MessageEventContent, MessageType, - Relation, TextMessageEventContent, + AudioMessageEventContent, InReplyTo, MessageType, Relation, RoomMessageEvent, + RoomMessageEventContent, TextMessageEventContent, }, Unsigned, }; @@ -34,8 +34,8 @@ macro_rules! json_object { #[test] fn serialization() { - let ev = MessageEvent { - content: MessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain( + let ev = RoomMessageEvent { + content: RoomMessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain( "test".into(), mxc_uri!("mxc://example.org/ffed755USFFxlgbQYZGtryd"), None, @@ -67,7 +67,7 @@ fn serialization() { #[test] fn content_serialization() { let message_event_content = - MessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain( + RoomMessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain( "test".into(), mxc_uri!("mxc://example.org/ffed755USFFxlgbQYZGtryd"), None, @@ -127,7 +127,7 @@ fn custom_content_deserialization() { #[test] fn formatted_body_serialization() { let message_event_content = - MessageEventContent::text_html("Hello, World!", "Hello, World!"); + RoomMessageEventContent::text_html("Hello, World!", "Hello, World!"); assert_eq!( to_json_value(&message_event_content).unwrap(), @@ -143,7 +143,7 @@ fn formatted_body_serialization() { #[test] fn plain_text_content_serialization() { 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!( to_json_value(&message_event_content).unwrap(), @@ -157,7 +157,7 @@ fn plain_text_content_serialization() { #[test] #[cfg(feature = "markdown")] fn markdown_content_serialization() { - let formatted_message = MessageEventContent::new(MessageType::Text( + let formatted_message = RoomMessageEventContent::new(MessageType::Text( 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…"), )); @@ -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."), )); @@ -201,7 +201,7 @@ fn markdown_content_serialization() { #[test] fn relates_to_content_serialization() { 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 { in_reply_to: InReplyTo::new(event_id!("$15827405538098VGFWH:example.com")), }), @@ -236,8 +236,8 @@ fn edit_deserialization_061() { }); assert_matches!( - from_json_value::(json_data).unwrap(), - MessageEventContent { + from_json_value::(json_data).unwrap(), + RoomMessageEventContent { msgtype: MessageType::Text(TextMessageEventContent { body, formatted: None, @@ -269,8 +269,8 @@ fn edit_deserialization_future() { }); assert_matches!( - from_json_value::(json_data).unwrap(), - MessageEventContent { + from_json_value::(json_data).unwrap(), + RoomMessageEventContent { msgtype: MessageType::Text(TextMessageEventContent { body, formatted: None, @@ -282,7 +282,7 @@ fn edit_deserialization_future() { && event_id == ev_id && matches!( &*new_content, - MessageEventContent { + RoomMessageEventContent { msgtype: MessageType::Text(TextMessageEventContent { body, formatted: None, @@ -313,8 +313,8 @@ fn verification_request_deserialization() { }); assert_matches!( - from_json_value::(json_data).unwrap(), - MessageEventContent { + from_json_value::(json_data).unwrap(), + RoomMessageEventContent { msgtype: MessageType::VerificationRequest(KeyVerificationRequestEventContent { body, to, @@ -367,9 +367,9 @@ fn content_deserialization() { }); assert_matches!( - from_json_value::(json_data) + from_json_value::(json_data) .unwrap(), - MessageEventContent { + RoomMessageEventContent { msgtype: MessageType::Audio(AudioMessageEventContent { body, info: None, @@ -388,5 +388,5 @@ fn content_deserialization_failure() { "body": "test","msgtype": "m.location", "url": "http://example.com/audio.mp3" }); - assert!(from_json_value::(json_data).is_err()); + assert!(from_json_value::(json_data).is_err()); } diff --git a/crates/ruma-events/tests/state_event.rs b/crates/ruma-events/tests/state_event.rs index 2310dbd0..c7fe8e6c 100644 --- a/crates/ruma-events/tests/state_event.rs +++ b/crates/ruma-events/tests/state_event.rs @@ -3,8 +3,8 @@ use matches::assert_matches; use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_events::{ room::{ - aliases::AliasesEventContent, - avatar::{AvatarEventContent, ImageInfo}, + aliases::RoomAliasesEventContent, + avatar::{ImageInfo, RoomAvatarEventContent}, ThumbnailInfo, }, AnyRoomEvent, AnyStateEvent, AnyStateEventContent, AnySyncStateEvent, RawExt, StateEvent, @@ -36,10 +36,10 @@ fn aliases_event_with_prev_content() -> JsonValue { #[test] fn serialize_aliases_with_prev_content() { 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"), 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"), sender: user_id!("@carl:example.com"), state_key: "".into(), @@ -55,7 +55,7 @@ fn serialize_aliases_with_prev_content() { #[test] fn serialize_aliases_without_prev_content() { 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"), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), prev_content: None, @@ -184,7 +184,7 @@ fn deserialize_avatar_without_prev_content() { assert_matches!( from_json_value::(json_data).unwrap(), AnyStateEvent::RoomAvatar(StateEvent { - content: AvatarEventContent { + content: RoomAvatarEventContent { info: Some(info), url, .. diff --git a/crates/ruma-events/tests/stripped.rs b/crates/ruma-events/tests/stripped.rs index ceb55740..b8874a2b 100644 --- a/crates/ruma-events/tests/stripped.rs +++ b/crates/ruma-events/tests/stripped.rs @@ -2,7 +2,7 @@ use std::convert::TryFrom; use js_int::uint; use ruma_events::{ - room::{join_rules::JoinRule, topic::TopicEventContent}, + room::{join_rules::JoinRule, topic::RoomTopicEventContent}, AnyStrippedStateEvent, StrippedStateEvent, }; 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] fn serialize_stripped_state_event_any_content() { let event = StrippedStateEvent { - content: TopicEventContent::new("Testing room".into()), + content: RoomTopicEventContent::new("Testing room".into()), state_key: "".into(), sender: user_id!("@example:localhost"), }; @@ -31,7 +31,7 @@ fn serialize_stripped_state_event_any_content() { #[test] fn serialize_stripped_state_event_any_event() { let event = AnyStrippedStateEvent::RoomTopic(StrippedStateEvent { - content: TopicEventContent::new("Testing room".into()), + content: RoomTopicEventContent::new("Testing room".into()), state_key: "".into(), sender: user_id!("@example:localhost"), }); diff --git a/crates/ruma-federation-api/src/knock/send_knock/v1.rs b/crates/ruma-federation-api/src/knock/send_knock/v1.rs index 7054904b..913fd863 100644 --- a/crates/ruma-federation-api/src/knock/send_knock/v1.rs +++ b/crates/ruma-federation-api/src/knock/send_knock/v1.rs @@ -1,7 +1,7 @@ //! [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_events::{room::member::MemberEvent, AnyStrippedStateEvent}; +use ruma_events::{room::member::RoomMemberEvent, AnyStrippedStateEvent}; use ruma_identifiers::{EventId, RoomId}; ruma_api! { @@ -25,7 +25,7 @@ ruma_api! { /// The full knock event. #[ruma_api(body)] - pub knock_event: &'a MemberEvent, + pub knock_event: &'a RoomMemberEvent, } response: { @@ -36,7 +36,11 @@ ruma_api! { impl<'a> Request<'a> { /// 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 } } } diff --git a/crates/ruma-federation-api/src/membership/create_invite/v1.rs b/crates/ruma-federation-api/src/membership/create_invite/v1.rs index 66ca87bc..2735d768 100644 --- a/crates/ruma-federation-api/src/membership/create_invite/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_invite/v1.rs @@ -2,7 +2,7 @@ use ruma_api::ruma_api; 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_serde::Raw; use serde::{Deserialize, Serialize}; @@ -44,7 +44,7 @@ ruma_api! { pub state_key: &'a UserId, /// The content of the event. - pub content: MemberEventContent, + pub content: RoomMemberEventContent, /// Information included alongside the event that is not signed. #[serde(default, skip_serializing_if = "UnsignedEventContent::is_empty")] @@ -105,7 +105,7 @@ pub struct RequestInit<'a> { pub state_key: &'a UserId, /// The content of the event. - pub content: MemberEventContent, + pub content: RoomMemberEventContent, /// Information included alongside the event that is not signed. pub unsigned: UnsignedEventContent, diff --git a/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs b/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs index d91b7dc7..1d83f7e0 100644 --- a/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs @@ -3,7 +3,7 @@ use js_int::UInt; use ruma_api::ruma_api; 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_serde::Raw; use serde::{Deserialize, Serialize}; @@ -50,7 +50,7 @@ ruma_api! { /// The content of the event. #[ruma_api(query)] - pub content: Raw, + pub content: Raw, /// This field must be present but is ignored; it may be 0. #[ruma_api(query)] @@ -97,7 +97,7 @@ pub struct RequestInit<'a> { pub state_key: &'a str, /// The content of the event. - pub content: Raw, + pub content: Raw, /// This field must be present but is ignored; it may be 0. pub depth: UInt, diff --git a/crates/ruma-state-res/benches/state_res_bench.rs b/crates/ruma-state-res/benches/state_res_bench.rs index 625a5d37..b77c2f65 100644 --- a/crates/ruma-state-res/benches/state_res_bench.rs +++ b/crates/ruma-state-res/benches/state_res_bench.rs @@ -24,8 +24,8 @@ use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_events::{ pdu::{EventHash, Pdu, RoomV3Pdu}, room::{ - join_rules::{JoinRule, JoinRulesEventContent}, - member::{MemberEventContent, MembershipState}, + join_rules::{JoinRule, RoomJoinRulesEventContent}, + member::{MembershipState, RoomMemberEventContent}, }, EventType, }; @@ -264,7 +264,7 @@ impl TestStore { alice(), EventType::RoomJoinRules, 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()], &[alice_mem.event_id().clone()], ); @@ -356,11 +356,11 @@ fn room_id() -> RoomId { } fn member_content_ban() -> Box { - to_raw_json_value(&MemberEventContent::new(MembershipState::Ban)).unwrap() + to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Ban)).unwrap() } fn member_content_join() -> Box { - to_raw_json_value(&MemberEventContent::new(MembershipState::Join)).unwrap() + to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Join)).unwrap() } fn to_pdu_event( @@ -441,7 +441,7 @@ fn INITIAL_EVENTS() -> HashMap> { alice(), EventType::RoomJoinRules, Some(""), - to_raw_json_value(&JoinRulesEventContent::new(JoinRule::Public)).unwrap(), + to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Public)).unwrap(), &["CREATE", "IMA", "IPOWER"], &["IPOWER"], ), diff --git a/crates/ruma-state-res/src/event_auth.rs b/crates/ruma-state-res/src/event_auth.rs index 1ee29636..b327b7cf 100644 --- a/crates/ruma-state-res/src/event_auth.rs +++ b/crates/ruma-state-res/src/event_auth.rs @@ -3,11 +3,11 @@ use std::{collections::BTreeSet, convert::TryFrom}; use js_int::{int, Int}; use ruma_events::{ room::{ - create::CreateEventContent, - join_rules::{JoinRule, JoinRulesEventContent}, + create::RoomCreateEventContent, + join_rules::{JoinRule, RoomJoinRulesEventContent}, member::{MembershipState, ThirdPartyInvite}, - power_levels::PowerLevelsEventContent, - third_party_invite::ThirdPartyInviteEventContent, + power_levels::RoomPowerLevelsEventContent, + third_party_invite::RoomThirdPartyInviteEventContent, }, EventType, }; @@ -281,7 +281,7 @@ pub fn auth_check( } else { // If no power level event found the creator gets 100 everyone else gets 0 room_create_event - .and_then(|create| from_json_str::(create.content().get()).ok()) + .and_then(|create| from_json_str::(create.content().get()).ok()) .and_then(|create| (create.creator == *sender).then(|| int!(100))) .unwrap_or_default() }; @@ -414,9 +414,9 @@ fn valid_membership_change( 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())?, - None => PowerLevelsEventContent::default(), + None => RoomPowerLevelsEventContent::default(), }; let sender_power = power_levels @@ -430,7 +430,7 @@ fn valid_membership_change( let mut join_rules = JoinRule::Invite; if let Some(jr) = &join_rules_event { - join_rules = from_json_str::(jr.content().get())?.join_rule; + join_rules = from_json_str::(jr.content().get())?.join_rule; } 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 // with values that are integers (or a string that is an integer), reject. let user_content = - from_json_str::(power_event.content().get()).unwrap(); + from_json_str::(power_event.content().get()).unwrap(); let current_content = - from_json_str::(current_state.content().get()).unwrap(); + from_json_str::(current_state.content().get()).unwrap(); // Validation of users is done in Ruma, synapse for loops validating user_ids and integers here info!("validation of power event finished"); @@ -768,7 +768,7 @@ fn get_send_level( ) -> Int { power_lvl .and_then(|ple| { - from_json_str::(ple.content().get()) + from_json_str::(ple.content().get()) .map(|content| { content.events.get(e_type).copied().unwrap_or_else(|| { 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, // allow if let Ok(tpid_ev) = - from_json_str::(current_tpid.content().get()) + from_json_str::(current_tpid.content().get()) { // A list of public keys in the public_keys field for key in tpid_ev.public_keys.unwrap_or_default() { diff --git a/crates/ruma-state-res/src/lib.rs b/crates/ruma-state-res/src/lib.rs index 9cb2d24c..eabc3724 100644 --- a/crates/ruma-state-res/src/lib.rs +++ b/crates/ruma-state-res/src/lib.rs @@ -7,7 +7,7 @@ use itertools::Itertools; use js_int::{int, Int}; use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_events::{ - room::member::{MemberEventContent, MembershipState}, + room::member::{MembershipState, RoomMemberEventContent}, EventType, }; use ruma_identifiers::{EventId, RoomVersionId, UserId}; @@ -601,7 +601,7 @@ fn is_power_event(event: impl Event) -> bool { event.state_key() == Some("") } EventType::RoomMember => { - if let Ok(content) = from_json_str::(event.content().get()) { + if let Ok(content) = from_json_str::(event.content().get()) { if [MembershipState::Leave, MembershipState::Ban].contains(&content.membership) { return Some(event.sender().as_str()) != event.state_key(); } @@ -625,7 +625,7 @@ mod tests { use rand::seq::SliceRandom; use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_events::{ - room::join_rules::{JoinRule, JoinRulesEventContent}, + room::join_rules::{JoinRule, RoomJoinRulesEventContent}, EventType, }; use ruma_identifiers::{EventId, RoomVersionId}; @@ -877,7 +877,7 @@ mod tests { alice(), EventType::RoomJoinRules, Some(""), - to_raw_json_value(&JoinRulesEventContent::new(JoinRule::Private)).unwrap(), + to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Private)).unwrap(), ), to_init_pdu_event( "ME", diff --git a/crates/ruma-state-res/src/test_utils.rs b/crates/ruma-state-res/src/test_utils.rs index fcb33f95..5acab6bd 100644 --- a/crates/ruma-state-res/src/test_utils.rs +++ b/crates/ruma-state-res/src/test_utils.rs @@ -12,8 +12,8 @@ use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_events::{ pdu::{EventHash, Pdu, RoomV3Pdu}, room::{ - join_rules::{JoinRule, JoinRulesEventContent}, - member::{MemberEventContent, MembershipState}, + join_rules::{JoinRule, RoomJoinRulesEventContent}, + member::{MembershipState, RoomMemberEventContent}, }, EventType, }; @@ -269,7 +269,7 @@ impl TestStore { alice(), EventType::RoomJoinRules, 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()], &[alice_mem.event_id().clone()], ); @@ -365,11 +365,11 @@ pub fn room_id() -> RoomId { } pub fn member_content_ban() -> Box { - to_raw_json_value(&MemberEventContent::new(MembershipState::Ban)).unwrap() + to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Ban)).unwrap() } pub fn member_content_join() -> Box { - to_raw_json_value(&MemberEventContent::new(MembershipState::Join)).unwrap() + to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Join)).unwrap() } pub fn to_init_pdu_event( @@ -481,7 +481,7 @@ pub fn INITIAL_EVENTS() -> HashMap> { alice(), EventType::RoomJoinRules, Some(""), - to_raw_json_value(&JoinRulesEventContent::new(JoinRule::Public)).unwrap(), + to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Public)).unwrap(), &["CREATE", "IMA", "IPOWER"], &["IPOWER"], ), diff --git a/crates/ruma/examples/hello_isahc.rs b/crates/ruma/examples/hello_isahc.rs index 06303df6..ec4fd8f1 100644 --- a/crates/ruma/examples/hello_isahc.rs +++ b/crates/ruma/examples/hello_isahc.rs @@ -5,7 +5,7 @@ use std::{convert::TryFrom, env, process::exit}; use ruma::{ api::client::r0::{alias::get_alias, membership::join_room_by_id, message::send_message_event}, - events::room::message::MessageEventContent, + events::room::message::RoomMessageEventContent, RoomAliasId, }; @@ -27,7 +27,7 @@ async fn hello_world( .send_request(send_message_event::Request::new( &room_id, "1", - &MessageEventContent::text_plain("Hello World!"), + &RoomMessageEventContent::text_plain("Hello World!"), )?) .await?; diff --git a/crates/ruma/examples/hello_world.rs b/crates/ruma/examples/hello_world.rs index 9388670f..e2e40197 100644 --- a/crates/ruma/examples/hello_world.rs +++ b/crates/ruma/examples/hello_world.rs @@ -2,7 +2,7 @@ use std::{convert::TryFrom, env, process::exit}; use ruma::{ api::client::r0::{alias::get_alias, membership::join_room_by_id, message::send_message_event}, - events::room::message::MessageEventContent, + events::room::message::RoomMessageEventContent, RoomAliasId, }; @@ -23,7 +23,7 @@ async fn hello_world( .send_request(send_message_event::Request::new( &room_id, "1", - &MessageEventContent::text_plain("Hello World!"), + &RoomMessageEventContent::text_plain("Hello World!"), )?) .await?; diff --git a/crates/ruma/examples/message_log.rs b/crates/ruma/examples/message_log.rs index 551f9e17..4bc98510 100644 --- a/crates/ruma/examples/message_log.rs +++ b/crates/ruma/examples/message_log.rs @@ -4,7 +4,7 @@ use assign::assign; use ruma::{ api::client::r0::{filter::FilterDefinition, sync::sync_events}, events::{ - room::message::{MessageEventContent, MessageType, TextMessageEventContent}, + room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent}, AnySyncMessageEvent, AnySyncRoomEvent, SyncMessageEvent, }, presence::PresenceState, @@ -44,7 +44,7 @@ async fn log_messages( if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage( SyncMessageEvent { content: - MessageEventContent { + RoomMessageEventContent { msgtype: MessageType::Text(TextMessageEventContent { body: msg_body, ..