From 489f51e2314adadbecc4931c69b4fa736d38c41a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 8 Apr 2022 10:51:02 +0200 Subject: [PATCH] events: Replace most Boxs with new owned ID types --- .../src/events/forwarded_room_key.rs | 6 +++--- crates/ruma-common/src/events/fully_read.rs | 6 +++--- .../src/events/key/verification/accept.rs | 6 +++--- .../src/events/key/verification/cancel.rs | 6 +++--- .../src/events/key/verification/done.rs | 6 +++--- .../src/events/key/verification/key.rs | 6 +++--- .../src/events/key/verification/mac.rs | 6 +++--- .../src/events/key/verification/ready.rs | 20 +++++++++---------- .../src/events/key/verification/request.rs | 10 +++++----- .../src/events/key/verification/start.rs | 14 ++++++------- crates/ruma-common/src/events/reaction.rs | 6 +++--- crates/ruma-common/src/events/relation.rs | 8 ++++---- .../src/events/room/canonical_alias.rs | 4 ++-- crates/ruma-common/src/events/room/create.rs | 8 ++++---- .../ruma-common/src/events/room/encrypted.rs | 12 +++++------ crates/ruma-common/src/events/room/member.rs | 4 ++-- crates/ruma-common/src/events/room/message.rs | 6 +++--- .../src/events/room/message/feedback.rs | 6 +++--- .../ruma-common/src/events/room/tombstone.rs | 6 +++--- .../src/events/room_key_request.rs | 15 +++++++------- .../ruma-common/src/events/secret/request.rs | 10 +++++----- crates/ruma-common/src/events/secret/send.rs | 6 +++--- crates/ruma-common/src/events/unsigned.rs | 8 ++++---- .../ruma-common/tests/events/room_message.rs | 6 +++--- 24 files changed, 95 insertions(+), 96 deletions(-) diff --git a/crates/ruma-common/src/events/forwarded_room_key.rs b/crates/ruma-common/src/events/forwarded_room_key.rs index fc3e454c..54393635 100644 --- a/crates/ruma-common/src/events/forwarded_room_key.rs +++ b/crates/ruma-common/src/events/forwarded_room_key.rs @@ -5,7 +5,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::{EventEncryptionAlgorithm, RoomId}; +use crate::{EventEncryptionAlgorithm, OwnedRoomId}; /// The content of an `m.forwarded_room_key` event. /// @@ -19,7 +19,7 @@ pub struct ToDeviceForwardedRoomKeyEventContent { pub algorithm: EventEncryptionAlgorithm, /// The room where the key is used. - pub room_id: Box, + pub room_id: OwnedRoomId, /// The Curve25519 key of the device which initiated the session originally. pub sender_key: String, @@ -57,7 +57,7 @@ pub struct ToDeviceForwardedRoomKeyEventContentInit { pub algorithm: EventEncryptionAlgorithm, /// The room where the key is used. - pub room_id: Box, + pub room_id: OwnedRoomId, /// The Curve25519 key of the device which initiated the session originally. pub sender_key: String, diff --git a/crates/ruma-common/src/events/fully_read.rs b/crates/ruma-common/src/events/fully_read.rs index 62b97769..1ccc4fe4 100644 --- a/crates/ruma-common/src/events/fully_read.rs +++ b/crates/ruma-common/src/events/fully_read.rs @@ -5,7 +5,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::EventId; +use crate::OwnedEventId; /// The content of an `m.fully_read` event. /// @@ -17,12 +17,12 @@ use crate::EventId; #[ruma_event(type = "m.fully_read", kind = RoomAccountData)] pub struct FullyReadEventContent { /// The event the user's read marker is located at in the room. - pub event_id: Box, + pub event_id: OwnedEventId, } impl FullyReadEventContent { /// Creates a new `FullyReadEventContent` with the given event ID. - pub fn new(event_id: Box) -> Self { + pub fn new(event_id: OwnedEventId) -> Self { Self { event_id } } } diff --git a/crates/ruma-common/src/events/key/verification/accept.rs b/crates/ruma-common/src/events/key/verification/accept.rs index c74b2ef0..0d024011 100644 --- a/crates/ruma-common/src/events/key/verification/accept.rs +++ b/crates/ruma-common/src/events/key/verification/accept.rs @@ -12,7 +12,7 @@ use super::{ HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation, ShortAuthenticationString, }; -use crate::{serde::Base64, TransactionId}; +use crate::{serde::Base64, OwnedTransactionId}; /// The content of a to-device `m.key.verification.accept` event. /// @@ -24,7 +24,7 @@ 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. - pub transaction_id: Box, + pub transaction_id: OwnedTransactionId, /// The method specific content. #[serde(flatten)] @@ -34,7 +34,7 @@ pub struct ToDeviceKeyVerificationAcceptEventContent { impl ToDeviceKeyVerificationAcceptEventContent { /// Creates a new `ToDeviceKeyVerificationAcceptEventContent` with the given transaction ID and /// method-specific content. - pub fn new(transaction_id: Box, method: AcceptMethod) -> Self { + pub fn new(transaction_id: OwnedTransactionId, method: AcceptMethod) -> Self { Self { transaction_id, method } } } diff --git a/crates/ruma-common/src/events/key/verification/cancel.rs b/crates/ruma-common/src/events/key/verification/cancel.rs index 84f1758a..316c5ccd 100644 --- a/crates/ruma-common/src/events/key/verification/cancel.rs +++ b/crates/ruma-common/src/events/key/verification/cancel.rs @@ -6,7 +6,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; use super::Relation; -use crate::{serde::StringEnum, PrivOwnedStr, TransactionId}; +use crate::{serde::StringEnum, OwnedTransactionId, PrivOwnedStr}; /// The content of a to-device `m.key.verification.cancel` event. /// @@ -16,7 +16,7 @@ use crate::{serde::StringEnum, PrivOwnedStr, TransactionId}; #[ruma_event(type = "m.key.verification.cancel", kind = ToDevice)] pub struct ToDeviceKeyVerificationCancelEventContent { /// The opaque identifier for the verification process/request. - pub transaction_id: Box, + pub transaction_id: OwnedTransactionId, /// A human readable description of the `code`. /// @@ -30,7 +30,7 @@ pub struct ToDeviceKeyVerificationCancelEventContent { impl ToDeviceKeyVerificationCancelEventContent { /// Creates a new `ToDeviceKeyVerificationCancelEventContent` with the given transaction ID, /// reason and code. - pub fn new(transaction_id: Box, reason: String, code: CancelCode) -> Self { + pub fn new(transaction_id: OwnedTransactionId, reason: String, code: CancelCode) -> Self { Self { transaction_id, reason, code } } } diff --git a/crates/ruma-common/src/events/key/verification/done.rs b/crates/ruma-common/src/events/key/verification/done.rs index ad808065..4e37394b 100644 --- a/crates/ruma-common/src/events/key/verification/done.rs +++ b/crates/ruma-common/src/events/key/verification/done.rs @@ -6,7 +6,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; use super::Relation; -use crate::TransactionId; +use crate::OwnedTransactionId; /// The content of a to-device `m.m.key.verification.done` event. /// @@ -18,12 +18,12 @@ 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: Box, + pub transaction_id: OwnedTransactionId, } impl ToDeviceKeyVerificationDoneEventContent { /// Creates a new `ToDeviceKeyVerificationDoneEventContent` with the given transaction ID. - pub fn new(transaction_id: Box) -> Self { + pub fn new(transaction_id: OwnedTransactionId) -> Self { Self { transaction_id } } } diff --git a/crates/ruma-common/src/events/key/verification/key.rs b/crates/ruma-common/src/events/key/verification/key.rs index edd419e9..be746414 100644 --- a/crates/ruma-common/src/events/key/verification/key.rs +++ b/crates/ruma-common/src/events/key/verification/key.rs @@ -6,7 +6,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; use super::Relation; -use crate::{serde::Base64, TransactionId}; +use crate::{serde::Base64, OwnedTransactionId}; /// The content of a to-device `m.key.verification.key` event. /// @@ -18,7 +18,7 @@ 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. - pub transaction_id: Box, + pub transaction_id: OwnedTransactionId, /// The device's ephemeral public key, encoded as unpadded base64. pub key: Base64, @@ -27,7 +27,7 @@ pub struct ToDeviceKeyVerificationKeyEventContent { impl ToDeviceKeyVerificationKeyEventContent { /// Creates a new `ToDeviceKeyVerificationKeyEventContent` with the given transaction ID and /// key. - pub fn new(transaction_id: Box, key: Base64) -> Self { + pub fn new(transaction_id: OwnedTransactionId, key: Base64) -> Self { Self { transaction_id, key } } } diff --git a/crates/ruma-common/src/events/key/verification/mac.rs b/crates/ruma-common/src/events/key/verification/mac.rs index 758c7d09..cbec56d3 100644 --- a/crates/ruma-common/src/events/key/verification/mac.rs +++ b/crates/ruma-common/src/events/key/verification/mac.rs @@ -8,7 +8,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; use super::Relation; -use crate::{serde::Base64, TransactionId}; +use crate::{serde::Base64, OwnedTransactionId}; /// The content of a to-device `m.key.verification.` event. /// @@ -20,7 +20,7 @@ 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. - pub transaction_id: Box, + pub transaction_id: OwnedTransactionId, /// A map of the key ID to the MAC of the key, using the algorithm in the verification process. /// @@ -36,7 +36,7 @@ impl ToDeviceKeyVerificationMacEventContent { /// Creates a new `ToDeviceKeyVerificationMacEventContent` with the given transaction ID, key ID /// to MAC map and key MAC. pub fn new( - transaction_id: Box, + transaction_id: OwnedTransactionId, mac: BTreeMap, keys: Base64, ) -> Self { diff --git a/crates/ruma-common/src/events/key/verification/ready.rs b/crates/ruma-common/src/events/key/verification/ready.rs index 9ab18d78..5951f2b2 100644 --- a/crates/ruma-common/src/events/key/verification/ready.rs +++ b/crates/ruma-common/src/events/key/verification/ready.rs @@ -6,7 +6,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; use super::{Relation, VerificationMethod}; -use crate::{DeviceId, TransactionId}; +use crate::{OwnedDeviceId, OwnedTransactionId}; /// The content of a to-device `m.m.key.verification.ready` event. /// @@ -16,7 +16,7 @@ use crate::{DeviceId, TransactionId}; #[ruma_event(type = "m.key.verification.ready", kind = ToDevice)] pub struct ToDeviceKeyVerificationReadyEventContent { /// The device ID which is initiating the request. - pub from_device: Box, + pub from_device: OwnedDeviceId, /// The verification methods supported by the sender. pub methods: Vec, @@ -26,16 +26,16 @@ pub struct ToDeviceKeyVerificationReadyEventContent { /// Must be unique with respect to the devices involved. Must be the same as the /// `transaction_id` given in the `m.key.verification.request` from a /// request. - pub transaction_id: Box, + pub transaction_id: OwnedTransactionId, } impl ToDeviceKeyVerificationReadyEventContent { /// Creates a new `ToDeviceKeyVerificationReadyEventContent` with the given device ID, /// verification methods and transaction ID. pub fn new( - from_device: Box, + from_device: OwnedDeviceId, methods: Vec, - transaction_id: Box, + transaction_id: OwnedTransactionId, ) -> Self { Self { from_device, methods, transaction_id } } @@ -49,7 +49,7 @@ impl ToDeviceKeyVerificationReadyEventContent { #[ruma_event(type = "m.key.verification.ready", kind = MessageLike)] pub struct KeyVerificationReadyEventContent { /// The device ID which is initiating the request. - pub from_device: Box, + pub from_device: OwnedDeviceId, /// The verification methods supported by the sender. pub methods: Vec, @@ -64,7 +64,7 @@ impl KeyVerificationReadyEventContent { /// Creates a new `KeyVerificationReadyEventContent` with the given device ID, methods and /// relation. pub fn new( - from_device: Box, + from_device: OwnedDeviceId, methods: Vec, relates_to: Relation, ) -> Self { @@ -74,7 +74,7 @@ impl KeyVerificationReadyEventContent { #[cfg(test)] mod tests { - use crate::{event_id, DeviceId}; + use crate::{event_id, OwnedDeviceId}; use matches::assert_matches; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; @@ -84,7 +84,7 @@ mod tests { #[test] fn serialization() { let event_id = event_id!("$1598361704261elfgc:localhost").to_owned(); - let device: Box = "123".into(); + let device: OwnedDeviceId = "123".into(); let json_data = json!({ "from_device": device, @@ -121,7 +121,7 @@ mod tests { #[test] fn deserialization() { let id = event_id!("$1598361704261elfgc:localhost"); - let device: Box = "123".into(); + let device: OwnedDeviceId = "123".into(); let json_data = json!({ "from_device": device, diff --git a/crates/ruma-common/src/events/key/verification/request.rs b/crates/ruma-common/src/events/key/verification/request.rs index 5dc61504..2e4f30e9 100644 --- a/crates/ruma-common/src/events/key/verification/request.rs +++ b/crates/ruma-common/src/events/key/verification/request.rs @@ -6,7 +6,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; use super::VerificationMethod; -use crate::{DeviceId, MilliSecondsSinceUnixEpoch, TransactionId}; +use crate::{MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedTransactionId}; /// The content of an `m.key.verification.request` event. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] @@ -14,12 +14,12 @@ use crate::{DeviceId, MilliSecondsSinceUnixEpoch, TransactionId}; #[ruma_event(type = "m.key.verification.request", kind = ToDevice)] pub struct ToDeviceKeyVerificationRequestEventContent { /// The device ID which is initiating the request. - pub from_device: Box, + pub from_device: OwnedDeviceId, /// An opaque identifier for the verification request. /// /// Must be unique with respect to the devices involved. - pub transaction_id: Box, + pub transaction_id: OwnedTransactionId, /// The verification methods supported by the sender. pub methods: Vec, @@ -35,8 +35,8 @@ impl ToDeviceKeyVerificationRequestEventContent { /// Creates a new `ToDeviceKeyVerificationRequestEventContent` with the given device ID, /// transaction ID, methods and timestamp. pub fn new( - from_device: Box, - transaction_id: Box, + from_device: OwnedDeviceId, + transaction_id: OwnedTransactionId, methods: Vec, timestamp: MilliSecondsSinceUnixEpoch, ) -> Self { diff --git a/crates/ruma-common/src/events/key/verification/start.rs b/crates/ruma-common/src/events/key/verification/start.rs index 1ef2bb2a..9e2ee70a 100644 --- a/crates/ruma-common/src/events/key/verification/start.rs +++ b/crates/ruma-common/src/events/key/verification/start.rs @@ -12,7 +12,7 @@ use super::{ HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation, ShortAuthenticationString, }; -use crate::{serde::Base64, DeviceId, TransactionId}; +use crate::{serde::Base64, OwnedDeviceId, OwnedTransactionId}; /// The content of a to-device `m.key.verification.start` event. /// @@ -22,14 +22,14 @@ use crate::{serde::Base64, DeviceId, TransactionId}; #[ruma_event(type = "m.key.verification.start", kind = ToDevice)] pub struct ToDeviceKeyVerificationStartEventContent { /// The device ID which is initiating the process. - pub from_device: Box, + pub from_device: OwnedDeviceId, /// An opaque identifier for the verification process. /// /// Must be unique with respect to the devices involved. Must be the same as the /// `transaction_id` given in the `m.key.verification.request` if this process is originating /// from a request. - pub transaction_id: Box, + pub transaction_id: OwnedTransactionId, /// Method specific content. #[serde(flatten)] @@ -40,8 +40,8 @@ impl ToDeviceKeyVerificationStartEventContent { /// Creates a new `ToDeviceKeyVerificationStartEventContent` with the given device ID, /// transaction ID and method specific content. pub fn new( - from_device: Box, - transaction_id: Box, + from_device: OwnedDeviceId, + transaction_id: OwnedTransactionId, method: StartMethod, ) -> Self { Self { from_device, transaction_id, method } @@ -56,7 +56,7 @@ impl ToDeviceKeyVerificationStartEventContent { #[ruma_event(type = "m.key.verification.start", kind = MessageLike)] pub struct KeyVerificationStartEventContent { /// The device ID which is initiating the process. - pub from_device: Box, + pub from_device: OwnedDeviceId, /// Method specific content. #[serde(flatten)] @@ -70,7 +70,7 @@ pub struct KeyVerificationStartEventContent { impl KeyVerificationStartEventContent { /// Creates a new `KeyVerificationStartEventContent` with the given device ID, method and /// relation. - pub fn new(from_device: Box, method: StartMethod, relates_to: Relation) -> Self { + pub fn new(from_device: OwnedDeviceId, method: StartMethod, relates_to: Relation) -> Self { Self { from_device, method, relates_to } } } diff --git a/crates/ruma-common/src/events/reaction.rs b/crates/ruma-common/src/events/reaction.rs index e1693c21..eea1893e 100644 --- a/crates/ruma-common/src/events/reaction.rs +++ b/crates/ruma-common/src/events/reaction.rs @@ -3,7 +3,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::EventId; +use crate::OwnedEventId; /// The payload for a `m.reaction` event. /// @@ -38,7 +38,7 @@ impl From for ReactionEventContent { #[serde(tag = "rel_type", rename = "m.annotation")] pub struct Relation { /// The event that is being annotated. - pub event_id: Box, + pub event_id: OwnedEventId, /// A string that indicates the annotation being applied. /// @@ -51,7 +51,7 @@ pub struct Relation { impl Relation { /// Creates a new `Relation` with the given event ID and key. - pub fn new(event_id: Box, key: String) -> Self { + pub fn new(event_id: OwnedEventId, key: String) -> Self { Self { event_id, key } } } diff --git a/crates/ruma-common/src/events/relation.rs b/crates/ruma-common/src/events/relation.rs index 817df276..163a2d76 100644 --- a/crates/ruma-common/src/events/relation.rs +++ b/crates/ruma-common/src/events/relation.rs @@ -6,7 +6,7 @@ use js_int::UInt; use serde::{Deserialize, Serialize}; use super::AnySyncMessageLikeEvent; -use crate::{serde::Raw, EventId, MilliSecondsSinceUnixEpoch, UserId}; +use crate::{serde::Raw, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId}; /// Summary of all reactions with the given key to an event. #[derive(Clone, Debug, Default, Deserialize, PartialEq, Eq, Serialize)] @@ -74,10 +74,10 @@ impl AnnotationChunk { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct BundledReplacement { /// The ID of the replacing event. - pub event_id: Box, + pub event_id: OwnedEventId, /// The user ID of the sender of the latest replacement. - pub sender: Box, + pub sender: OwnedUserId, /// Timestamp in milliseconds on originating homeserver when the latest replacement was sent. #[serde(skip_serializing_if = "Option::is_none")] @@ -87,7 +87,7 @@ pub struct BundledReplacement { #[cfg(feature = "unstable-msc2676")] impl BundledReplacement { /// Creates a new `BundledReplacement` with the given event ID and sender. - pub fn new(event_id: Box, sender: Box) -> Self { + pub fn new(event_id: OwnedEventId, sender: OwnedUserId) -> Self { Self { event_id, sender, origin_server_ts: None } } } diff --git a/crates/ruma-common/src/events/room/canonical_alias.rs b/crates/ruma-common/src/events/room/canonical_alias.rs index fb81c533..343313c6 100644 --- a/crates/ruma-common/src/events/room/canonical_alias.rs +++ b/crates/ruma-common/src/events/room/canonical_alias.rs @@ -5,7 +5,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::{OwnedRoomAliasId, RoomAliasId}; +use crate::OwnedRoomAliasId; /// The content of an `m.room.canonical_alias` event. /// @@ -27,7 +27,7 @@ pub struct RoomCanonicalAliasEventContent { /// List of alternative aliases to the room. #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub alt_aliases: Vec>, + pub alt_aliases: Vec, } impl RoomCanonicalAliasEventContent { diff --git a/crates/ruma-common/src/events/room/create.rs b/crates/ruma-common/src/events/room/create.rs index 6201b9bd..ca50c7b8 100644 --- a/crates/ruma-common/src/events/room/create.rs +++ b/crates/ruma-common/src/events/room/create.rs @@ -5,7 +5,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::{room::RoomType, EventId, OwnedUserId, RoomId, RoomVersionId}; +use crate::{room::RoomType, OwnedEventId, OwnedRoomId, OwnedUserId, RoomVersionId}; /// The content of an `m.room.create` event. /// @@ -65,15 +65,15 @@ impl RoomCreateEventContent { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct PreviousRoom { /// The ID of the old room. - pub room_id: Box, + pub room_id: OwnedRoomId, /// The event ID of the last known event in the old room. - pub event_id: Box, + pub event_id: OwnedEventId, } impl PreviousRoom { /// Creates a new `PreviousRoom` from the given room and event IDs. - pub fn new(room_id: Box, event_id: Box) -> Self { + pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId) -> Self { Self { room_id, event_id } } } diff --git a/crates/ruma-common/src/events/room/encrypted.rs b/crates/ruma-common/src/events/room/encrypted.rs index 549507de..76385103 100644 --- a/crates/ruma-common/src/events/room/encrypted.rs +++ b/crates/ruma-common/src/events/room/encrypted.rs @@ -9,9 +9,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; use super::message::{self, InReplyTo}; -#[cfg(feature = "unstable-msc2677")] -use crate::EventId; -use crate::{DeviceId, OwnedEventId}; +use crate::{OwnedDeviceId, OwnedEventId}; mod relation_serde; @@ -164,7 +162,7 @@ impl Reference { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Annotation { /// The event that is being annotated. - pub event_id: Box, + pub event_id: OwnedEventId, /// The annotation. pub key: String, @@ -173,7 +171,7 @@ pub struct Annotation { #[cfg(feature = "unstable-msc2677")] impl Annotation { /// Creates a new `Annotation` with the given event ID and key. - pub fn new(event_id: Box, key: String) -> Self { + pub fn new(event_id: OwnedEventId, key: String) -> Self { Self { event_id, key } } } @@ -269,7 +267,7 @@ pub struct MegolmV1AesSha2Content { pub sender_key: String, /// The ID of the sending device. - pub device_id: Box, + pub device_id: OwnedDeviceId, /// The ID of the session used to encrypt the message. pub session_id: String, @@ -289,7 +287,7 @@ pub struct MegolmV1AesSha2ContentInit { pub sender_key: String, /// The ID of the sending device. - pub device_id: Box, + pub device_id: OwnedDeviceId, /// The ID of the session used to encrypt the message. pub session_id: String, diff --git a/crates/ruma-common/src/events/room/member.rs b/crates/ruma-common/src/events/room/member.rs index d6453247..aad78b51 100644 --- a/crates/ruma-common/src/events/room/member.rs +++ b/crates/ruma-common/src/events/room/member.rs @@ -248,7 +248,7 @@ pub struct SignedContent { /// The invited Matrix user ID. /// /// Must be equal to the user_id property of the event. - pub mxid: Box, + pub mxid: OwnedUserId, /// A single signature from the verifying server, in the format specified by the Signing Events /// section of the server-server API. @@ -261,8 +261,8 @@ pub struct SignedContent { impl SignedContent { /// Creates a new `SignedContent` with the given mxid, signature and token. pub fn new( - mxid: Box, signatures: BTreeMap>, + mxid: OwnedUserId, token: String, ) -> Self { Self { mxid, signatures, token } diff --git a/crates/ruma-common/src/events/room/message.rs b/crates/ruma-common/src/events/room/message.rs index 381e5f3e..18f78824 100644 --- a/crates/ruma-common/src/events/room/message.rs +++ b/crates/ruma-common/src/events/room/message.rs @@ -29,7 +29,7 @@ use crate::events::{ use crate::{ events::key::verification::VerificationMethod, serde::{JsonObject, StringEnum}, - DeviceId, OwnedEventId, OwnedMxcUri, OwnedUserId, PrivOwnedStr, + OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedUserId, PrivOwnedStr, }; #[cfg(feature = "unstable-msc3488")] use crate::{ @@ -1906,7 +1906,7 @@ pub struct KeyVerificationRequestEventContent { pub methods: Vec, /// The device ID which is initiating the request. - pub from_device: Box, + pub from_device: OwnedDeviceId, /// The user ID which should receive the request. /// @@ -1922,7 +1922,7 @@ impl KeyVerificationRequestEventContent { pub fn new( body: String, methods: Vec, - from_device: Box, + from_device: OwnedDeviceId, to: OwnedUserId, ) -> Self { Self { body, methods, from_device, to } diff --git a/crates/ruma-common/src/events/room/message/feedback.rs b/crates/ruma-common/src/events/room/message/feedback.rs index 1d612299..7f3d462b 100644 --- a/crates/ruma-common/src/events/room/message/feedback.rs +++ b/crates/ruma-common/src/events/room/message/feedback.rs @@ -5,7 +5,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::{serde::StringEnum, EventId, PrivOwnedStr}; +use crate::{serde::StringEnum, OwnedEventId, PrivOwnedStr}; /// The content of an `m.room.message.feedback` event. /// @@ -18,7 +18,7 @@ use crate::{serde::StringEnum, EventId, PrivOwnedStr}; #[ruma_event(type = "m.room.message.feedback", kind = MessageLike)] pub struct RoomMessageFeedbackEventContent { /// The event that this feedback is related to. - pub target_event_id: Box, + pub target_event_id: OwnedEventId, /// The type of feedback. #[serde(rename = "type")] @@ -27,7 +27,7 @@ pub struct RoomMessageFeedbackEventContent { impl RoomMessageFeedbackEventContent { /// Create a `RoomMessageFeedbackEventContent` from the given target event id and feedback type. - pub fn new(target_event_id: Box, feedback_type: FeedbackType) -> Self { + pub fn new(target_event_id: OwnedEventId, feedback_type: FeedbackType) -> Self { Self { target_event_id, feedback_type } } } diff --git a/crates/ruma-common/src/events/room/tombstone.rs b/crates/ruma-common/src/events/room/tombstone.rs index 730f7538..d8bdedcc 100644 --- a/crates/ruma-common/src/events/room/tombstone.rs +++ b/crates/ruma-common/src/events/room/tombstone.rs @@ -5,7 +5,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::RoomId; +use crate::OwnedRoomId; /// The content of an `m.room.tombstone` event. /// @@ -23,12 +23,12 @@ pub struct RoomTombstoneEventContent { pub body: String, /// The new room the client should be visiting. - pub replacement_room: Box, + pub replacement_room: OwnedRoomId, } impl RoomTombstoneEventContent { /// Creates a new `RoomTombstoneEventContent` with the given body and replacement room ID. - pub fn new(body: String, replacement_room: Box) -> Self { + pub fn new(body: String, replacement_room: OwnedRoomId) -> Self { Self { body, replacement_room } } } diff --git a/crates/ruma-common/src/events/room_key_request.rs b/crates/ruma-common/src/events/room_key_request.rs index e56e01a3..20c41044 100644 --- a/crates/ruma-common/src/events/room_key_request.rs +++ b/crates/ruma-common/src/events/room_key_request.rs @@ -6,7 +6,8 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; use crate::{ - serde::StringEnum, DeviceId, EventEncryptionAlgorithm, PrivOwnedStr, RoomId, TransactionId, + serde::StringEnum, EventEncryptionAlgorithm, OwnedDeviceId, OwnedRoomId, OwnedTransactionId, + PrivOwnedStr, }; /// The content of an `m.room_key_request` event. @@ -23,13 +24,13 @@ pub struct ToDeviceRoomKeyRequestEventContent { pub body: Option, /// ID of the device requesting the key. - pub requesting_device_id: Box, + pub requesting_device_id: OwnedDeviceId, /// A random string uniquely identifying the request for a key. /// /// If the key is requested multiple times, it should be reused. It should also reused /// in order to cancel a request. - pub request_id: Box, + pub request_id: OwnedTransactionId, } impl ToDeviceRoomKeyRequestEventContent { @@ -38,8 +39,8 @@ impl ToDeviceRoomKeyRequestEventContent { pub fn new( action: Action, body: Option, - requesting_device_id: Box, - request_id: Box, + requesting_device_id: OwnedDeviceId, + request_id: OwnedTransactionId, ) -> Self { Self { action, body, requesting_device_id, request_id } } @@ -77,7 +78,7 @@ pub struct RequestedKeyInfo { pub algorithm: EventEncryptionAlgorithm, /// The room where the key is used. - pub room_id: Box, + pub room_id: OwnedRoomId, /// The Curve25519 key of the device which initiated the session originally. pub sender_key: String, @@ -91,7 +92,7 @@ impl RequestedKeyInfo { /// ID. pub fn new( algorithm: EventEncryptionAlgorithm, - room_id: Box, + room_id: OwnedRoomId, sender_key: String, session_id: String, ) -> Self { diff --git a/crates/ruma-common/src/events/secret/request.rs b/crates/ruma-common/src/events/secret/request.rs index db50837a..4c0f429c 100644 --- a/crates/ruma-common/src/events/secret/request.rs +++ b/crates/ruma-common/src/events/secret/request.rs @@ -7,7 +7,7 @@ use std::convert::TryFrom; use ruma_macros::EventContent; use serde::{ser::SerializeStruct, Deserialize, Serialize}; -use crate::{serde::StringEnum, DeviceId, PrivOwnedStr, TransactionId}; +use crate::{serde::StringEnum, OwnedDeviceId, OwnedTransactionId, PrivOwnedStr}; /// The content of an `m.secret.request` event. /// @@ -23,14 +23,14 @@ pub struct ToDeviceSecretRequestEventContent { pub action: RequestAction, /// The ID of the device requesting the event. - pub requesting_device_id: Box, + pub requesting_device_id: OwnedDeviceId, /// A random string uniquely identifying (with respect to the requester and the target) the /// target for a secret. /// /// If the secret is requested from multiple devices at the same time, the same ID may be used /// for every target. The same ID is also used in order to cancel a previous request. - pub request_id: Box, + pub request_id: OwnedTransactionId, } impl ToDeviceSecretRequestEventContent { @@ -38,8 +38,8 @@ impl ToDeviceSecretRequestEventContent { /// request ID. pub fn new( action: RequestAction, - requesting_device_id: Box, - request_id: Box, + requesting_device_id: OwnedDeviceId, + request_id: OwnedTransactionId, ) -> Self { Self { action, requesting_device_id, request_id } } diff --git a/crates/ruma-common/src/events/secret/send.rs b/crates/ruma-common/src/events/secret/send.rs index ef66cd61..84fab36d 100644 --- a/crates/ruma-common/src/events/secret/send.rs +++ b/crates/ruma-common/src/events/secret/send.rs @@ -5,7 +5,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::TransactionId; +use crate::OwnedTransactionId; /// The content of an `m.secret.send` event. /// @@ -18,7 +18,7 @@ use crate::TransactionId; #[ruma_event(type = "m.secret.send", kind = ToDevice)] pub struct ToDeviceSecretSendEventContent { /// The ID of the request that this is a response to. - pub request_id: Box, + pub request_id: OwnedTransactionId, /// The contents of the secret. pub secret: String, @@ -26,7 +26,7 @@ pub struct ToDeviceSecretSendEventContent { impl ToDeviceSecretSendEventContent { /// Creates a new `SecretSendEventContent` with the given request ID and secret. - pub fn new(request_id: Box, secret: String) -> Self { + pub fn new(request_id: OwnedTransactionId, secret: String) -> Self { Self { request_id, secret } } } diff --git a/crates/ruma-common/src/events/unsigned.rs b/crates/ruma-common/src/events/unsigned.rs index 5be6e4c9..013b01e2 100644 --- a/crates/ruma-common/src/events/unsigned.rs +++ b/crates/ruma-common/src/events/unsigned.rs @@ -5,7 +5,7 @@ use serde_json::{from_str as from_json_str, value::RawValue as RawJsonValue}; #[cfg(feature = "unstable-msc2675")] use super::relation::Relations; use super::{room::redaction::SyncRoomRedactionEvent, StateEventContent}; -use crate::{serde::Raw, TransactionId}; +use crate::{serde::Raw, OwnedTransactionId}; /// Extra information about a message event that is not incorporated into the event's hash. #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -22,7 +22,7 @@ pub struct MessageLikeUnsigned { /// The client-supplied transaction ID, if the client being given the event is the same one /// which sent it. #[serde(skip_serializing_if = "Option::is_none")] - pub transaction_id: Option>, + pub transaction_id: Option, /// Server-compiled information from other events relating to this event. #[cfg(feature = "unstable-msc2675")] @@ -69,7 +69,7 @@ pub struct StateUnsigned { /// The client-supplied transaction ID, if the client being given the event is the same one /// which sent it. #[serde(skip_serializing_if = "Option::is_none")] - pub transaction_id: Option>, + pub transaction_id: Option, /// Optional previous content of the event. #[serde(skip_serializing_if = "Option::is_none")] @@ -126,7 +126,7 @@ impl StateUnsigned { #[serde(skip_serializing_if = "Option::is_none")] age: Option, #[serde(skip_serializing_if = "Option::is_none")] - transaction_id: Option>, + transaction_id: Option, prev_content: Option>, #[cfg(feature = "unstable-msc2675")] #[serde(rename = "m.relations", skip_serializing_if = "Option::is_none")] diff --git a/crates/ruma-common/tests/events/room_message.rs b/crates/ruma-common/tests/events/room_message.rs index 4be6d036..8864c3d3 100644 --- a/crates/ruma-common/tests/events/room_message.rs +++ b/crates/ruma-common/tests/events/room_message.rs @@ -21,7 +21,7 @@ use ruma_common::{ }, MessageLikeUnsigned, }, - mxc_uri, room_id, user_id, DeviceId, MilliSecondsSinceUnixEpoch, + mxc_uri, room_id, user_id, MilliSecondsSinceUnixEpoch, OwnedDeviceId, }; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; @@ -414,7 +414,7 @@ fn edit_deserialization_future() { #[test] fn verification_request_deserialization() { let user_id = user_id!("@example2:localhost"); - let device_id: Box = "XOWLHHFSWM".into(); + let device_id: OwnedDeviceId = "XOWLHHFSWM".into(); let json_data = json!({ "body": "@example:localhost is requesting to verify your key, ...", @@ -449,7 +449,7 @@ fn verification_request_deserialization() { #[test] fn verification_request_serialization() { let user_id = user_id!("@example2:localhost").to_owned(); - let device_id: Box = "XOWLHHFSWM".into(); + let device_id: OwnedDeviceId = "XOWLHHFSWM".into(); let body = "@example:localhost is requesting to verify your key, ...".to_owned(); let methods =