From 3ce578f3849f12fa4101bc85b94f8e3603d297d3 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 24 Nov 2021 21:41:28 +0100 Subject: [PATCH] identifiers: Make UserId a DST --- crates/ruma-api/src/lib.rs | 5 +- crates/ruma-api/tests/conversions.rs | 12 +- crates/ruma-api/tests/ruma_api_macros.rs | 2 +- crates/ruma-api/tests/ui/03-move-value.rs | 6 +- .../src/r0/account/register.rs | 4 +- .../ruma-client-api/src/r0/account/whoami.rs | 4 +- crates/ruma-client-api/src/r0/backup.rs | 2 +- crates/ruma-client-api/src/r0/filter.rs | 8 +- .../src/r0/filter/create_filter.rs | 2 +- .../ruma-client-api/src/r0/keys/claim_keys.rs | 8 +- .../src/r0/keys/get_key_changes.rs | 6 +- .../ruma-client-api/src/r0/keys/get_keys.rs | 10 +- .../src/r0/keys/upload_signatures.rs | 4 +- .../src/r0/membership/invite_user.rs | 2 +- .../src/r0/membership/joined_members.rs | 4 +- .../src/r0/room/create_room.rs | 4 +- .../src/r0/search/search_events.rs | 4 +- .../src/r0/server/get_user_info.rs | 2 +- .../ruma-client-api/src/r0/session/login.rs | 4 +- .../src/r0/sync/sync_events.rs | 4 +- .../src/r0/to_device/send_event_to_device.rs | 3 +- .../src/r0/user_directory/search_users.rs | 4 +- crates/ruma-common/src/encryption.rs | 16 +-- crates/ruma-common/src/push.rs | 2 +- crates/ruma-common/src/push/condition.rs | 8 +- crates/ruma-common/src/thirdparty.rs | 4 +- crates/ruma-events/src/direct.rs | 4 +- crates/ruma-events/src/event_kinds.rs | 24 ++-- crates/ruma-events/src/ignored_user_list.rs | 6 +- .../src/key/verification/accept.rs | 4 +- .../ruma-events/src/key/verification/start.rs | 4 +- crates/ruma-events/src/pdu.rs | 4 +- crates/ruma-events/src/policy/rule/room.rs | 2 +- crates/ruma-events/src/presence.rs | 4 +- crates/ruma-events/src/receipt.rs | 2 +- .../ruma-events/src/room/canonical_alias.rs | 2 +- crates/ruma-events/src/room/create.rs | 8 +- crates/ruma-events/src/room/member.rs | 4 +- crates/ruma-events/src/room/message.rs | 4 +- crates/ruma-events/src/room/message/reply.rs | 9 +- crates/ruma-events/src/room/name.rs | 4 +- crates/ruma-events/src/room/power_levels.rs | 10 +- crates/ruma-events/src/room/redaction.rs | 8 +- crates/ruma-events/src/room_key.rs | 2 +- crates/ruma-events/src/typing.rs | 4 +- crates/ruma-events/tests/custom.rs | 4 +- crates/ruma-events/tests/enums.rs | 4 +- crates/ruma-events/tests/ephemeral_event.rs | 6 +- crates/ruma-events/tests/event_enums.rs | 2 +- crates/ruma-events/tests/message_event.rs | 2 +- crates/ruma-events/tests/pdu.rs | 4 +- crates/ruma-events/tests/redacted.rs | 14 +- crates/ruma-events/tests/redaction.rs | 2 +- crates/ruma-events/tests/room_message.rs | 4 +- crates/ruma-events/tests/state_event.rs | 4 +- crates/ruma-events/tests/stripped.rs | 4 +- crates/ruma-events/tests/to_device.rs | 2 +- .../tests/ui/04-event-sanity-check.rs | 2 +- .../src/device/get_devices/v1.rs | 4 +- .../src/keys/claim_keys/v1.rs | 8 +- .../src/keys/get_keys/v1.rs | 12 +- .../src/openid/get_openid_userinfo/v1.rs | 4 +- .../src/thirdparty/bind_callback/v1.rs | 8 +- .../src/transactions/edu.rs | 24 ++-- crates/ruma-identifiers-macros/src/lib.rs | 2 +- crates/ruma-identifiers/src/macros.rs | 83 ------------ crates/ruma-identifiers/src/user_id.rs | 124 +++++++----------- .../src/association/bind_3pid/v2.rs | 4 +- .../get_account_information/v2.rs | 4 +- .../invitation/sign_invitation_ed25519/v2.rs | 11 +- .../src/lookup/lookup_3pid/v2.rs | 4 +- .../src/send_event_notification/v1.rs | 2 +- crates/ruma-serde-macros/src/outgoing.rs | 1 + crates/ruma-serde/tests/empty_strings.rs | 6 +- crates/ruma-signatures/src/functions.rs | 6 +- .../ruma-state-res/benches/state_res_bench.rs | 22 ++-- crates/ruma-state-res/src/event_auth.rs | 4 +- crates/ruma-state-res/src/lib.rs | 2 +- crates/ruma-state-res/src/test_utils.rs | 26 ++-- 79 files changed, 278 insertions(+), 380 deletions(-) diff --git a/crates/ruma-api/src/lib.rs b/crates/ruma-api/src/lib.rs index 211b4141..2b69ac03 100644 --- a/crates/ruma-api/src/lib.rs +++ b/crates/ruma-api/src/lib.rs @@ -298,11 +298,10 @@ pub trait OutgoingRequestAppserviceExt: OutgoingRequest { self, base_url: &str, access_token: SendAccessToken<'_>, - user_id: UserId, + user_id: &UserId, ) -> Result, IntoHttpError> { let mut http_request = self.try_into_http_request(base_url, access_token)?; - let user_id_query = - ruma_serde::urlencoded::to_string(&[("user_id", &user_id.into_string())])?; + let user_id_query = ruma_serde::urlencoded::to_string(&[("user_id", user_id)])?; let uri = http_request.uri().to_owned(); let mut parts = uri.into_parts(); diff --git a/crates/ruma-api/tests/conversions.rs b/crates/ruma-api/tests/conversions.rs index dba46c71..91d2b230 100644 --- a/crates/ruma-api/tests/conversions.rs +++ b/crates/ruma-api/tests/conversions.rs @@ -27,7 +27,7 @@ ruma_api! { #[ruma_api(path)] pub bar: String, #[ruma_api(path)] - pub user: UserId, + pub user: Box, } response: { @@ -47,7 +47,7 @@ fn request_serde() { q1: "query_param_special_chars %/&@!".to_owned(), q2: 55, bar: "barVal".to_owned(), - user: user_id!("@bazme:ruma.io"), + user: user_id!("@bazme:ruma.io").to_owned(), }; let http_req = req @@ -72,7 +72,7 @@ fn invalid_uri_should_not_panic() { q1: "query_param_special_chars %/&@!".to_owned(), q2: 55, bar: "barVal".to_owned(), - user: user_id!("@bazme:ruma.io"), + user: user_id!("@bazme:ruma.io").to_owned(), }; let result = req.try_into_http_request::>("invalid uri", SendAccessToken::None); @@ -87,7 +87,7 @@ fn request_with_user_id_serde() { q1: "query_param_special_chars %/&@!".to_owned(), q2: 55, bar: "barVal".to_owned(), - user: user_id!("@bazme:ruma.io"), + user: user_id!("@bazme:ruma.io").to_owned(), }; let user_id = user_id!("@_virtual_:ruma.io"); @@ -127,7 +127,7 @@ mod without_query { #[ruma_api(path)] pub bar: String, #[ruma_api(path)] - pub user: UserId, + pub user: Box, } response: { @@ -145,7 +145,7 @@ mod without_query { hello: "hi".to_owned(), world: "test".to_owned(), bar: "barVal".to_owned(), - user: user_id!("@bazme:ruma.io"), + user: user_id!("@bazme:ruma.io").to_owned(), }; let user_id = user_id!("@_virtual_:ruma.io"); diff --git a/crates/ruma-api/tests/ruma_api_macros.rs b/crates/ruma-api/tests/ruma_api_macros.rs index 34b689a3..7139ae5b 100644 --- a/crates/ruma-api/tests/ruma_api_macros.rs +++ b/crates/ruma-api/tests/ruma_api_macros.rs @@ -39,7 +39,7 @@ pub mod some_endpoint { // This value will be inserted into the request's URL in place of the // ":user" path component. #[ruma_api(path)] - pub user: UserId, + pub user: Box, } response: { diff --git a/crates/ruma-api/tests/ui/03-move-value.rs b/crates/ruma-api/tests/ui/03-move-value.rs index a07366ec..aec212c1 100644 --- a/crates/ruma-api/tests/ui/03-move-value.rs +++ b/crates/ruma-api/tests/ui/03-move-value.rs @@ -26,7 +26,7 @@ mod newtype_body { pub bar: String, #[ruma_api(query)] - pub baz: UserId, + pub baz: Box, #[ruma_api(header = CONTENT_TYPE)] pub world: String, @@ -64,7 +64,7 @@ mod raw_body { pub bar: String, #[ruma_api(query)] - pub baz: UserId, + pub baz: Box, #[ruma_api(header = CONTENT_TYPE)] pub world: String, @@ -103,7 +103,7 @@ mod plain { pub bar: String, #[ruma_api(query)] - pub baz: UserId, + pub baz: Box, #[ruma_api(header = CONTENT_TYPE)] pub world: String, diff --git a/crates/ruma-client-api/src/r0/account/register.rs b/crates/ruma-client-api/src/r0/account/register.rs index 2488aa8a..bc01ff40 100644 --- a/crates/ruma-client-api/src/r0/account/register.rs +++ b/crates/ruma-client-api/src/r0/account/register.rs @@ -83,7 +83,7 @@ ruma_api! { pub access_token: Option, /// The fully-qualified Matrix ID that has been registered. - pub user_id: UserId, + pub user_id: Box, /// ID of the registered device. /// @@ -103,7 +103,7 @@ impl Request<'_> { impl Response { /// Creates a new `Response` with the given user ID. - pub fn new(user_id: UserId) -> Self { + pub fn new(user_id: Box) -> Self { Self { access_token: None, user_id, device_id: None } } } diff --git a/crates/ruma-client-api/src/r0/account/whoami.rs b/crates/ruma-client-api/src/r0/account/whoami.rs index 53f3cd1e..cb5bc76c 100644 --- a/crates/ruma-client-api/src/r0/account/whoami.rs +++ b/crates/ruma-client-api/src/r0/account/whoami.rs @@ -18,7 +18,7 @@ ruma_api! { response: { /// The id of the user that owns the access token. - pub user_id: UserId, + pub user_id: Box, } error: crate::Error @@ -33,7 +33,7 @@ impl Request { impl Response { /// Creates a new `Response` with the given user ID. - pub fn new(user_id: UserId) -> Self { + pub fn new(user_id: Box) -> Self { Self { user_id } } } diff --git a/crates/ruma-client-api/src/r0/backup.rs b/crates/ruma-client-api/src/r0/backup.rs index d3b9b6cf..0881f6b8 100644 --- a/crates/ruma-client-api/src/r0/backup.rs +++ b/crates/ruma-client-api/src/r0/backup.rs @@ -48,7 +48,7 @@ pub enum BackupAlgorithm { public_key: String, /// Signatures of the auth_data as Signed JSON. - signatures: BTreeMap, String>>, + signatures: BTreeMap, BTreeMap, String>>, }, } diff --git a/crates/ruma-client-api/src/r0/filter.rs b/crates/ruma-client-api/src/r0/filter.rs index 70d8fbfe..54036f9e 100644 --- a/crates/ruma-client-api/src/r0/filter.rs +++ b/crates/ruma-client-api/src/r0/filter.rs @@ -80,13 +80,13 @@ pub struct RoomEventFilter<'a> { /// If this list is absent then no senders are excluded. A matching sender will be excluded /// even if it is listed in the 'senders' filter. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub not_senders: &'a [UserId], + pub not_senders: &'a [Box], /// A list of senders IDs to include. /// /// If this list is absent then all senders are included. #[serde(skip_serializing_if = "Option::is_none")] - pub senders: Option<&'a [UserId]>, + pub senders: Option<&'a [Box]>, /// A list of event types to include. /// @@ -255,7 +255,7 @@ pub struct Filter<'a> { /// /// If this list is absent then all senders are included. #[serde(skip_serializing_if = "Option::is_none")] - pub senders: Option<&'a [UserId]>, + pub senders: Option<&'a [Box]>, /// A list of event types to include. /// @@ -269,7 +269,7 @@ pub struct Filter<'a> { /// If this list is absent then no senders are excluded. A matching sender will be excluded /// even if it is listed in the 'senders' filter. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub not_senders: &'a [UserId], + pub not_senders: &'a [Box], } impl<'a> Filter<'a> { diff --git a/crates/ruma-client-api/src/r0/filter/create_filter.rs b/crates/ruma-client-api/src/r0/filter/create_filter.rs index 8bd68706..43b1ce44 100644 --- a/crates/ruma-client-api/src/r0/filter/create_filter.rs +++ b/crates/ruma-client-api/src/r0/filter/create_filter.rs @@ -82,7 +82,7 @@ mod tests { use crate::r0::filter::FilterDefinition; assert_matches!( - super::Request::new(&user_id!("@foo:bar.com"), FilterDefinition::default()) + super::Request::new(user_id!("@foo:bar.com"), FilterDefinition::default()) .try_into_http_request::>( "https://matrix.org", SendAccessToken::IfRequired("tok"), diff --git a/crates/ruma-client-api/src/r0/keys/claim_keys.rs b/crates/ruma-client-api/src/r0/keys/claim_keys.rs index f4d27157..c67ad18b 100644 --- a/crates/ruma-client-api/src/r0/keys/claim_keys.rs +++ b/crates/ruma-client-api/src/r0/keys/claim_keys.rs @@ -28,7 +28,7 @@ ruma_api! { pub timeout: Option, /// The keys to be claimed. - pub one_time_keys: BTreeMap, DeviceKeyAlgorithm>>, + pub one_time_keys: BTreeMap, BTreeMap, DeviceKeyAlgorithm>>, } response: { @@ -37,7 +37,7 @@ ruma_api! { pub failures: BTreeMap, /// One-time keys for the queried devices. - pub one_time_keys: BTreeMap, + pub one_time_keys: BTreeMap, OneTimeKeys>, } error: crate::Error @@ -46,7 +46,7 @@ ruma_api! { impl Request { /// Creates a new `Request` with the given key claims and the recommended 10 second timeout. pub fn new( - one_time_keys: BTreeMap, DeviceKeyAlgorithm>>, + one_time_keys: BTreeMap, BTreeMap, DeviceKeyAlgorithm>>, ) -> Self { Self { timeout: Some(Duration::from_secs(10)), one_time_keys } } @@ -54,7 +54,7 @@ impl Request { impl Response { /// Creates a new `Response` with the given keys and no failures. - pub fn new(one_time_keys: BTreeMap) -> Self { + pub fn new(one_time_keys: BTreeMap, OneTimeKeys>) -> Self { Self { failures: BTreeMap::new(), one_time_keys } } } diff --git a/crates/ruma-client-api/src/r0/keys/get_key_changes.rs b/crates/ruma-client-api/src/r0/keys/get_key_changes.rs index adfa77ff..8d75d128 100644 --- a/crates/ruma-client-api/src/r0/keys/get_key_changes.rs +++ b/crates/ruma-client-api/src/r0/keys/get_key_changes.rs @@ -30,11 +30,11 @@ ruma_api! { response: { /// The Matrix User IDs of all users who updated their device identity keys. - pub changed: Vec, + pub changed: Vec>, /// The Matrix User IDs of all users who may have left all the end-to-end /// encrypted rooms they previously shared with the user. - pub left: Vec, + pub left: Vec>, } error: crate::Error @@ -49,7 +49,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given changed and left user ID lists. - pub fn new(changed: Vec, left: Vec) -> Self { + pub fn new(changed: Vec>, left: Vec>) -> Self { Self { changed, left } } } diff --git a/crates/ruma-client-api/src/r0/keys/get_keys.rs b/crates/ruma-client-api/src/r0/keys/get_keys.rs index b43cbccc..9180f3d1 100644 --- a/crates/ruma-client-api/src/r0/keys/get_keys.rs +++ b/crates/ruma-client-api/src/r0/keys/get_keys.rs @@ -35,7 +35,7 @@ ruma_api! { /// The keys to be downloaded. /// /// An empty list indicates all devices for the corresponding user. - pub device_keys: BTreeMap>>, + pub device_keys: BTreeMap, Vec>>, /// If the client is fetching keys as a result of a device update received in a sync /// request, this should be the 'since' token of that sync request, or any later sync token. @@ -56,22 +56,22 @@ ruma_api! { /// Information on the queried devices. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub device_keys: BTreeMap, DeviceKeys>>, + pub device_keys: BTreeMap, BTreeMap, DeviceKeys>>, /// Information on the master cross-signing keys of the queried users. #[cfg(feature = "unstable-pre-spec")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub master_keys: BTreeMap, + pub master_keys: BTreeMap, CrossSigningKey>, /// Information on the self-signing keys of the queried users. #[cfg(feature = "unstable-pre-spec")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub self_signing_keys: BTreeMap, + pub self_signing_keys: BTreeMap, CrossSigningKey>, /// Information on the user-signing keys of the queried users. #[cfg(feature = "unstable-pre-spec")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub user_signing_keys: BTreeMap, + pub user_signing_keys: BTreeMap, CrossSigningKey>, } error: crate::Error diff --git a/crates/ruma-client-api/src/r0/keys/upload_signatures.rs b/crates/ruma-client-api/src/r0/keys/upload_signatures.rs index d1a400c6..343b37ab 100644 --- a/crates/ruma-client-api/src/r0/keys/upload_signatures.rs +++ b/crates/ruma-client-api/src/r0/keys/upload_signatures.rs @@ -21,7 +21,7 @@ ruma_api! { request: { /// Signed keys. #[ruma_api(body)] - pub signed_keys: BTreeMap>, + pub signed_keys: BTreeMap, BTreeMap>, } #[derive(Default)] @@ -32,7 +32,7 @@ ruma_api! { impl Request { /// Creates a new `Request` with the given signed keys. - pub fn new(signed_keys: BTreeMap>) -> Self { + pub fn new(signed_keys: BTreeMap, BTreeMap>) -> Self { Self { signed_keys } } } diff --git a/crates/ruma-client-api/src/r0/membership/invite_user.rs b/crates/ruma-client-api/src/r0/membership/invite_user.rs index eeb5d672..b527d4fe 100644 --- a/crates/ruma-client-api/src/r0/membership/invite_user.rs +++ b/crates/ruma-client-api/src/r0/membership/invite_user.rs @@ -95,7 +95,7 @@ mod tests { json!({ "user_id": "@carl:example.org" }), ) .unwrap(); - let user_id = user_id!("@carl:example.org"); + let user_id = user_id!("@carl:example.org").to_owned(); let recipient = IncomingInvitationRecipient::UserId { user_id }; assert_eq!(incoming, recipient); } diff --git a/crates/ruma-client-api/src/r0/membership/joined_members.rs b/crates/ruma-client-api/src/r0/membership/joined_members.rs index fb4a424a..c05a6228 100644 --- a/crates/ruma-client-api/src/r0/membership/joined_members.rs +++ b/crates/ruma-client-api/src/r0/membership/joined_members.rs @@ -25,7 +25,7 @@ ruma_api! { response: { /// A list of the rooms the user is in, i.e. /// the ID of each room in which the user has joined membership. - pub joined: BTreeMap, + pub joined: BTreeMap, RoomMember>, } error: crate::Error @@ -40,7 +40,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given joined rooms. - pub fn new(joined: BTreeMap) -> Self { + pub fn new(joined: BTreeMap, RoomMember>) -> Self { Self { joined } } } 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 efa94530..55bb75ea 100644 --- a/crates/ruma-client-api/src/r0/room/create_room.rs +++ b/crates/ruma-client-api/src/r0/room/create_room.rs @@ -44,7 +44,7 @@ ruma_api! { /// /// This will tell the server to invite everyone in the list to the newly created room. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub invite: &'a [UserId], + pub invite: &'a [Box], /// List of third party IDs of users to invite. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] @@ -156,7 +156,7 @@ impl CreationContent { /// a `RoomCreateEventContent`. pub fn into_event_content( self, - creator: UserId, + creator: Box, room_version: RoomVersionId, ) -> RoomCreateEventContent { #[allow(unused_mut)] diff --git a/crates/ruma-client-api/src/r0/search/search_events.rs b/crates/ruma-client-api/src/r0/search/search_events.rs index 4eb66bf5..d9c72505 100644 --- a/crates/ruma-client-api/src/r0/search/search_events.rs +++ b/crates/ruma-client-api/src/r0/search/search_events.rs @@ -194,7 +194,7 @@ pub struct EventContextResult { /// The historic profile information of the users that sent the events returned. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub profile_info: BTreeMap, + pub profile_info: BTreeMap, UserProfile>, /// Pagination token for the start of the chunk. #[serde(skip_serializing_if = "Option::is_none")] @@ -501,5 +501,5 @@ pub enum RoomIdOrUserId { RoomId(Box), /// Represents a user ID. - UserId(UserId), + UserId(Box), } diff --git a/crates/ruma-client-api/src/r0/server/get_user_info.rs b/crates/ruma-client-api/src/r0/server/get_user_info.rs index 164ba358..df9d5303 100644 --- a/crates/ruma-client-api/src/r0/server/get_user_info.rs +++ b/crates/ruma-client-api/src/r0/server/get_user_info.rs @@ -27,7 +27,7 @@ ruma_api! { response: { /// The Matrix user ID of the user. #[serde(skip_serializing_if = "Option::is_none")] - pub user_id: Option, + pub user_id: Option>, /// A map of the user's device identifiers to information about that device. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] diff --git a/crates/ruma-client-api/src/r0/session/login.rs b/crates/ruma-client-api/src/r0/session/login.rs index aa97e19c..d2c2fe3d 100644 --- a/crates/ruma-client-api/src/r0/session/login.rs +++ b/crates/ruma-client-api/src/r0/session/login.rs @@ -39,7 +39,7 @@ ruma_api! { response: { /// The fully-qualified Matrix ID that has been registered. - pub user_id: UserId, + pub user_id: Box, /// An access token for the account. pub access_token: String, @@ -76,7 +76,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given user ID, access token and device ID. - pub fn new(user_id: UserId, access_token: String, device_id: Box) -> Self { + pub fn new(user_id: Box, access_token: String, device_id: Box) -> Self { Self { user_id, access_token, home_server: None, device_id, well_known: None } } } diff --git a/crates/ruma-client-api/src/r0/sync/sync_events.rs b/crates/ruma-client-api/src/r0/sync/sync_events.rs index c37aefd0..37b58b11 100644 --- a/crates/ruma-client-api/src/r0/sync/sync_events.rs +++ b/crates/ruma-client-api/src/r0/sync/sync_events.rs @@ -556,12 +556,12 @@ pub struct DeviceLists { /// List of users who have updated their device identity keys or who now /// share an encrypted room with the client since the previous sync #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub changed: Vec, + pub changed: Vec>, /// List of users who no longer share encrypted rooms since the previous sync /// response. #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub left: Vec, + pub left: Vec>, } impl DeviceLists { diff --git a/crates/ruma-client-api/src/r0/to_device/send_event_to_device.rs b/crates/ruma-client-api/src/r0/to_device/send_event_to_device.rs index cb450ead..e8d959e0 100644 --- a/crates/ruma-client-api/src/r0/to_device/send_event_to_device.rs +++ b/crates/ruma-client-api/src/r0/to_device/send_event_to_device.rs @@ -57,4 +57,5 @@ impl Response { /// Messages to send in a send-to-device request. /// /// Represented as a map of `{ user-ids => { device-ids => message-content } }`. -pub type Messages = BTreeMap>>; +pub type Messages = + BTreeMap, BTreeMap>>; diff --git a/crates/ruma-client-api/src/r0/user_directory/search_users.rs b/crates/ruma-client-api/src/r0/user_directory/search_users.rs index 4cdb0a2b..de6c7504 100644 --- a/crates/ruma-client-api/src/r0/user_directory/search_users.rs +++ b/crates/ruma-client-api/src/r0/user_directory/search_users.rs @@ -72,7 +72,7 @@ fn is_default_limit(limit: &UInt) -> bool { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct User { /// The user's matrix user ID. - pub user_id: UserId, + pub user_id: Box, /// The display name of the user, if one exists. #[serde(skip_serializing_if = "Option::is_none")] @@ -92,7 +92,7 @@ pub struct User { impl User { /// Create a new `User` with the given `UserId`. - pub fn new(user_id: UserId) -> Self { + pub fn new(user_id: Box) -> Self { Self { user_id, display_name: None, avatar_url: None } } } diff --git a/crates/ruma-common/src/encryption.rs b/crates/ruma-common/src/encryption.rs index 39005391..14c5028f 100644 --- a/crates/ruma-common/src/encryption.rs +++ b/crates/ruma-common/src/encryption.rs @@ -14,7 +14,7 @@ pub struct DeviceKeys { /// The ID of the user the device belongs to. /// /// Must match the user ID used when logging in. - pub user_id: UserId, + pub user_id: Box, /// The ID of the device these keys belong to. /// @@ -28,7 +28,7 @@ pub struct DeviceKeys { pub keys: BTreeMap, String>, /// Signatures for the device key object. - pub signatures: BTreeMap, String>>, + pub signatures: BTreeMap, BTreeMap, String>>, /// Additional data added to the device key information by intermediate servers, and /// not covered by the signatures. @@ -40,11 +40,11 @@ impl DeviceKeys { /// Creates a new `DeviceKeys` from the given user id, device id, algorithms, keys and /// signatures. pub fn new( - user_id: UserId, + user_id: Box, device_id: Box, algorithms: Vec, keys: BTreeMap, String>, - signatures: BTreeMap, String>>, + signatures: BTreeMap, BTreeMap, String>>, ) -> Self { Self { user_id, device_id, algorithms, keys, signatures, unsigned: Default::default() } } @@ -72,7 +72,7 @@ impl UnsignedDeviceInfo { } /// Signatures for a `SignedKey` object. -pub type SignedKeySignatures = BTreeMap, String>>; +pub type SignedKeySignatures = BTreeMap, BTreeMap, String>>; /// A key for the SignedCurve25519 algorithm #[derive(Debug, Clone, Serialize, Deserialize)] @@ -105,14 +105,14 @@ pub enum OneTimeKey { } /// Signatures for a `CrossSigningKey` object. -pub type CrossSigningKeySignatures = BTreeMap>; +pub type CrossSigningKeySignatures = BTreeMap, BTreeMap>; /// A cross signing key. #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct CrossSigningKey { /// The ID of the user the key belongs to. - pub user_id: UserId, + pub user_id: Box, /// What the key is used for. pub usage: Vec, @@ -132,7 +132,7 @@ pub struct CrossSigningKey { impl CrossSigningKey { /// Creates a new `CrossSigningKey` with the given user ID, usage, keys and signatures. pub fn new( - user_id: UserId, + user_id: Box, usage: Vec, keys: BTreeMap, signatures: CrossSigningKeySignatures, diff --git a/crates/ruma-common/src/push.rs b/crates/ruma-common/src/push.rs index b0f5eb55..a89d05ac 100644 --- a/crates/ruma-common/src/push.rs +++ b/crates/ruma-common/src/push.rs @@ -963,7 +963,7 @@ mod tests { #[test] fn default_ruleset_applies() { - let set = Ruleset::server_default(&user_id!("@jolly_jumper:server.name")); + let set = Ruleset::server_default(user_id!("@jolly_jumper:server.name")); let context_one_to_one = &PushConditionRoomCtx { room_id: room_id!("!dm:server.name").to_owned(), diff --git a/crates/ruma-common/src/push/condition.rs b/crates/ruma-common/src/push/condition.rs index 8ff0b3d3..72f6f3a7 100644 --- a/crates/ruma-common/src/push/condition.rs +++ b/crates/ruma-common/src/push/condition.rs @@ -90,7 +90,7 @@ impl PushCondition { Self::RoomMemberCount { is } => is.contains(&context.member_count), Self::SenderNotificationPermission { key } => { let sender_id = match event.get("sender") { - Some(v) => match UserId::try_from(v) { + Some(v) => match <&UserId>::try_from(v) { Ok(u) => u, Err(_) => return false, }, @@ -99,7 +99,7 @@ impl PushCondition { let sender_level = context .users_power_levels - .get(&sender_id) + .get(sender_id) .unwrap_or(&context.default_power_level); match context.notification_power_levels.get(key) { @@ -125,7 +125,7 @@ pub struct PushConditionRoomCtx { pub user_display_name: String, /// The power levels of the users of the room. - pub users_power_levels: BTreeMap, + pub users_power_levels: BTreeMap, Int>, /// The default power level of the users of the room. pub default_power_level: Int, @@ -478,7 +478,7 @@ mod tests { #[test] fn conditions_apply_to_events() { - let first_sender = user_id!("@worthy_whale:server.name"); + let first_sender = user_id!("@worthy_whale:server.name").to_owned(); let mut users_power_levels = BTreeMap::new(); users_power_levels.insert(first_sender, 25.into()); diff --git a/crates/ruma-common/src/thirdparty.rs b/crates/ruma-common/src/thirdparty.rs index c46b7acf..97e879e6 100644 --- a/crates/ruma-common/src/thirdparty.rs +++ b/crates/ruma-common/src/thirdparty.rs @@ -198,7 +198,7 @@ impl Location { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct User { /// A matrix user ID representing a third party user. - pub userid: UserId, + pub userid: Box, /// The protocol ID that the third party user is a part of. pub protocol: String, @@ -209,7 +209,7 @@ pub struct User { impl User { /// Creates a new `User` with the given userid, protocol and fields. - pub fn new(userid: UserId, protocol: String, fields: BTreeMap) -> Self { + pub fn new(userid: Box, protocol: String, fields: BTreeMap) -> Self { Self { userid, protocol, fields } } } diff --git a/crates/ruma-events/src/direct.rs b/crates/ruma-events/src/direct.rs index 45099efc..5aa6fac3 100644 --- a/crates/ruma-events/src/direct.rs +++ b/crates/ruma-events/src/direct.rs @@ -18,10 +18,10 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[allow(clippy::exhaustive_structs)] #[ruma_event(type = "m.direct", kind = GlobalAccountData)] -pub struct DirectEventContent(pub BTreeMap>>); +pub struct DirectEventContent(pub BTreeMap, Vec>>); impl Deref for DirectEventContent { - type Target = BTreeMap>>; + type Target = BTreeMap, Vec>>; fn deref(&self) -> &Self::Target { &self.0 diff --git a/crates/ruma-events/src/event_kinds.rs b/crates/ruma-events/src/event_kinds.rs index e614bdf6..81db0f86 100644 --- a/crates/ruma-events/src/event_kinds.rs +++ b/crates/ruma-events/src/event_kinds.rs @@ -55,7 +55,7 @@ pub struct MessageEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -80,7 +80,7 @@ pub struct SyncMessageEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -102,7 +102,7 @@ pub struct RedactedMessageEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -127,7 +127,7 @@ pub struct RedactedSyncMessageEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -149,7 +149,7 @@ pub struct StateEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -183,7 +183,7 @@ pub struct SyncStateEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -208,7 +208,7 @@ pub struct StrippedStateEvent { pub content: C, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// A unique key which defines the overwriting semantics for this piece of room state. /// @@ -246,7 +246,7 @@ pub struct RedactedStateEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -277,7 +277,7 @@ pub struct RedactedSyncStateEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -299,7 +299,7 @@ pub struct ToDeviceEvent { pub content: C, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, } /// The decrypted payload of an `m.olm.v1.curve25519-aes-sha2` event. @@ -309,10 +309,10 @@ pub struct DecryptedOlmV1Event { pub content: C, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// The fully-qualified ID of the intended recipient this event. - pub recipient: UserId, + pub recipient: Box, /// The recipient's ed25519 key. pub recipient_keys: OlmV1Keys, diff --git a/crates/ruma-events/src/ignored_user_list.rs b/crates/ruma-events/src/ignored_user_list.rs index 4e51f239..8c84a4ee 100644 --- a/crates/ruma-events/src/ignored_user_list.rs +++ b/crates/ruma-events/src/ignored_user_list.rs @@ -13,12 +13,12 @@ use serde::{Deserialize, Serialize}; pub struct IgnoredUserListEventContent { /// A list of users to ignore. #[serde(with = "ruma_serde::vec_as_map_of_empty")] - pub ignored_users: Vec, + pub ignored_users: Vec>, } impl IgnoredUserListEventContent { /// Creates a new `IgnoredUserListEventContent` from the given user IDs. - pub fn new(ignored_users: Vec) -> Self { + pub fn new(ignored_users: Vec>) -> Self { Self { ignored_users } } } @@ -36,7 +36,7 @@ mod tests { fn serialization() { let ignored_user_list_event = GlobalAccountDataEvent { content: IgnoredUserListEventContent { - ignored_users: vec![user_id!("@carl:example.com")], + ignored_users: vec![user_id!("@carl:example.com").to_owned()], }, }; diff --git a/crates/ruma-events/src/key/verification/accept.rs b/crates/ruma-events/src/key/verification/accept.rs index 1604a7d5..6b45094b 100644 --- a/crates/ruma-events/src/key/verification/accept.rs +++ b/crates/ruma-events/src/key/verification/accept.rs @@ -195,7 +195,7 @@ mod tests { }), }; - let sender = user_id!("@example:localhost"); + let sender = user_id!("@example:localhost").to_owned(); let json_data = json!({ "content": { @@ -216,7 +216,7 @@ mod tests { assert_eq!(to_json_value(&key_verification_accept).unwrap(), json_data); - let sender = user_id!("@example:localhost"); + let sender = user_id!("@example:localhost").to_owned(); let json_data = json!({ "content": { diff --git a/crates/ruma-events/src/key/verification/start.rs b/crates/ruma-events/src/key/verification/start.rs index befabeee..0800f533 100644 --- a/crates/ruma-events/src/key/verification/start.rs +++ b/crates/ruma-events/src/key/verification/start.rs @@ -234,7 +234,7 @@ mod tests { ), }; - let sender = user_id!("@example:localhost"); + let sender = user_id!("@example:localhost").to_owned(); let json_data = json!({ "content": { @@ -255,7 +255,7 @@ mod tests { assert_eq!(to_json_value(&key_verification_start).unwrap(), json_data); - let sender = user_id!("@example:localhost"); + let sender = user_id!("@example:localhost").to_owned(); let json_data = json!({ "content": { diff --git a/crates/ruma-events/src/pdu.rs b/crates/ruma-events/src/pdu.rs index a2af16d9..7b8d335f 100644 --- a/crates/ruma-events/src/pdu.rs +++ b/crates/ruma-events/src/pdu.rs @@ -41,7 +41,7 @@ pub struct RoomV1Pdu { pub room_id: Box, /// The user id of the user who sent this event. - pub sender: UserId, + pub sender: Box, #[cfg(not(feature = "unstable-pre-spec"))] /// The `server_name` of the homeserver that created this event. @@ -100,7 +100,7 @@ pub struct RoomV3Pdu { pub room_id: Box, /// The user id of the user who sent this event. - pub sender: UserId, + pub sender: Box, #[cfg(not(feature = "unstable-pre-spec"))] /// The `server_name` of the homeserver that created this event. diff --git a/crates/ruma-events/src/policy/rule/room.rs b/crates/ruma-events/src/policy/rule/room.rs index 099bb83f..7d74e249 100644 --- a/crates/ruma-events/src/policy/rule/room.rs +++ b/crates/ruma-events/src/policy/rule/room.rs @@ -33,7 +33,7 @@ mod tests { fn serialization() { let room_event = PolicyRuleRoomEvent { event_id: event_id!("$143273582443PhrSn:example.org").to_owned(), - sender: user_id!("@example:example.org"), + sender: user_id!("@example:example.org").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(1_432_735_824_653_u64.try_into().unwrap()), room_id: room_id!("!jEsUZKDJdhlrceRyVU:example.org").to_owned(), state_key: "rule:#*:example.org".into(), diff --git a/crates/ruma-events/src/presence.rs b/crates/ruma-events/src/presence.rs index d4ca826b..a761c903 100644 --- a/crates/ruma-events/src/presence.rs +++ b/crates/ruma-events/src/presence.rs @@ -18,7 +18,7 @@ pub struct PresenceEvent { pub content: PresenceEventContent, /// Contains the fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, } /// Informs the room of members presence. @@ -99,7 +99,7 @@ mod tests { presence: PresenceState::Online, status_msg: Some("Making cupcakes".into()), }, - sender: user_id!("@example:localhost"), + sender: user_id!("@example:localhost").to_owned(), }; let json = json!({ diff --git a/crates/ruma-events/src/receipt.rs b/crates/ruma-events/src/receipt.rs index c80c1a78..cfff685b 100644 --- a/crates/ruma-events/src/receipt.rs +++ b/crates/ruma-events/src/receipt.rs @@ -41,7 +41,7 @@ pub type Receipts = BTreeMap; /// A mapping of user ID to receipt. /// /// The user ID is the entity who sent this receipt. -pub type UserReceipts = BTreeMap; +pub type UserReceipts = BTreeMap, Receipt>; /// An acknowledgement of an event. #[derive(Clone, Debug, Default, Deserialize, Serialize)] diff --git a/crates/ruma-events/src/room/canonical_alias.rs b/crates/ruma-events/src/room/canonical_alias.rs index 4a767457..f9461404 100644 --- a/crates/ruma-events/src/room/canonical_alias.rs +++ b/crates/ruma-events/src/room/canonical_alias.rs @@ -55,7 +55,7 @@ mod tests { origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), prev_content: None, room_id: room_id!("!dummy:example.com").to_owned(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), state_key: "".into(), unsigned: Unsigned::default(), }; diff --git a/crates/ruma-events/src/room/create.rs b/crates/ruma-events/src/room/create.rs index a611a453..6b80b331 100644 --- a/crates/ruma-events/src/room/create.rs +++ b/crates/ruma-events/src/room/create.rs @@ -18,7 +18,7 @@ pub struct RoomCreateEventContent { /// /// This is set by the homeserver. #[ruma_event(skip_redaction)] - pub creator: UserId, + pub creator: Box, /// Whether or not this room's data should be transferred to other homeservers. #[serde( @@ -48,7 +48,7 @@ pub struct RoomCreateEventContent { impl RoomCreateEventContent { /// Creates a new `RoomCreateEventContent` with the given creator. - pub fn new(creator: UserId) -> Self { + pub fn new(creator: Box) -> Self { Self { creator, federate: true, @@ -119,7 +119,7 @@ mod tests { #[test] fn serialization() { let content = RoomCreateEventContent { - creator: user_id!("@carl:example.com"), + creator: user_id!("@carl:example.com").to_owned(), federate: false, room_version: RoomVersionId::Version4, predecessor: None, @@ -140,7 +140,7 @@ mod tests { #[test] fn space_serialization() { let content = RoomCreateEventContent { - creator: user_id!("@carl:example.com"), + creator: user_id!("@carl:example.com").to_owned(), federate: false, room_version: RoomVersionId::Version4, predecessor: None, diff --git a/crates/ruma-events/src/room/member.rs b/crates/ruma-events/src/room/member.rs index 2c10fad5..059f605f 100644 --- a/crates/ruma-events/src/room/member.rs +++ b/crates/ruma-events/src/room/member.rs @@ -174,7 +174,7 @@ pub struct SignedContent { /// The invited Matrix user ID. /// /// Must be equal to the user_id property of the event. - pub mxid: UserId, + pub mxid: Box, /// A single signature from the verifying server, in the format specified by the Signing Events /// section of the server-server API. @@ -187,7 +187,7 @@ pub struct SignedContent { impl SignedContent { /// Creates a new `SignedContent` with the given mxid, signature and token. pub fn new( - mxid: UserId, + mxid: Box, signatures: BTreeMap, BTreeMap>, token: String, ) -> Self { diff --git a/crates/ruma-events/src/room/message.rs b/crates/ruma-events/src/room/message.rs index 59bdfad3..1c6107ed 100644 --- a/crates/ruma-events/src/room/message.rs +++ b/crates/ruma-events/src/room/message.rs @@ -975,7 +975,7 @@ pub struct KeyVerificationRequestEventContent { /// Users should only respond to verification requests if they are named in this field. Users /// who are not named in this field and who did not send this event should ignore all other /// events that have a `m.reference` relationship with this event. - pub to: UserId, + pub to: Box, } #[cfg(feature = "unstable-pre-spec")] @@ -986,7 +986,7 @@ impl KeyVerificationRequestEventContent { body: String, methods: Vec, from_device: Box, - to: UserId, + to: Box, ) -> Self { Self { body, methods, from_device, to } } diff --git a/crates/ruma-events/src/room/message/reply.rs b/crates/ruma-events/src/room/message/reply.rs index 498e1aec..33970d08 100644 --- a/crates/ruma-events/src/room/message/reply.rs +++ b/crates/ruma-events/src/room/message/reply.rs @@ -300,21 +300,18 @@ fn formatted_or_plain_body<'a>(formatted: &'a Option, body: &'a s #[cfg(test)] mod tests { - use std::convert::TryFrom; - - use ruma_identifiers::{room_id, EventId, UserId}; + use ruma_identifiers::{event_id, room_id, user_id}; use super::RoomMessageEvent; use crate::room::message::RoomMessageEventContent; #[test] fn plain_quote_fallback_multiline() { - let sender = UserId::try_from("@alice:example.com").unwrap(); assert_eq!( super::get_plain_quote_fallback(&RoomMessageEvent { content: RoomMessageEventContent::text_plain("multi\nline"), - event_id: EventId::new(sender.server_name()), - sender, + event_id: event_id!("$1598361704261elfgc:localhost").to_owned(), + sender: user_id!("@alice:example.com").to_owned(), origin_server_ts: ruma_common::MilliSecondsSinceUnixEpoch::now(), room_id: room_id!("!n8f893n9:example.com").to_owned(), unsigned: crate::Unsigned::new(), diff --git a/crates/ruma-events/src/room/name.rs b/crates/ruma-events/src/room/name.rs index d545e88e..af6530b6 100644 --- a/crates/ruma-events/src/room/name.rs +++ b/crates/ruma-events/src/room/name.rs @@ -45,7 +45,7 @@ mod tests { origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), prev_content: None, room_id: room_id!("!n8f893n9:example.com").to_owned(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), state_key: "".into(), unsigned: Unsigned::default(), }; @@ -74,7 +74,7 @@ mod tests { origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), prev_content: Some(RoomNameEventContent { name: "The old name".try_into().ok() }), room_id: room_id!("!n8f893n9:example.com").to_owned(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), state_key: "".into(), unsigned: Unsigned { age: Some(int!(100)), ..Unsigned::default() }, }; diff --git a/crates/ruma-events/src/room/power_levels.rs b/crates/ruma-events/src/room/power_levels.rs index 111cf386..d5a72943 100644 --- a/crates/ruma-events/src/room/power_levels.rs +++ b/crates/ruma-events/src/room/power_levels.rs @@ -98,7 +98,7 @@ pub struct RoomPowerLevelsEventContent { )] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] #[ruma_event(skip_redaction)] - pub users: BTreeMap, + pub users: BTreeMap, Int>, /// The default power level for every user in the room. /// @@ -184,7 +184,7 @@ mod tests { prev_content: None, room_id: room_id!("!n8f893n9:example.com").to_owned(), unsigned: Unsigned::default(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), state_key: "".into(), }; @@ -217,7 +217,7 @@ mod tests { redact: int!(23), state_default: int!(23), users: btreemap! { - user.clone() => int!(23) + user.to_owned() => int!(23) }, users_default: int!(23), notifications: assign!(NotificationPowerLevels::new(), { room: int!(23) }), @@ -236,14 +236,14 @@ mod tests { redact: int!(42), state_default: int!(42), users: btreemap! { - user.clone() => int!(42) + user.to_owned() => int!(42) }, users_default: int!(42), notifications: assign!(NotificationPowerLevels::new(), { room: int!(42) }), }), room_id: room_id!("!n8f893n9:example.com").to_owned(), unsigned: Unsigned { age: Some(int!(100)), ..Unsigned::default() }, - sender: user, + sender: user.to_owned(), state_key: "".into(), }; diff --git a/crates/ruma-events/src/room/redaction.rs b/crates/ruma-events/src/room/redaction.rs index 6c829742..74e980c4 100644 --- a/crates/ruma-events/src/room/redaction.rs +++ b/crates/ruma-events/src/room/redaction.rs @@ -21,7 +21,7 @@ pub struct RoomRedactionEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -68,7 +68,7 @@ pub struct RedactedRoomRedactionEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -94,7 +94,7 @@ pub struct SyncRoomRedactionEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -137,7 +137,7 @@ pub struct RedactedSyncRoomRedactionEvent { pub event_id: Box, /// The fully-qualified ID of the user who sent this event. - pub sender: UserId, + pub sender: Box, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: MilliSecondsSinceUnixEpoch, diff --git a/crates/ruma-events/src/room_key.rs b/crates/ruma-events/src/room_key.rs index 07d63ef5..e53b1295 100644 --- a/crates/ruma-events/src/room_key.rs +++ b/crates/ruma-events/src/room_key.rs @@ -56,7 +56,7 @@ mod tests { session_id: "SessId".into(), session_key: "SessKey".into(), }, - sender: user_id!("@user:example.org"), + sender: user_id!("@user:example.org").to_owned(), }; assert_eq!( diff --git a/crates/ruma-events/src/typing.rs b/crates/ruma-events/src/typing.rs index 91f103e1..44e09136 100644 --- a/crates/ruma-events/src/typing.rs +++ b/crates/ruma-events/src/typing.rs @@ -12,12 +12,12 @@ use serde::{Deserialize, Serialize}; #[ruma_event(type = "m.typing", kind = EphemeralRoom)] pub struct TypingEventContent { /// The list of user IDs typing in this room, if any. - pub user_ids: Vec, + pub user_ids: Vec>, } impl TypingEventContent { /// Creates a new `TypingEventContent` with the given user IDs. - pub fn new(user_ids: Vec) -> Self { + pub fn new(user_ids: Vec>) -> Self { Self { user_ids } } } diff --git a/crates/ruma-events/tests/custom.rs b/crates/ruma-events/tests/custom.rs index 82c5b8f7..43b516dd 100644 --- a/crates/ruma-events/tests/custom.rs +++ b/crates/ruma-events/tests/custom.rs @@ -53,7 +53,7 @@ fn serialize_custom_message_event() { event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10)), room_id: room_id!("!room:room.com").to_owned(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), unsigned: Unsigned::default(), }; @@ -94,7 +94,7 @@ fn serialize_custom_state_event() { origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10)), prev_content: None, room_id: room_id!("!roomid:room.com").to_owned(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), state_key: "".into(), unsigned: Unsigned::default(), }; diff --git a/crates/ruma-events/tests/enums.rs b/crates/ruma-events/tests/enums.rs index 98eb9340..4028427b 100644 --- a/crates/ruma-events/tests/enums.rs +++ b/crates/ruma-events/tests/enums.rs @@ -205,7 +205,7 @@ fn message_event_serialization() { event_id: event_id!("$1234:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(0)), room_id: room_id!("!roomid:example.com").to_owned(), - sender: user_id!("@test:example.com"), + sender: user_id!("@test:example.com").to_owned(), unsigned: Unsigned::default(), }; @@ -286,7 +286,7 @@ fn alias_event_field_access() { if state_event.state_key() == "" && state_event.room_id() == room_id!("!room:room.com") && state_event.event_id() == event_id!("$152037280074GZeOm:localhost") - && state_event.sender() == &user_id!("@example:localhost") + && state_event.sender() == user_id!("@example:localhost") ); let deser = from_json_value::(json_data).unwrap(); diff --git a/crates/ruma-events/tests/ephemeral_event.rs b/crates/ruma-events/tests/ephemeral_event.rs index dd833ef3..5c2d2608 100644 --- a/crates/ruma-events/tests/ephemeral_event.rs +++ b/crates/ruma-events/tests/ephemeral_event.rs @@ -14,7 +14,7 @@ use ruma_events::{ #[test] fn ephemeral_serialize_typing() { let aliases_event = EphemeralRoomEvent { - content: TypingEventContent::new(vec![user_id!("@carl:example.com")]), + content: TypingEventContent::new(vec![user_id!("@carl:example.com").to_owned()]), room_id: room_id!("!roomid:room.com").to_owned(), }; @@ -53,7 +53,7 @@ fn deserialize_ephemeral_typing() { #[test] fn ephemeral_serialize_receipt() { let event_id = event_id!("$h29iv0s8:example.com").to_owned(); - let user_id = user_id!("@carl:example.com"); + let user_id = user_id!("@carl:example.com").to_owned(); let aliases_event = EphemeralRoomEvent { content: ReceiptEventContent(btreemap! { @@ -108,7 +108,7 @@ fn deserialize_ephemeral_receipt() { && room_id == room_id!("!roomid:room.com") && receipts .get(event_id) - .map(|r| r.get(&ReceiptType::Read).unwrap().get(&user_id).unwrap()) + .map(|r| r.get(&ReceiptType::Read).unwrap().get(user_id).unwrap()) .map(|r| r.ts) .unwrap() == Some(MilliSecondsSinceUnixEpoch(uint!(1))) diff --git a/crates/ruma-events/tests/event_enums.rs b/crates/ruma-events/tests/event_enums.rs index 4a3b81fe..a32114e4 100644 --- a/crates/ruma-events/tests/event_enums.rs +++ b/crates/ruma-events/tests/event_enums.rs @@ -89,7 +89,7 @@ fn serialize_message_event() { event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), room_id: room_id!("!roomid:room.com").to_owned(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), unsigned: Unsigned::default(), }); diff --git a/crates/ruma-events/tests/message_event.rs b/crates/ruma-events/tests/message_event.rs index a9897a6c..1bc5de0e 100644 --- a/crates/ruma-events/tests/message_event.rs +++ b/crates/ruma-events/tests/message_event.rs @@ -35,7 +35,7 @@ fn message_serialize_sticker() { event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), room_id: room_id!("!roomid:room.com").to_owned(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), unsigned: Unsigned::default(), }; diff --git a/crates/ruma-events/tests/pdu.rs b/crates/ruma-events/tests/pdu.rs index edd791cd..58b460ae 100644 --- a/crates/ruma-events/tests/pdu.rs +++ b/crates/ruma-events/tests/pdu.rs @@ -29,7 +29,7 @@ fn serialize_pdu_as_v1() { let v1_pdu = RoomV1Pdu { room_id: room_id!("!n8f893n9:example.com").to_owned(), event_id: event_id!("$somejoinevent:matrix.org").to_owned(), - sender: user_id!("@sender:example.com"), + sender: user_id!("@sender:example.com").to_owned(), origin: "matrix.org".into(), origin_server_ts: MilliSecondsSinceUnixEpoch(1_592_050_773_658_u64.try_into().unwrap()), kind: EventType::RoomPowerLevels, @@ -95,7 +95,7 @@ fn serialize_pdu_as_v3() { let v3_pdu = RoomV3Pdu { room_id: room_id!("!n8f893n9:example.com").to_owned(), - sender: user_id!("@sender:example.com"), + sender: user_id!("@sender:example.com").to_owned(), origin: "matrix.org".into(), origin_server_ts: MilliSecondsSinceUnixEpoch(1_592_050_773_658_u64.try_into().unwrap()), kind: EventType::RoomPowerLevels, diff --git a/crates/ruma-events/tests/redacted.rs b/crates/ruma-events/tests/redacted.rs index b38e26f2..122cbd2b 100644 --- a/crates/ruma-events/tests/redacted.rs +++ b/crates/ruma-events/tests/redacted.rs @@ -26,7 +26,7 @@ fn unsigned() -> RedactedUnsigned { redacts: event_id!("$h29iv0s8:example.com").to_owned(), event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), unsigned: Unsigned::default(), })); @@ -39,7 +39,7 @@ fn redacted_message_event_serialize() { content: RedactedRoomMessageEventContent::new(), event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), unsigned: RedactedUnsigned::default(), }; @@ -61,7 +61,7 @@ fn redacted_aliases_event_serialize_no_content() { event_id: event_id!("$h29iv0s8:example.com").to_owned(), state_key: "".into(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), unsigned: RedactedUnsigned::default(), }; @@ -84,7 +84,7 @@ fn redacted_aliases_event_serialize_with_content() { event_id: event_id!("$h29iv0s8:example.com").to_owned(), state_key: "".to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), unsigned: RedactedUnsigned::default(), }; @@ -163,7 +163,7 @@ fn redacted_deserialize_any_room_sync() { redacts: event_id!("$h29iv0s8:example.com").to_owned(), event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), unsigned: Unsigned::default(), })); @@ -250,7 +250,7 @@ fn redacted_custom_event_deserialize() { let redacted = RedactedSyncStateEvent { content: RedactedCustomEventContent { event_type: "m.made.up".into() }, event_id: event_id!("$h29iv0s8:example.com").to_owned(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), state_key: "hello there".into(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), unsigned: unsigned.clone(), @@ -289,7 +289,7 @@ fn redact_method_properly_redacts() { redacts: event_id!("$143273582443PhrSn:example.com").to_owned(), event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), unsigned: Unsigned::default(), }; diff --git a/crates/ruma-events/tests/redaction.rs b/crates/ruma-events/tests/redaction.rs index da57e9f0..63142fd5 100644 --- a/crates/ruma-events/tests/redaction.rs +++ b/crates/ruma-events/tests/redaction.rs @@ -32,7 +32,7 @@ fn serialize_redaction() { event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), room_id: room_id!("!roomid:room.com").to_owned(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), unsigned: Unsigned::default(), }; diff --git a/crates/ruma-events/tests/room_message.rs b/crates/ruma-events/tests/room_message.rs index 579c07c4..4601d78d 100644 --- a/crates/ruma-events/tests/room_message.rs +++ b/crates/ruma-events/tests/room_message.rs @@ -43,7 +43,7 @@ fn serialization() { event_id: event_id!("$143273582443PhrSn:example.org").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)), room_id: room_id!("!testroomid:example.org").to_owned(), - sender: user_id!("@user:example.org"), + sender: user_id!("@user:example.org").to_owned(), unsigned: Unsigned::default(), }; @@ -335,7 +335,7 @@ fn verification_request_deserialization() { #[test] #[cfg(feature = "unstable-pre-spec")] fn verification_request_serialization() { - let user_id = user_id!("@example2:localhost"); + let user_id = user_id!("@example2:localhost").to_owned(); let device_id: Box = "XOWLHHFSWM".into(); let body = "@example:localhost is requesting to verify your key, ...".to_owned(); diff --git a/crates/ruma-events/tests/state_event.rs b/crates/ruma-events/tests/state_event.rs index b0e43c86..f922f630 100644 --- a/crates/ruma-events/tests/state_event.rs +++ b/crates/ruma-events/tests/state_event.rs @@ -45,7 +45,7 @@ fn serialize_aliases_with_prev_content() { room_alias_id!("#inner:localhost").to_owned() ])), room_id: room_id!("!roomid:room.com").to_owned(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), state_key: "".into(), unsigned: Unsigned::default(), }; @@ -66,7 +66,7 @@ fn serialize_aliases_without_prev_content() { origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), prev_content: None, room_id: room_id!("!roomid:room.com").to_owned(), - sender: user_id!("@carl:example.com"), + sender: user_id!("@carl:example.com").to_owned(), state_key: "".into(), unsigned: Unsigned::default(), }; diff --git a/crates/ruma-events/tests/stripped.rs b/crates/ruma-events/tests/stripped.rs index c7c5de07..771e6934 100644 --- a/crates/ruma-events/tests/stripped.rs +++ b/crates/ruma-events/tests/stripped.rs @@ -13,7 +13,7 @@ fn serialize_stripped_state_event_any_content() { let event = StrippedStateEvent { content: RoomTopicEventContent::new("Testing room".into()), state_key: "".into(), - sender: user_id!("@example:localhost"), + sender: user_id!("@example:localhost").to_owned(), }; let json_data = json!({ @@ -33,7 +33,7 @@ fn serialize_stripped_state_event_any_event() { let event = AnyStrippedStateEvent::RoomTopic(StrippedStateEvent { content: RoomTopicEventContent::new("Testing room".into()), state_key: "".into(), - sender: user_id!("@example:localhost"), + sender: user_id!("@example:localhost").to_owned(), }); let json_data = json!({ diff --git a/crates/ruma-events/tests/to_device.rs b/crates/ruma-events/tests/to_device.rs index f077100c..41fb34c6 100644 --- a/crates/ruma-events/tests/to_device.rs +++ b/crates/ruma-events/tests/to_device.rs @@ -5,7 +5,7 @@ use serde_json::{json, to_value as to_json_value}; #[test] fn serialization() { let ev = ToDeviceEvent { - sender: user_id!("@example:example.org"), + sender: user_id!("@example:example.org").to_owned(), content: ToDeviceRoomKeyEventContent::new( EventEncryptionAlgorithm::MegolmV1AesSha2, room_id!("!testroomid:example.org").to_owned(), diff --git a/crates/ruma-events/tests/ui/04-event-sanity-check.rs b/crates/ruma-events/tests/ui/04-event-sanity-check.rs index 39182fd7..668eb284 100644 --- a/crates/ruma-events/tests/ui/04-event-sanity-check.rs +++ b/crates/ruma-events/tests/ui/04-event-sanity-check.rs @@ -13,7 +13,7 @@ use ruma_identifiers::{EventId, RoomId, UserId}; pub struct StateEvent { pub content: C, pub event_id: Box, - pub sender: UserId, + pub sender: Box, pub origin_server_ts: MilliSecondsSinceUnixEpoch, pub room_id: Box, pub state_key: String, diff --git a/crates/ruma-federation-api/src/device/get_devices/v1.rs b/crates/ruma-federation-api/src/device/get_devices/v1.rs index 66ef021a..ce9534a9 100644 --- a/crates/ruma-federation-api/src/device/get_devices/v1.rs +++ b/crates/ruma-federation-api/src/device/get_devices/v1.rs @@ -26,7 +26,7 @@ ruma_api! { response: { /// The user ID devices were requested for. - pub user_id: UserId, + pub user_id: Box, /// A unique ID for a given user_id which describes the version of the returned device list. /// @@ -50,7 +50,7 @@ impl Response { /// Creates a new `Response` with the given user id and stream id. /// /// The device list will be empty. - pub fn new(user_id: UserId, stream_id: UInt) -> Self { + pub fn new(user_id: Box, stream_id: UInt) -> Self { Self { user_id, stream_id, devices: Vec::new() } } } diff --git a/crates/ruma-federation-api/src/keys/claim_keys/v1.rs b/crates/ruma-federation-api/src/keys/claim_keys/v1.rs index 59f89a20..4c43caee 100644 --- a/crates/ruma-federation-api/src/keys/claim_keys/v1.rs +++ b/crates/ruma-federation-api/src/keys/claim_keys/v1.rs @@ -44,11 +44,11 @@ impl Response { } /// A claim for one time keys -pub type OneTimeKeyClaims = BTreeMap, DeviceKeyAlgorithm>>; +pub type OneTimeKeyClaims = BTreeMap, BTreeMap, DeviceKeyAlgorithm>>; /// One time keys for use in pre-key messages pub type OneTimeKeys = - BTreeMap, BTreeMap, OneTimeKey>>>; + BTreeMap, BTreeMap, BTreeMap, OneTimeKey>>>; /// A key and its signature #[derive(Debug, Clone, Serialize, Deserialize)] @@ -58,14 +58,14 @@ pub struct KeyObject { pub key: String, /// Signature of the key object. - pub signatures: BTreeMap, String>>, + pub signatures: BTreeMap, BTreeMap, String>>, } impl KeyObject { /// Creates a new `KeyObject` with the given key and signatures. pub fn new( key: String, - signatures: BTreeMap, String>>, + signatures: BTreeMap, BTreeMap, String>>, ) -> Self { Self { key, signatures } } diff --git a/crates/ruma-federation-api/src/keys/get_keys/v1.rs b/crates/ruma-federation-api/src/keys/get_keys/v1.rs index f2cf5222..4ca2efea 100644 --- a/crates/ruma-federation-api/src/keys/get_keys/v1.rs +++ b/crates/ruma-federation-api/src/keys/get_keys/v1.rs @@ -22,36 +22,36 @@ ruma_api! { /// The keys to be downloaded. /// /// Gives all keys for a given user if the list of device ids is empty. - pub device_keys: BTreeMap>>, + pub device_keys: BTreeMap, Vec>>, } #[derive(Default)] response: { /// Keys from the queried devices. - pub device_keys: BTreeMap, DeviceKeys>>, + pub device_keys: BTreeMap, BTreeMap, DeviceKeys>>, /// Information on the master cross-signing keys of the queried users. #[cfg(feature = "unstable-pre-spec")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub master_keys: BTreeMap, + pub master_keys: BTreeMap, CrossSigningKey>, /// Information on the self-signing keys of the queried users. #[cfg(feature = "unstable-pre-spec")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub self_signing_keys: BTreeMap, + pub self_signing_keys: BTreeMap, CrossSigningKey>, } } impl Request { /// Creates a new `Request` asking for the given device keys. - pub fn new(device_keys: BTreeMap>>) -> Self { + pub fn new(device_keys: BTreeMap, Vec>>) -> Self { Self { device_keys } } } impl Response { /// Creates a new `Response` with the given device keys. - pub fn new(device_keys: BTreeMap, DeviceKeys>>) -> Self { + pub fn new(device_keys: BTreeMap, BTreeMap, DeviceKeys>>) -> Self { Self { device_keys, ..Default::default() } } } diff --git a/crates/ruma-federation-api/src/openid/get_openid_userinfo/v1.rs b/crates/ruma-federation-api/src/openid/get_openid_userinfo/v1.rs index 687d2128..d0f26918 100644 --- a/crates/ruma-federation-api/src/openid/get_openid_userinfo/v1.rs +++ b/crates/ruma-federation-api/src/openid/get_openid_userinfo/v1.rs @@ -21,7 +21,7 @@ ruma_api! { response: { /// The Matrix User ID who generated the token. - pub sub: UserId, + pub sub: Box, } } @@ -34,7 +34,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given user id. - pub fn new(sub: UserId) -> Self { + pub fn new(sub: Box) -> Self { Self { sub } } } diff --git a/crates/ruma-federation-api/src/thirdparty/bind_callback/v1.rs b/crates/ruma-federation-api/src/thirdparty/bind_callback/v1.rs index 5dade970..26201a06 100644 --- a/crates/ruma-federation-api/src/thirdparty/bind_callback/v1.rs +++ b/crates/ruma-federation-api/src/thirdparty/bind_callback/v1.rs @@ -68,13 +68,13 @@ pub struct ThirdPartyInvite { pub address: String, /// The now-bound user ID that received the invite. - pub mxid: UserId, + pub mxid: Box, /// The room ID the invite is valid for. pub room_id: Box, /// The user ID that sent the invite. - pub sender: UserId, + pub sender: Box, /// Signature from the identity server using a long-term private key. pub signed: BTreeMap, BTreeMap>, @@ -84,9 +84,9 @@ impl ThirdPartyInvite { /// Creates a new third party invite with the given parameters. pub fn new( address: String, - mxid: UserId, + mxid: Box, room_id: Box, - sender: UserId, + sender: Box, signed: BTreeMap, BTreeMap>, ) -> Self { Self { medium: Medium::Email, address, mxid, room_id, sender, signed } diff --git a/crates/ruma-federation-api/src/transactions/edu.rs b/crates/ruma-federation-api/src/transactions/edu.rs index 47658949..f1b5a925 100644 --- a/crates/ruma-federation-api/src/transactions/edu.rs +++ b/crates/ruma-federation-api/src/transactions/edu.rs @@ -95,7 +95,7 @@ impl PresenceContent { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct PresenceUpdate { /// The user ID this presence EDU is for. - pub user_id: UserId, + pub user_id: Box, /// The presence of the user. pub presence: PresenceState, @@ -116,7 +116,7 @@ pub struct PresenceUpdate { impl PresenceUpdate { /// Creates a new `PresenceUpdate` with the given `user_id`, `presence` and `last_activity`. - pub fn new(user_id: UserId, presence: PresenceState, last_activity: UInt) -> Self { + pub fn new(user_id: Box, presence: PresenceState, last_activity: UInt) -> Self { Self { user_id, presence, @@ -149,12 +149,12 @@ impl ReceiptContent { pub struct ReceiptMap { /// Read receipts for users in the room. #[serde(rename = "m.read")] - pub read: BTreeMap, + pub read: BTreeMap, ReceiptData>, } impl ReceiptMap { /// Creates a new `ReceiptMap`. - pub fn new(read: BTreeMap) -> Self { + pub fn new(read: BTreeMap, ReceiptData>) -> Self { Self { read } } } @@ -185,7 +185,7 @@ pub struct TypingContent { pub room_id: Box, /// The user ID that has had their typing status changed. - pub user_id: UserId, + pub user_id: Box, /// Whether the user is typing in the room or not. pub typing: bool, @@ -193,7 +193,7 @@ pub struct TypingContent { impl TypingContent { /// Creates a new `TypingContent`. - pub fn new(room_id: Box, user_id: UserId, typing: bool) -> Self { + pub fn new(room_id: Box, user_id: Box, typing: bool) -> Self { Self { room_id, user_id, typing } } } @@ -203,7 +203,7 @@ impl TypingContent { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct DeviceListUpdateContent { /// The user ID who owns the device. - pub user_id: UserId, + pub user_id: Box, /// The ID of the device whose details are changing. pub device_id: Box, @@ -234,7 +234,7 @@ pub struct DeviceListUpdateContent { impl DeviceListUpdateContent { /// Create a new `DeviceListUpdateContent` with the given `user_id`, `device_id` and /// `stream_id`. - pub fn new(user_id: UserId, device_id: Box, stream_id: UInt) -> Self { + pub fn new(user_id: Box, device_id: Box, stream_id: UInt) -> Self { Self { user_id, device_id, @@ -252,7 +252,7 @@ impl DeviceListUpdateContent { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct DirectDeviceContent { /// The user ID of the sender. - pub sender: UserId, + pub sender: Box, /// Event type for the message. #[serde(rename = "type")] @@ -270,7 +270,7 @@ pub struct DirectDeviceContent { impl DirectDeviceContent { /// Creates a new `DirectDeviceContent` with the given `sender, `ev_type` and `message_id`. - pub fn new(sender: UserId, ev_type: EventType, message_id: String) -> Self { + pub fn new(sender: Box, ev_type: EventType, message_id: String) -> Self { Self { sender, ev_type, message_id, messages: DirectDeviceMessages::new() } } } @@ -279,7 +279,7 @@ impl DirectDeviceContent { /// /// Represented as a map of `{ user-ids => { device-ids => message-content } }`. pub type DirectDeviceMessages = - BTreeMap>>; + BTreeMap, BTreeMap>>; #[cfg(test)] mod test { @@ -460,7 +460,7 @@ mod test { }) if sender == "@john:example.com" && *ev_type == EventType::RoomKeyRequest && message_id == "hiezohf6Hoo7kaev" - && messages.get(&user_id!("@alice:example.org")).is_some() + && messages.get(user_id!("@alice:example.org")).is_some() ); assert_eq!(serde_json::to_value(&edu).unwrap(), json); diff --git a/crates/ruma-identifiers-macros/src/lib.rs b/crates/ruma-identifiers-macros/src/lib.rs index a49e6c87..a7dacb5c 100644 --- a/crates/ruma-identifiers-macros/src/lib.rs +++ b/crates/ruma-identifiers-macros/src/lib.rs @@ -129,7 +129,7 @@ pub fn user_id(input: TokenStream) -> TokenStream { assert!(user_id::validate(&id.value()).is_ok(), "Invalid user_id"); let output = quote! { - <#dollar_crate::UserId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap() + <&#dollar_crate::UserId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap() }; output.into() diff --git a/crates/ruma-identifiers/src/macros.rs b/crates/ruma-identifiers/src/macros.rs index d9d9bc18..0e22ef52 100644 --- a/crates/ruma-identifiers/src/macros.rs +++ b/crates/ruma-identifiers/src/macros.rs @@ -76,89 +76,6 @@ macro_rules! as_str_based_impls { }; } -macro_rules! common_impls { - ($id:ty, $try_from:ident, $desc:literal) => { - impl $id { - doc_concat! { - #[doc = concat!("Creates a string slice from this `", stringify!($id), "`")] - pub fn as_str(&self) -> &str { - &self.full_id - } - } - - doc_concat! { - #[doc = concat!("Creates a byte slice from this `", stringify!($id), "`")] - pub fn as_bytes(&self) -> &[u8] { - self.full_id.as_bytes() - } - } - - doc_concat! { - #[doc = concat!("Converts this `", stringify!($id), "` into a `String`")] - pub fn into_string(self) -> String { - self.full_id.into() - } - } - - doc_concat! { - #[doc = concat!("Converts this `", stringify!($id), "` into a `Vec`")] - pub fn into_bytes(self) -> Vec { - Box::<[u8]>::from(self.full_id).into() - } - } - } - - impl From<$id> for String { - fn from(id: $id) -> Self { - id.into_string() - } - } - - impl From<$id> for Vec { - fn from(id: $id) -> Self { - id.into_bytes() - } - } - - impl std::str::FromStr for $id { - type Err = crate::Error; - - fn from_str(s: &str) -> Result { - $try_from(s) - } - } - - impl std::convert::TryFrom<&str> for $id { - type Error = crate::Error; - - fn try_from(s: &str) -> Result { - $try_from(s) - } - } - - impl std::convert::TryFrom for $id { - type Error = crate::Error; - - fn try_from(s: String) -> Result { - $try_from(s) - } - } - - #[cfg(feature = "serde")] - impl<'de> serde::Deserialize<'de> for $id { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - crate::deserialize_id(deserializer, $desc) - } - } - - as_str_based_impls!($id); - partial_eq_string!($id); - }; -} - macro_rules! opaque_identifier_common_impls { ($id:ty) => { impl $id { diff --git a/crates/ruma-identifiers/src/user_id.rs b/crates/ruma-identifiers/src/user_id.rs index 3530979c..31feccdd 100644 --- a/crates/ruma-identifiers/src/user_id.rs +++ b/crates/ruma-identifiers/src/user_id.rs @@ -1,6 +1,6 @@ //! Matrix user identifiers. -use std::{convert::TryInto, fmt, num::NonZeroU8}; +use std::convert::TryInto; use crate::{MatrixToRef, ServerName}; @@ -13,39 +13,23 @@ use crate::{MatrixToRef, ServerName}; /// # use std::convert::TryFrom; /// # use ruma_identifiers::UserId; /// assert_eq!( -/// UserId::try_from("@carl:example.com").unwrap().as_ref(), +/// <&UserId>::try_from("@carl:example.com").unwrap(), /// "@carl:example.com" /// ); /// ``` -#[derive(Clone)] -pub struct UserId { - full_id: Box, - colon_idx: NonZeroU8, +#[repr(transparent)] +pub struct UserId(str); - /// Whether this user id is a historical one. - /// - /// A historical user id is one that is not legal per the regular user id rules, but was - /// accepted by previous versions of the spec and thus has to be supported because users with - /// these kinds of ids still exist. - is_historical: bool, -} - -impl fmt::Debug for UserId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.full_id.fmt(f) - } -} +opaque_identifier_validated!(UserId, ruma_identifiers_validation::user_id::validate); impl UserId { /// Attempts to generate a `UserId` for the given origin server with a localpart consisting of /// 12 random ASCII characters. #[cfg(feature = "rand")] - pub fn new(server_name: &ServerName) -> Self { - use crate::generate_localpart; - - let full_id = format!("@{}:{}", generate_localpart(12).to_lowercase(), server_name).into(); - - Self { full_id, colon_idx: NonZeroU8::new(13).unwrap(), is_historical: false } + pub fn new(server_name: &ServerName) -> Box { + Self::from_owned( + format!("@{}:{}", crate::generate_localpart(12).to_lowercase(), server_name).into(), + ) } /// Attempts to complete a user ID, by adding the colon + server name and `@` prefix, if not @@ -58,30 +42,24 @@ impl UserId { pub fn parse_with_server_name( id: impl AsRef + Into>, server_name: &ServerName, - ) -> Result { + ) -> Result, crate::Error> { let id_str = id.as_ref(); if id_str.starts_with('@') { - try_from(id.into()) + try_from(id) } else { - let is_fully_conforming = localpart_is_fully_conforming(id_str)?; - - Ok(Self { - full_id: format!("@{}:{}", id_str, server_name).into(), - colon_idx: NonZeroU8::new(id_str.len() as u8 + 1).unwrap(), - is_historical: !is_fully_conforming, - }) + Ok(Self::from_owned(format!("@{}:{}", id_str, server_name).into())) } } /// Returns the user's localpart. pub fn localpart(&self) -> &str { - &self.full_id[1..self.colon_idx.get() as usize] + &self.as_str()[1..self.colon_idx() as usize] } /// Returns the server name of the user ID. pub fn server_name(&self) -> &ServerName { - self.full_id[self.colon_idx.get() as usize + 1..].try_into().unwrap() + self.as_str()[self.colon_idx() as usize + 1..].try_into().unwrap() } /// Whether this user ID is a historical one. @@ -89,7 +67,7 @@ impl UserId { /// A historical user ID is one that doesn't conform to the latest specification of the user ID /// grammar but is still accepted because it was previously allowed. pub fn is_historical(&self) -> bool { - self.is_historical + !localpart_is_fully_conforming(self.localpart()).unwrap() } /// Create a `matrix.to` reference for this user ID. @@ -105,24 +83,14 @@ impl UserId { /// ); /// ``` pub fn matrix_to_url(&self) -> MatrixToRef<'_> { - MatrixToRef::new(&self.full_id, Vec::new()) + MatrixToRef::new(self.as_str(), Vec::new()) + } + + fn colon_idx(&self) -> usize { + self.as_str().find(':').unwrap() } } -/// Attempts to create a new Matrix user ID from a string representation. -/// -/// The string must include the leading @ sigil, the localpart, a literal colon, and a server name. -fn try_from(user_id: S) -> Result -where - S: AsRef + Into>, -{ - let (colon_idx, is_historical) = - ruma_identifiers_validation::user_id::validate(user_id.as_ref())?; - Ok(UserId { full_id: user_id.into(), colon_idx, is_historical: !is_historical }) -} - -common_impls!(UserId, try_from, "a Matrix user ID"); - pub use ruma_identifiers_validation::user_id::localpart_is_fully_conforming; #[cfg(test)] @@ -134,8 +102,8 @@ mod tests { #[test] fn valid_user_id_from_str() { - let user_id = UserId::try_from("@carl:example.com").expect("Failed to create UserId."); - assert_eq!(user_id.as_ref(), "@carl:example.com"); + let user_id = <&UserId>::try_from("@carl:example.com").expect("Failed to create UserId."); + assert_eq!(user_id.as_str(), "@carl:example.com"); assert_eq!(user_id.localpart(), "carl"); assert_eq!(user_id.server_name(), "example.com"); assert!(!user_id.is_historical()); @@ -146,7 +114,7 @@ mod tests { let server_name = server_name!("example.com"); let user_id = UserId::parse_with_server_name("@carl:example.com", &server_name) .expect("Failed to create UserId."); - assert_eq!(user_id.as_ref(), "@carl:example.com"); + assert_eq!(user_id.as_str(), "@carl:example.com"); assert_eq!(user_id.localpart(), "carl"); assert_eq!(user_id.server_name(), "example.com"); assert!(!user_id.is_historical()); @@ -157,7 +125,7 @@ mod tests { let server_name = server_name!("example.com"); let user_id = UserId::parse_with_server_name("carl", &server_name).expect("Failed to create UserId."); - assert_eq!(user_id.as_ref(), "@carl:example.com"); + assert_eq!(user_id.as_str(), "@carl:example.com"); assert_eq!(user_id.localpart(), "carl"); assert_eq!(user_id.server_name(), "example.com"); assert!(!user_id.is_historical()); @@ -165,8 +133,9 @@ mod tests { #[test] fn valid_historical_user_id() { - let user_id = UserId::try_from("@a%b[irc]:example.com").expect("Failed to create UserId."); - assert_eq!(user_id.as_ref(), "@a%b[irc]:example.com"); + let user_id = + <&UserId>::try_from("@a%b[irc]:example.com").expect("Failed to create UserId."); + assert_eq!(user_id.as_str(), "@a%b[irc]:example.com"); assert_eq!(user_id.localpart(), "a%b[irc]"); assert_eq!(user_id.server_name(), "example.com"); assert!(user_id.is_historical()); @@ -177,7 +146,7 @@ mod tests { let server_name = server_name!("example.com"); let user_id = UserId::parse_with_server_name("@a%b[irc]:example.com", &server_name) .expect("Failed to create UserId."); - assert_eq!(user_id.as_ref(), "@a%b[irc]:example.com"); + assert_eq!(user_id.as_str(), "@a%b[irc]:example.com"); assert_eq!(user_id.localpart(), "a%b[irc]"); assert_eq!(user_id.server_name(), "example.com"); assert!(user_id.is_historical()); @@ -188,7 +157,7 @@ mod tests { let server_name = server_name!("example.com"); let user_id = UserId::parse_with_server_name("a%b[irc]", &server_name) .expect("Failed to create UserId."); - assert_eq!(user_id.as_ref(), "@a%b[irc]:example.com"); + assert_eq!(user_id.as_str(), "@a%b[irc]:example.com"); assert_eq!(user_id.localpart(), "a%b[irc]"); assert_eq!(user_id.server_name(), "example.com"); assert!(user_id.is_historical()); @@ -196,8 +165,8 @@ mod tests { #[test] fn uppercase_user_id() { - let user_id = UserId::try_from("@CARL:example.com").expect("Failed to create UserId."); - assert_eq!(user_id.as_ref(), "@CARL:example.com"); + let user_id = <&UserId>::try_from("@CARL:example.com").expect("Failed to create UserId."); + assert_eq!(user_id.as_str(), "@CARL:example.com"); assert!(user_id.is_historical()); } @@ -220,7 +189,7 @@ mod tests { fn serialize_valid_user_id() { assert_eq!( serde_json::to_string( - &UserId::try_from("@carl:example.com").expect("Failed to create UserId.") + <&UserId>::try_from("@carl:example.com").expect("Failed to create UserId.") ) .expect("Failed to convert UserId to JSON."), r#""@carl:example.com""# @@ -231,52 +200,61 @@ mod tests { #[test] fn deserialize_valid_user_id() { assert_eq!( - serde_json::from_str::(r#""@carl:example.com""#) + serde_json::from_str::>(r#""@carl:example.com""#) .expect("Failed to convert JSON to UserId"), - UserId::try_from("@carl:example.com").expect("Failed to create UserId.") + <&UserId>::try_from("@carl:example.com").expect("Failed to create UserId.") ); } #[test] fn valid_user_id_with_explicit_standard_port() { assert_eq!( - UserId::try_from("@carl:example.com:443").expect("Failed to create UserId.").as_ref(), + <&UserId>::try_from("@carl:example.com:443") + .expect("Failed to create UserId.") + .as_ref(), "@carl:example.com:443" ); } #[test] fn valid_user_id_with_non_standard_port() { - let user_id = UserId::try_from("@carl:example.com:5000").expect("Failed to create UserId."); - assert_eq!(user_id.as_ref(), "@carl:example.com:5000"); + let user_id = + <&UserId>::try_from("@carl:example.com:5000").expect("Failed to create UserId."); + assert_eq!(user_id.as_str(), "@carl:example.com:5000"); assert!(!user_id.is_historical()); } #[test] #[cfg(not(feature = "compat"))] fn invalid_characters_in_user_id_localpart() { - assert_eq!(UserId::try_from("@te\nst:example.com").unwrap_err(), Error::InvalidCharacters); + assert_eq!( + <&UserId>::try_from("@te\nst:example.com").unwrap_err(), + Error::InvalidCharacters + ); } #[test] fn missing_user_id_sigil() { - assert_eq!(UserId::try_from("carl:example.com").unwrap_err(), Error::MissingLeadingSigil); + assert_eq!( + <&UserId>::try_from("carl:example.com").unwrap_err(), + Error::MissingLeadingSigil + ); } #[test] fn missing_user_id_delimiter() { - assert_eq!(UserId::try_from("@carl").unwrap_err(), Error::MissingDelimiter); + assert_eq!(<&UserId>::try_from("@carl").unwrap_err(), Error::MissingDelimiter); } #[test] fn invalid_user_id_host() { - assert_eq!(UserId::try_from("@carl:/").unwrap_err(), Error::InvalidServerName); + assert_eq!(<&UserId>::try_from("@carl:/").unwrap_err(), Error::InvalidServerName); } #[test] fn invalid_user_id_port() { assert_eq!( - UserId::try_from("@carl:example.com:notaport").unwrap_err(), + <&UserId>::try_from("@carl:example.com:notaport").unwrap_err(), Error::InvalidServerName ); } diff --git a/crates/ruma-identity-service-api/src/association/bind_3pid/v2.rs b/crates/ruma-identity-service-api/src/association/bind_3pid/v2.rs index d9417e73..ca260fc1 100644 --- a/crates/ruma-identity-service-api/src/association/bind_3pid/v2.rs +++ b/crates/ruma-identity-service-api/src/association/bind_3pid/v2.rs @@ -33,7 +33,7 @@ ruma_api! { pub medium: Medium, /// The Matrix user ID associated with the 3PID. - pub mxid: UserId, + pub mxid: Box, /// A UNIX timestamp before which the association is not known to be valid. pub not_before: MilliSecondsSinceUnixEpoch, @@ -63,7 +63,7 @@ impl Response { pub fn new( address: String, medium: Medium, - mxid: UserId, + mxid: Box, not_before: MilliSecondsSinceUnixEpoch, not_after: MilliSecondsSinceUnixEpoch, ts: MilliSecondsSinceUnixEpoch, diff --git a/crates/ruma-identity-service-api/src/authentication/get_account_information/v2.rs b/crates/ruma-identity-service-api/src/authentication/get_account_information/v2.rs index bccf7dac..86ad3091 100644 --- a/crates/ruma-identity-service-api/src/authentication/get_account_information/v2.rs +++ b/crates/ruma-identity-service-api/src/authentication/get_account_information/v2.rs @@ -18,7 +18,7 @@ ruma_api! { response: { /// The user ID which registered the token. - pub user_id: UserId, + pub user_id: Box, } } @@ -31,7 +31,7 @@ impl Request { impl Response { /// Creates a new `Response` with the given `UserId`. - pub fn new(user_id: UserId) -> Self { + pub fn new(user_id: Box) -> Self { Self { user_id } } } diff --git a/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519/v2.rs b/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519/v2.rs index b1d90d83..04791618 100644 --- a/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519/v2.rs +++ b/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519/v2.rs @@ -26,10 +26,10 @@ ruma_api! { response: { /// The Matrix user ID of the user accepting the invitation. - pub mxid: UserId, + pub mxid: Box, /// The Matrix user ID of the user who sent the invitation. - pub sender: UserId, + pub sender: Box, /// The signature of the mxid, sender and token. pub signatures: ServerSignatures, @@ -48,7 +48,12 @@ impl<'a> Request<'a> { impl Response { /// Creates a `Response` with the given Matrix user ID, sender user ID, signatures and token. - pub fn new(mxid: UserId, sender: UserId, signatures: ServerSignatures, token: String) -> Self { + pub fn new( + mxid: Box, + sender: Box, + signatures: ServerSignatures, + token: String, + ) -> Self { Self { mxid, sender, signatures, token } } } diff --git a/crates/ruma-identity-service-api/src/lookup/lookup_3pid/v2.rs b/crates/ruma-identity-service-api/src/lookup/lookup_3pid/v2.rs index fd06626d..be044de9 100644 --- a/crates/ruma-identity-service-api/src/lookup/lookup_3pid/v2.rs +++ b/crates/ruma-identity-service-api/src/lookup/lookup_3pid/v2.rs @@ -38,7 +38,7 @@ ruma_api! { /// /// Addresses which do not have associations will not be included, which can make this /// property be an empty object. - pub mappings: BTreeMap, + pub mappings: BTreeMap>, } } @@ -56,7 +56,7 @@ impl<'a> Request<'a> { impl Response { /// Create a `Response` with the BTreeMap which map addresses from the request which were /// found to their corresponding User IDs. - pub fn new(mappings: BTreeMap) -> Self { + pub fn new(mappings: BTreeMap>) -> Self { Self { mappings } } } diff --git a/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs b/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs index 00c77950..991a3ce3 100644 --- a/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs +++ b/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs @@ -366,7 +366,7 @@ mod tests { event_id: Some(eid), room_id: Some(rid), event_type: Some(&EventType::RoomMessage), - sender: Some(&uid), + sender: Some(uid), sender_display_name: Some("Major Tom"), room_alias: Some(alias), content: Some(serde_json::from_str("{}").unwrap()), diff --git a/crates/ruma-serde-macros/src/outgoing.rs b/crates/ruma-serde-macros/src/outgoing.rs index 4c9e8c01..d44fca39 100644 --- a/crates/ruma-serde-macros/src/outgoing.rs +++ b/crates/ruma-serde-macros/src/outgoing.rs @@ -271,6 +271,7 @@ fn strip_lifetimes(field_type: &mut Type) -> bool { || last_seg.ident == "RoomId" || last_seg.ident == "RoomIdOrAliasId" || last_seg.ident == "RoomName" + || last_seg.ident == "UserId" { // The identifiers that need to be boxed `Box` since they are DST's. Some(parse_quote! { ::std::boxed::Box<#path> }) diff --git a/crates/ruma-serde/tests/empty_strings.rs b/crates/ruma-serde/tests/empty_strings.rs index f813ffc1..e073161a 100644 --- a/crates/ruma-serde/tests/empty_strings.rs +++ b/crates/ruma-serde/tests/empty_strings.rs @@ -55,8 +55,8 @@ mod user { const CARL: &str = "@carl:example.com"; - fn carl() -> UserId { - user_id!("@carl:example.com") + fn carl() -> Box { + user_id!("@carl:example.com").to_owned() } #[derive(Serialize, Deserialize, PartialEq, Debug)] @@ -66,7 +66,7 @@ mod user { deserialize_with = "ruma_serde::empty_string_as_none", serialize_with = "ruma_serde::none_as_empty_string" )] - x: Option, + x: Option>, } #[test] diff --git a/crates/ruma-signatures/src/functions.rs b/crates/ruma-signatures/src/functions.rs index ec3850a2..ec9fe426 100644 --- a/crates/ruma-signatures/src/functions.rs +++ b/crates/ruma-signatures/src/functions.rs @@ -3,8 +3,8 @@ use std::{ borrow::Cow, collections::{BTreeMap, BTreeSet}, + convert::TryFrom, mem, - str::FromStr, }; use base64::{decode_config, encode_config, Config, STANDARD_NO_PAD, URL_SAFE_NO_PAD}; @@ -780,8 +780,8 @@ fn servers_to_check_signatures( if !is_third_party_invite(object)? { match object.get("sender") { Some(CanonicalJsonValue::String(raw_sender)) => { - let user_id = - UserId::from_str(raw_sender).map_err(|e| Error::from(ParseError::UserId(e)))?; + let user_id = <&UserId>::try_from(raw_sender.as_str()) + .map_err(|e| Error::from(ParseError::UserId(e)))?; servers_to_check.insert(user_id.server_name().to_owned()); } diff --git a/crates/ruma-state-res/benches/state_res_bench.rs b/crates/ruma-state-res/benches/state_res_bench.rs index 12290ea7..cac9f28a 100644 --- a/crates/ruma-state-res/benches/state_res_bench.rs +++ b/crates/ruma-state-res/benches/state_res_bench.rs @@ -9,7 +9,7 @@ use std::{ collections::{HashMap, HashSet}, - convert::{TryFrom, TryInto}, + convert::TryInto, sync::{ atomic::{AtomicU64, Ordering::SeqCst}, Arc, @@ -29,7 +29,7 @@ use ruma_events::{ }, EventType, }; -use ruma_identifiers::{room_id, EventId, RoomId, RoomVersionId, UserId}; +use ruma_identifiers::{room_id, user_id, EventId, RoomId, RoomVersionId, UserId}; use ruma_state_res::{self as state_res, Error, Event, Result, StateMap}; use serde_json::{ json, @@ -339,20 +339,20 @@ fn event_id(id: &str) -> Box { format!("${}:foo", id).try_into().unwrap() } -fn alice() -> UserId { - UserId::try_from("@alice:foo").unwrap() +fn alice() -> Box { + user_id!("@alice:foo").to_owned() } -fn bob() -> UserId { - UserId::try_from("@bob:foo").unwrap() +fn bob() -> Box { + user_id!("@bob:foo").to_owned() } -fn charlie() -> UserId { - UserId::try_from("@charlie:foo").unwrap() +fn charlie() -> Box { + user_id!("@charlie:foo").to_owned() } -fn ella() -> UserId { - UserId::try_from("@ella:foo").unwrap() +fn ella() -> Box { + user_id!("@ella:foo").to_owned() } fn room_id() -> &'static RoomId { @@ -369,7 +369,7 @@ fn member_content_join() -> Box { fn to_pdu_event( id: &str, - sender: UserId, + sender: Box, ev_type: EventType, state_key: Option<&str>, content: Box, diff --git a/crates/ruma-state-res/src/event_auth.rs b/crates/ruma-state-res/src/event_auth.rs index b327b7cf..cb8429a4 100644 --- a/crates/ruma-state-res/src/event_auth.rs +++ b/crates/ruma-state-res/src/event_auth.rs @@ -227,10 +227,10 @@ pub fn auth_check( } let target_user = - UserId::try_from(state_key).map_err(|e| Error::InvalidPdu(format!("{}", e)))?; + <&UserId>::try_from(state_key).map_err(|e| Error::InvalidPdu(format!("{}", e)))?; if !valid_membership_change( - &target_user, + target_user, fetch_state(&EventType::RoomMember, target_user.as_str()).as_ref(), sender, sender_member_event.as_ref(), diff --git a/crates/ruma-state-res/src/lib.rs b/crates/ruma-state-res/src/lib.rs index 8d51ec17..0acfe025 100644 --- a/crates/ruma-state-res/src/lib.rs +++ b/crates/ruma-state-res/src/lib.rs @@ -325,7 +325,7 @@ struct PowerLevelsContentFields { serde(deserialize_with = "ruma_serde::btreemap_int_or_string_to_int_values") )] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - users: BTreeMap, + users: BTreeMap, Int>, #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] #[serde(default, skip_serializing_if = "ruma_serde::is_default")] diff --git a/crates/ruma-state-res/src/test_utils.rs b/crates/ruma-state-res/src/test_utils.rs index 9b83eae2..c7967eb3 100644 --- a/crates/ruma-state-res/src/test_utils.rs +++ b/crates/ruma-state-res/src/test_utils.rs @@ -153,7 +153,7 @@ pub fn do_check( let ev_id = e.event_id(); let event = to_pdu_event( e.event_id().as_str(), - e.sender().clone(), + e.sender().to_owned(), e.event_type().clone(), e.state_key(), e.content().to_owned(), @@ -347,24 +347,24 @@ pub fn event_id(id: &str) -> Box { format!("${}:foo", id).try_into().unwrap() } -pub fn alice() -> UserId { - user_id!("@alice:foo") +pub fn alice() -> Box { + user_id!("@alice:foo").to_owned() } -pub fn bob() -> UserId { - user_id!("@bob:foo") +pub fn bob() -> Box { + user_id!("@bob:foo").to_owned() } -pub fn charlie() -> UserId { - user_id!("@charlie:foo") +pub fn charlie() -> Box { + user_id!("@charlie:foo").to_owned() } -pub fn ella() -> UserId { - user_id!("@ella:foo") +pub fn ella() -> Box { + user_id!("@ella:foo").to_owned() } -pub fn zara() -> UserId { - user_id!("@zara:foo") +pub fn zara() -> Box { + user_id!("@zara:foo").to_owned() } pub fn room_id() -> &'static RoomId { @@ -381,7 +381,7 @@ pub fn member_content_join() -> Box { pub fn to_init_pdu_event( id: &str, - sender: UserId, + sender: Box, ev_type: EventType, state_key: Option<&str>, content: Box, @@ -414,7 +414,7 @@ pub fn to_init_pdu_event( pub fn to_pdu_event( id: &str, - sender: UserId, + sender: Box, ev_type: EventType, state_key: Option<&str>, content: Box,