From 0a9b6c136fcc29d4f72996dc7eaf7ed4948e820a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 28 Dec 2024 23:31:24 +0000 Subject: [PATCH] refactor for ruma identifiers optimizations Signed-off-by: Jason Volk --- Cargo.lock | 26 ++++++------ Cargo.toml | 2 +- src/admin/debug/commands.rs | 2 +- src/admin/room/alias.rs | 5 +-- src/admin/room/moderation.rs | 28 ++++++------- src/api/client/room/create.rs | 40 +++++++++---------- src/api/client/session.rs | 6 +-- src/api/client/sync/v3.rs | 10 ++--- src/api/client/sync/v4.rs | 4 +- src/api/router/auth.rs | 2 +- src/api/server/invite.rs | 4 +- src/service/globals/mod.rs | 6 +-- src/service/rooms/alias/mod.rs | 6 +-- .../rooms/event_handler/parse_incoming_pdu.rs | 4 +- src/service/rooms/state/mod.rs | 2 +- src/service/rooms/timeline/mod.rs | 10 ++--- src/service/sending/data.rs | 8 ++-- src/service/sending/sender.rs | 2 +- src/service/users/mod.rs | 2 +- 19 files changed, 81 insertions(+), 88 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0404f778..5b00a313 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3173,7 +3173,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.10.1" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "assign", "js_int", @@ -3195,7 +3195,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "js_int", "ruma-common", @@ -3207,7 +3207,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "as_variant", "assign", @@ -3230,7 +3230,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "as_variant", "base64 0.22.1", @@ -3261,7 +3261,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "as_variant", "indexmap 2.7.0", @@ -3286,7 +3286,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "bytes", "http", @@ -3304,7 +3304,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "js_int", "thiserror 2.0.7", @@ -3313,7 +3313,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "js_int", "ruma-common", @@ -3323,7 +3323,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "cfg-if", "proc-macro-crate", @@ -3338,7 +3338,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "js_int", "ruma-common", @@ -3350,7 +3350,7 @@ dependencies = [ [[package]] name = "ruma-server-util" version = "0.3.0" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "headers", "http", @@ -3363,7 +3363,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "base64 0.22.1", "ed25519-dalek", @@ -3379,7 +3379,7 @@ dependencies = [ [[package]] name = "ruma-state-res" version = "0.11.0" -source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785" dependencies = [ "futures-util", "js_int", diff --git a/Cargo.toml b/Cargo.toml index 36f6c1ad..24e6eb79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -336,7 +336,7 @@ version = "0.1.2" [workspace.dependencies.ruma] git = "https://github.com/girlbossceo/ruwuma" #branch = "conduwuit-changes" -rev = "54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a" +rev = "30a08ff7be779df6858036c3f01f3ba64c1ee785" features = [ "compat", "rand", diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index 85a014b9..5bc65d9b 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -75,7 +75,7 @@ pub(super) async fn parse_pdu(&self) -> Result { match serde_json::from_str(&string) { | Ok(value) => match ruma::signatures::reference_hash(&value, &RoomVersionId::V6) { | Ok(hash) => { - let event_id = EventId::parse(format!("${hash}")); + let event_id = OwnedEventId::parse(format!("${hash}")); match serde_json::from_value::( serde_json::to_value(value).expect("value is json"), diff --git a/src/admin/room/alias.rs b/src/admin/room/alias.rs index 835138b2..4490600d 100644 --- a/src/admin/room/alias.rs +++ b/src/admin/room/alias.rs @@ -4,8 +4,7 @@ use clap::Subcommand; use conduwuit::Result; use futures::StreamExt; use ruma::{ - events::room::message::RoomMessageEventContent, OwnedRoomAliasId, OwnedRoomId, RoomAliasId, - RoomId, + events::room::message::RoomMessageEventContent, OwnedRoomAliasId, OwnedRoomId, RoomId, }; use crate::{escape_html, Command}; @@ -58,7 +57,7 @@ pub(super) async fn process( | RoomAliasCommand::Which { ref room_alias_localpart } => { let room_alias_str = format!("#{}:{}", room_alias_localpart, services.globals.server_name()); - let room_alias = match RoomAliasId::parse_box(room_alias_str) { + let room_alias = match OwnedRoomAliasId::parse(room_alias_str) { | Ok(alias) => alias, | Err(err) => return Ok(RoomMessageEventContent::text_plain(format!( diff --git a/src/admin/room/moderation.rs b/src/admin/room/moderation.rs index b16aff1f..bf54505e 100644 --- a/src/admin/room/moderation.rs +++ b/src/admin/room/moderation.rs @@ -105,10 +105,9 @@ async fn ban_room( }; debug!("Room specified is a room ID, banning room ID"); + self.services.rooms.metadata.ban_room(room_id, true); - self.services.rooms.metadata.ban_room(&room_id, true); - - room_id + room_id.to_owned() } else if room.is_room_alias_id() { let room_alias = match RoomAliasId::parse(&room) { | Ok(room_alias) => room_alias, @@ -129,7 +128,7 @@ async fn ban_room( .services .rooms .alias - .resolve_local_alias(&room_alias) + .resolve_local_alias(room_alias) .await { room_id @@ -143,20 +142,20 @@ async fn ban_room( .services .rooms .alias - .resolve_alias(&room_alias, None) + .resolve_alias(room_alias, None) .await { | Ok((room_id, servers)) => { debug!( ?room_id, ?servers, - "Got federation response fetching room ID for {room}" + "Got federation response fetching room ID for {room_id}" ); room_id }, | Err(e) => { return Ok(RoomMessageEventContent::notice_plain(format!( - "Failed to resolve room alias {room} to a room ID: {e}" + "Failed to resolve room alias {room_alias} to a room ID: {e}" ))); }, } @@ -316,7 +315,7 @@ async fn ban_list_of_rooms( }, }; - room_ids.push(room_id); + room_ids.push(room_id.to_owned()); } if room_alias_or_id.is_room_alias_id() { @@ -326,7 +325,7 @@ async fn ban_list_of_rooms( .services .rooms .alias - .resolve_local_alias(&room_alias) + .resolve_local_alias(room_alias) .await { room_id @@ -340,7 +339,7 @@ async fn ban_list_of_rooms( .services .rooms .alias - .resolve_alias(&room_alias, None) + .resolve_alias(room_alias, None) .await { | Ok((room_id, servers)) => { @@ -519,10 +518,9 @@ async fn unban_room( }; debug!("Room specified is a room ID, unbanning room ID"); + self.services.rooms.metadata.ban_room(room_id, false); - self.services.rooms.metadata.ban_room(&room_id, false); - - room_id + room_id.to_owned() } else if room.is_room_alias_id() { let room_alias = match RoomAliasId::parse(&room) { | Ok(room_alias) => room_alias, @@ -543,7 +541,7 @@ async fn unban_room( .services .rooms .alias - .resolve_local_alias(&room_alias) + .resolve_local_alias(room_alias) .await { room_id @@ -557,7 +555,7 @@ async fn unban_room( .services .rooms .alias - .resolve_alias(&room_alias, None) + .resolve_alias(room_alias, None) .await { | Ok((room_id, servers)) => { diff --git a/src/api/client/room/create.rs b/src/api/client/room/create.rs index 89cddc0f..a78242ca 100644 --- a/src/api/client/room/create.rs +++ b/src/api/client/room/create.rs @@ -1,7 +1,9 @@ use std::collections::BTreeMap; use axum::extract::State; -use conduwuit::{debug_info, debug_warn, error, info, pdu::PduBuilder, warn, Err, Error, Result}; +use conduwuit::{ + debug_info, debug_warn, err, error, info, pdu::PduBuilder, warn, Err, Error, Result, +}; use futures::FutureExt; use ruma::{ api::client::{ @@ -24,8 +26,7 @@ use ruma::{ }, int, serde::{JsonObject, Raw}, - CanonicalJsonObject, Int, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, - RoomVersionId, + CanonicalJsonObject, Int, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomId, RoomVersionId, }; use serde_json::{json, value::to_raw_value}; use service::{appservice::RegistrationInfo, Services}; @@ -554,14 +555,15 @@ async fn room_alias_check( return Err(Error::BadRequest(ErrorKind::Unknown, "Room alias name is forbidden.")); } - let full_room_alias = RoomAliasId::parse(format!( - "#{}:{}", - room_alias_name, services.globals.config.server_name - )) - .map_err(|e| { - info!("Failed to parse room alias {room_alias_name}: {e}"); - Error::BadRequest(ErrorKind::InvalidParam, "Invalid room alias specified.") - })?; + let server_name = services.globals.server_name(); + let full_room_alias = OwnedRoomAliasId::parse(format!("#{room_alias_name}:{server_name}")) + .map_err(|e| { + err!(Request(InvalidParam(debug_error!( + ?e, + ?room_alias_name, + "Failed to parse room alias.", + )))) + })?; if services .rooms @@ -620,15 +622,11 @@ fn custom_room_id_check(services: &Services, custom_room_id: &str) -> Result { // A new user joined an encrypted room - if !share_encrypted_room(services, sender_user, &user_id, Some(room_id)) + if !share_encrypted_room(services, sender_user, user_id, Some(room_id)) .await { - device_list_updates.insert(user_id); + device_list_updates.insert(user_id.into()); } }, | MembershipState::Leave => { // Write down users that have left encrypted rooms we are in - left_encrypted_users.insert(user_id); + left_encrypted_users.insert(user_id.into()); }, | _ => {}, } diff --git a/src/api/client/sync/v4.rs b/src/api/client/sync/v4.rs index 0c6ea650..9915752e 100644 --- a/src/api/client/sync/v4.rs +++ b/src/api/client/sync/v4.rs @@ -30,7 +30,7 @@ use ruma::{ TimelineEventType::{self, *}, }, serde::Raw, - uint, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, UInt, UserId, + uint, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, UInt, }; use service::{rooms::read_receipt::pack_receipts, Services}; @@ -243,7 +243,7 @@ pub(crate) async fn sync_events_v4_route( if pdu.kind == RoomMember { if let Some(state_key) = &pdu.state_key { let user_id = - UserId::parse(state_key.clone()).map_err(|_| { + OwnedUserId::parse(state_key.clone()).map_err(|_| { Error::bad_database("Invalid UserId in member PDU.") })?; diff --git a/src/api/router/auth.rs b/src/api/router/auth.rs index c5b040e0..dd25e091 100644 --- a/src/api/router/auth.rs +++ b/src/api/router/auth.rs @@ -212,7 +212,7 @@ async fn auth_appservice( .query .user_id .clone() - .map_or_else(user_id_default, UserId::parse) + .map_or_else(user_id_default, OwnedUserId::parse) else { return Err!(Request(InvalidUsername("Username is invalid."))); }; diff --git a/src/api/server/invite.rs b/src/api/server/invite.rs index a5b4a11c..6d3be04c 100644 --- a/src/api/server/invite.rs +++ b/src/api/server/invite.rs @@ -6,7 +6,7 @@ use ruma::{ api::{client::error::ErrorKind, federation::membership::create_invite}, events::room::member::{MembershipState, RoomMemberEventContent}, serde::JsonObject, - CanonicalJsonValue, EventId, OwnedUserId, UserId, + CanonicalJsonValue, OwnedEventId, OwnedUserId, UserId, }; use crate::Ruma; @@ -86,7 +86,7 @@ pub(crate) async fn create_invite_route( .map_err(|e| err!(Request(InvalidParam("Failed to sign event: {e}"))))?; // Generate event id - let event_id = EventId::parse(format!( + let event_id = OwnedEventId::parse(format!( "${}", ruma::signatures::reference_hash(&signed_event, &body.room_version) .expect("ruma can calculate reference hashes") diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index 88199f5f..3f98babe 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -10,9 +10,7 @@ use std::{ use conduwuit::{error, Config, Result}; use data::Data; use regex::RegexSet; -use ruma::{ - OwnedEventId, OwnedRoomAliasId, OwnedServerName, OwnedUserId, RoomAliasId, ServerName, UserId, -}; +use ruma::{OwnedEventId, OwnedRoomAliasId, OwnedServerName, OwnedUserId, ServerName, UserId}; use tokio::sync::Mutex; use crate::service; @@ -73,7 +71,7 @@ impl crate::Service for Service { jwt_decoding_key, bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())), stateres_mutex: Arc::new(Mutex::new(())), - admin_alias: RoomAliasId::parse(format!("#admins:{}", &config.server_name)) + admin_alias: OwnedRoomAliasId::try_from(format!("#admins:{}", &config.server_name)) .expect("#admins:server_name is valid alias name"), server_user: UserId::parse_with_server_name( String::from("conduit"), diff --git a/src/service/rooms/alias/mod.rs b/src/service/rooms/alias/mod.rs index 9dcf9d8e..0acbb116 100644 --- a/src/service/rooms/alias/mod.rs +++ b/src/service/rooms/alias/mod.rs @@ -129,10 +129,10 @@ impl Service { servers: Option>, ) -> Result<(OwnedRoomId, Vec)> { if room.is_room_id() { - let room_id = RoomId::parse(room).expect("valid RoomId"); - Ok((room_id, servers.unwrap_or_default())) + let room_id: &RoomId = room.try_into().expect("valid RoomId"); + Ok((room_id.to_owned(), servers.unwrap_or_default())) } else { - let alias = &RoomAliasId::parse(room).expect("valid RoomAliasId"); + let alias: &RoomAliasId = room.try_into().expect("valid RoomAliasId"); self.resolve_alias(alias, servers).await } } diff --git a/src/service/rooms/event_handler/parse_incoming_pdu.rs b/src/service/rooms/event_handler/parse_incoming_pdu.rs index f3c75f36..0c11314d 100644 --- a/src/service/rooms/event_handler/parse_incoming_pdu.rs +++ b/src/service/rooms/event_handler/parse_incoming_pdu.rs @@ -1,5 +1,5 @@ use conduwuit::{err, implement, pdu::gen_event_id_canonical_json, result::FlatOk, Result}; -use ruma::{CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, RoomId}; +use ruma::{CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId}; use serde_json::value::RawValue as RawJsonValue; #[implement(super::Service)] @@ -14,7 +14,7 @@ pub async fn parse_incoming_pdu( let room_id: OwnedRoomId = value .get("room_id") .and_then(CanonicalJsonValue::as_str) - .map(RoomId::parse) + .map(OwnedRoomId::parse) .flat_ok_or(err!(Request(InvalidParam("Invalid room_id in pdu"))))?; let room_version_id = self diff --git a/src/service/rooms/state/mod.rs b/src/service/rooms/state/mod.rs index a7f79e94..2769beb8 100644 --- a/src/service/rooms/state/mod.rs +++ b/src/service/rooms/state/mod.rs @@ -139,7 +139,7 @@ impl Service { .state_cache .update_membership( room_id, - &user_id, + user_id, membership_event, &pdu.sender, None, diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index a2f1ab1b..81df7b35 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -35,7 +35,7 @@ use ruma::{ push::{Action, Ruleset, Tweak}, state_res::{self, Event, RoomVersion}, uint, user_id, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId, - OwnedServerName, RoomId, RoomVersionId, ServerName, UserId, + OwnedServerName, OwnedUserId, RoomId, RoomVersionId, ServerName, UserId, }; use serde::Deserialize; use serde_json::value::{to_raw_value, RawValue as RawJsonValue}; @@ -424,7 +424,7 @@ impl Service { if pdu.kind == TimelineEventType::RoomMember { if let Some(state_key) = &pdu.state_key { - let target_user_id = UserId::parse(state_key.clone())?; + let target_user_id = OwnedUserId::parse(state_key)?; if self.services.users.is_active_local(&target_user_id).await { push_target.insert(target_user_id); @@ -534,7 +534,7 @@ impl Service { | TimelineEventType::RoomMember => { if let Some(state_key) = &pdu.state_key { // if the state_key fails - let target_user_id = UserId::parse(state_key.clone()) + let target_user_id = UserId::parse(state_key) .expect("This state_key was previously validated"); let content: RoomMemberEventContent = pdu.get_content()?; @@ -550,7 +550,7 @@ impl Service { .state_cache .update_membership( &pdu.room_id, - &target_user_id, + target_user_id, content, &pdu.sender, invite_state, @@ -627,7 +627,7 @@ impl Service { .and_then(|state_key| UserId::parse(state_key.as_str()).ok()) { let appservice_uid = appservice.registration.sender_localpart.as_str(); - if state_key_uid == appservice_uid { + if state_key_uid == &appservice_uid { self.services .sending .send_pdu_appservice(appservice.registration.id.clone(), pdu_id)?; diff --git a/src/service/sending/data.rs b/src/service/sending/data.rs index a699b8ee..436f633e 100644 --- a/src/service/sending/data.rs +++ b/src/service/sending/data.rs @@ -7,7 +7,7 @@ use conduwuit::{ }; use database::{Database, Deserialized, Map}; use futures::{Stream, StreamExt}; -use ruma::{ServerName, UserId}; +use ruma::{OwnedServerName, ServerName, UserId}; use super::{Destination, SendingEvent}; use crate::{globals, Dep}; @@ -209,7 +209,7 @@ fn parse_servercurrentevent(key: &[u8], value: &[u8]) -> Result<(Destination, Se let mut parts = key[1..].splitn(3, |&b| b == 0xFF); let user = parts.next().expect("splitn always returns one element"); - let user_string = utils::string_from_bytes(user) + let user_string = utils::str_from_bytes(user) .map_err(|_| Error::bad_database("Invalid user string in servercurrentevent"))?; let user_id = UserId::parse(user_string) .map_err(|_| Error::bad_database("Invalid user id in servercurrentevent"))?; @@ -225,7 +225,7 @@ fn parse_servercurrentevent(key: &[u8], value: &[u8]) -> Result<(Destination, Se .ok_or_else(|| Error::bad_database("Invalid bytes in servercurrentpdus."))?; ( - Destination::Push(user_id, pushkey_string), + Destination::Push(user_id.to_owned(), pushkey_string), if value.is_empty() { SendingEvent::Pdu(event.into()) } else { @@ -246,7 +246,7 @@ fn parse_servercurrentevent(key: &[u8], value: &[u8]) -> Result<(Destination, Se })?; ( - Destination::Federation(ServerName::parse(server).map_err(|_| { + Destination::Federation(OwnedServerName::parse(&server).map_err(|_| { Error::bad_database("Invalid server string in server_currenttransaction") })?), if value.is_empty() { diff --git a/src/service/sending/sender.rs b/src/service/sending/sender.rs index 339236a5..bf4ebafb 100644 --- a/src/service/sending/sender.rs +++ b/src/service/sending/sender.rs @@ -883,7 +883,7 @@ impl Service { .get("room_id") .and_then(|val| RoomId::parse(val.as_str()?).ok()) { - match self.services.state.get_room_version(&room_id).await { + match self.services.state.get_room_version(room_id).await { | Ok(room_version_id) => match room_version_id { | RoomVersionId::V1 | RoomVersionId::V2 => {}, | _ => _ = pdu_json.remove("event_id"), diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index 1d7f4248..fe064d9c 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -937,7 +937,7 @@ impl Service { let user_string = utils::string_from_bytes(user_bytes) .map_err(|e| err!(Database("User ID in openid_userid is invalid unicode. {e}")))?; - UserId::parse(user_string) + OwnedUserId::try_from(user_string) .map_err(|e| err!(Database("User ID in openid_userid is invalid. {e}"))) }