From a2ac491c5460da736c8872747aa3417a65c81a4e Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 25 Nov 2023 12:42:05 -0500 Subject: [PATCH 01/10] bump ruma, add wrong room keys error code, tiny logging change can't update ruma to very latest commit because of the weird JsOption thing for syncv4 that i can't wrap my head around how to use, not important anyways Signed-off-by: strawberry --- Cargo.toml | 5 ++++- src/api/client_server/membership.rs | 6 +++--- src/api/client_server/room.rs | 2 +- src/service/admin/mod.rs | 2 +- src/service/rooms/spaces/mod.rs | 6 +++--- src/service/rooms/state_accessor/mod.rs | 10 ++++++++-- src/utils/error.rs | 8 +++++--- 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c00d56a9..0fa69147 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ tower-http = { version = "0.4.1", features = ["add-extension", "cors", "sensitiv # Used for matrix spec type definitions and helpers #ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } -ruma = { git = "https://github.com/ruma/ruma", rev = "b4853aa8fa5e3a24e3689fc88044de9915f6ab67", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } +ruma = { git = "https://github.com/ruma/ruma", rev = "5446ea979b314b90da1734f20efaff443d64f73d", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "4ec9c69bb7e09391add2382b3ebac97b6e8f4c64", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } @@ -116,6 +116,9 @@ async-trait = "0.1.68" sd-notify = { version = "0.4.1", optional = true } +# stupid ruma using JsOption instead of Option +js_option = "0.1" + [target.'cfg(unix)'.dependencies] nix = { version = "0.26.2", features = ["resource"] } diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index ed59691d..09f70a03 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -64,7 +64,7 @@ pub async fn join_room_by_id_route( .map(|user| user.server_name().to_owned()), ); - servers.push(body.room_id.server_name().to_owned()); + servers.push(body.room_id.server_name().unwrap().into()); join_room_by_id_helper( body.sender_user.as_deref(), @@ -105,7 +105,7 @@ pub async fn join_room_by_id_or_alias_route( .map(|user| user.server_name().to_owned()), ); - servers.push(room_id.server_name().to_owned()); + servers.push(room_id.server_name().unwrap().into()); (servers, room_id) } @@ -1366,7 +1366,7 @@ pub async fn leave_all_rooms(user_id: &UserId) -> Result<()> { pub async fn leave_room(user_id: &UserId, room_id: &RoomId, reason: Option) -> Result<()> { // Ask a remote server if we don't have this room if !services().rooms.metadata.exists(room_id)? - && room_id.server_name() != services().globals.server_name() + && room_id.server_name() != Some(services().globals.server_name()) { if let Err(e) = remote_leave_room(user_id, room_id).await { warn!("Failed to leave room {} remotely: {}", user_id, e); diff --git a/src/api/client_server/room.rs b/src/api/client_server/room.rs index 0e2d9326..20409a28 100644 --- a/src/api/client_server/room.rs +++ b/src/api/client_server/room.rs @@ -366,7 +366,7 @@ pub async fn create_room_route( services().rooms.timeline.build_and_append_pdu( PduBuilder { event_type: TimelineEventType::RoomName, - content: to_raw_value(&RoomNameEventContent::new(Some(name.clone()))) + content: to_raw_value(&RoomNameEventContent::new(name.clone())) .expect("event is valid, we just created it"), unsigned: None, state_key: Some("".to_owned()), diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 64958fc7..bd682550 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -1051,7 +1051,7 @@ impl Service { services().rooms.timeline.build_and_append_pdu( PduBuilder { event_type: TimelineEventType::RoomName, - content: to_raw_value(&RoomNameEventContent::new(Some(room_name))) + content: to_raw_value(&RoomNameEventContent::new(room_name)) .expect("event is valid, we just created it"), unsigned: None, state_key: Some("".to_owned()), diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index 615e9ca0..0e84221f 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -134,7 +134,7 @@ impl Service { if serde_json::from_str::(pdu.content.get()) .ok() - .and_then(|c| c.via) + .and_then(|c| Some(c.via)) .map_or(true, |v| v.is_empty()) { continue; @@ -185,7 +185,7 @@ impl Service { stack.push(children_ids); } } else { - let server = current_room.server_name(); + let server = current_room.server_name().unwrap(); if server == services().globals.server_name() { continue; } @@ -193,7 +193,7 @@ impl Service { // Early return so the client can see some data already break; } - warn!("Asking {server} for /hierarchy"); + debug!("Asking {server} for /hierarchy"); if let Ok(response) = services() .sending .send_federation_request( diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index b00dc58c..14c3bae7 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -279,8 +279,14 @@ impl Service { .room_state_get(room_id, &StateEventType::RoomName, "")? .map_or(Ok(None), |s| { serde_json::from_str(s.content.get()) - .map(|c: RoomNameEventContent| c.name) - .map_err(|_| Error::bad_database("Invalid room name event in database.")) + .map(|c: RoomNameEventContent| Some(c.name)) + .map_err(|e| { + error!( + "Invalid room name event in database for room {}. {}", + room_id, e + ); + Error::bad_database("Invalid room name event in database.") + }) }) } diff --git a/src/utils/error.rs b/src/utils/error.rs index 6e88cf59..765a31bb 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -116,9 +116,11 @@ impl Error { Self::BadRequest(kind, _) => ( kind.clone(), match kind { - Forbidden | GuestAccessForbidden | ThreepidAuthFailed | ThreepidDenied => { - StatusCode::FORBIDDEN - } + WrongRoomKeysVersion { .. } + | Forbidden + | GuestAccessForbidden + | ThreepidAuthFailed + | ThreepidDenied => StatusCode::FORBIDDEN, Unauthorized | UnknownToken { .. } | MissingToken => StatusCode::UNAUTHORIZED, NotFound | Unrecognized => StatusCode::NOT_FOUND, LimitExceeded { .. } => StatusCode::TOO_MANY_REQUESTS, From 6dcc8b6cf1dd8554c54e435132ee90a9a7353ca8 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 7 Jan 2024 21:21:13 -0500 Subject: [PATCH 02/10] bump ruma to latest commit (syncv3 JsOption and push optional power levels) Signed-off-by: strawberry --- Cargo.toml | 2 +- src/api/client_server/sync.rs | 18 ++++++++++++++---- src/service/pusher/mod.rs | 12 ++++++++---- src/service/rooms/state_accessor/mod.rs | 5 +++-- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0fa69147..03f0cd6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ tower-http = { version = "0.4.1", features = ["add-extension", "cors", "sensitiv # Used for matrix spec type definitions and helpers #ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } -ruma = { git = "https://github.com/ruma/ruma", rev = "5446ea979b314b90da1734f20efaff443d64f73d", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } +ruma = { git = "https://github.com/ruma/ruma", rev = "9a5142052c808275f47613d4b66cb6c9fc286079", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "4ec9c69bb7e09391add2382b3ebac97b6e8f4c64", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 57572284..5e675297 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -1614,12 +1614,22 @@ pub async fn sync_events_v4_route( rooms.insert( room_id.clone(), sync_events::v4::SlidingSyncRoom { - name: services().rooms.state_accessor.get_name(room_id)?.or(name), - avatar: services() + name: services() .rooms .state_accessor - .get_avatar(room_id)? - .map_or(avatar, |a| a.url), + .get_name(room_id)? + .or_else(|| name), + avatar: if let Some(avatar) = avatar { + ruma::JsOption::Some(avatar) + } else { + match services().rooms.state_accessor.get_avatar(room_id)? { + ruma::JsOption::Some(avatar) => { + js_option::JsOption::Some(avatar.url.unwrap()) + } + ruma::JsOption::Null => ruma::JsOption::Null, + ruma::JsOption::Undefined => ruma::JsOption::Undefined, + } + }, initial: Some(roomsince == &0), is_dm: None, invite_state: None, diff --git a/src/service/pusher/mod.rs b/src/service/pusher/mod.rs index 315c5ef0..418b7a8f 100644 --- a/src/service/pusher/mod.rs +++ b/src/service/pusher/mod.rs @@ -1,6 +1,6 @@ mod data; pub use data::Data; -use ruma::events::AnySyncTimelineEvent; +use ruma::{events::AnySyncTimelineEvent, push::PushConditionPowerLevelsCtx}; use crate::{services, Error, PduEvent, Result}; use bytes::BytesMut; @@ -193,6 +193,12 @@ impl Service { pdu: &Raw, room_id: &RoomId, ) -> Result<&'a [Action]> { + let power_levels = PushConditionPowerLevelsCtx { + users: power_levels.users.clone(), + users_default: power_levels.users_default, + notifications: power_levels.notifications.clone(), + }; + let ctx = PushConditionRoomCtx { room_id: room_id.to_owned(), member_count: 10_u32.into(), // TODO: get member count efficiently @@ -201,9 +207,7 @@ impl Service { .users .displayname(user)? .unwrap_or_else(|| user.localpart().to_owned()), - users_power_levels: power_levels.users.clone(), - default_power_level: power_levels.users_default, - notification_power_levels: power_levels.notifications.clone(), + power_levels: Some(power_levels), }; Ok(ruleset.get_actions(pdu, &ctx)) diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index 14c3bae7..f49d8a3c 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -5,6 +5,7 @@ use std::{ }; pub use data::Data; +use js_option::JsOption; use lru_cache::LruCache; use ruma::{ events::{ @@ -290,12 +291,12 @@ impl Service { }) } - pub fn get_avatar(&self, room_id: &RoomId) -> Result> { + pub fn get_avatar(&self, room_id: &RoomId) -> Result> { services() .rooms .state_accessor .room_state_get(room_id, &StateEventType::RoomAvatar, "")? - .map_or(Ok(None), |s| { + .map_or(Ok(JsOption::Undefined), |s| { serde_json::from_str(s.content.get()) .map_err(|_| Error::bad_database("Invalid room avatar event in database.")) }) From e7070843456bf259e395b98c60f9b185eb75e86b Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Fri, 16 Feb 2024 20:52:07 +0000 Subject: [PATCH 03/10] chore: bump ruma to latest commit (as of 2024-02-16) --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 03f0cd6f..0cf062f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ tower-http = { version = "0.4.1", features = ["add-extension", "cors", "sensitiv # Used for matrix spec type definitions and helpers #ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } -ruma = { git = "https://github.com/ruma/ruma", rev = "9a5142052c808275f47613d4b66cb6c9fc286079", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } +ruma = { git = "https://github.com/ruma/ruma", rev = "f1a8497ecb0cc24b0159f301336a3bf3896d476e", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "4ec9c69bb7e09391add2382b3ebac97b6e8f4c64", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } From d841b81c56ab24210e966201258c6f7b9438340a Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Fri, 16 Feb 2024 20:52:19 +0000 Subject: [PATCH 04/10] chore: update Cargo.lock --- Cargo.lock | 79 +++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 94a0c5e3..fc17fda3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -387,6 +387,7 @@ dependencies = [ "http", "hyper", "image", + "js_option", "jsonwebtoken", "lazy_static", "lru-cache", @@ -708,7 +709,7 @@ dependencies = [ "atomic", "pear", "serde", - "toml 0.8.8", + "toml", "uncased", "version_check", ] @@ -1802,12 +1803,11 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.3.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" dependencies = [ - "once_cell", - "toml_edit 0.19.15", + "toml_edit 0.20.7", ] [[package]] @@ -2018,8 +2018,8 @@ dependencies = [ [[package]] name = "ruma" -version = "0.8.2" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.9.4" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ "assign", "js_int", @@ -2037,8 +2037,8 @@ dependencies = [ [[package]] name = "ruma-appservice-api" -version = "0.8.1" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.9.0" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ "js_int", "ruma-common", @@ -2049,9 +2049,10 @@ dependencies = [ [[package]] name = "ruma-client-api" -version = "0.16.2" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.17.4" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ + "as_variant", "assign", "bytes", "http", @@ -2067,8 +2068,8 @@ dependencies = [ [[package]] name = "ruma-common" -version = "0.11.3" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.12.1" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ "as_variant", "base64", @@ -2095,8 +2096,8 @@ dependencies = [ [[package]] name = "ruma-events" -version = "0.26.0" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.27.11" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ "as_variant", "indexmap 2.2.1", @@ -2117,8 +2118,8 @@ dependencies = [ [[package]] name = "ruma-federation-api" -version = "0.7.1" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.8.0" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ "js_int", "ruma-common", @@ -2129,8 +2130,8 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" -version = "0.9.1" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.9.3" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ "js_int", "thiserror", @@ -2138,8 +2139,8 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" -version = "0.7.1" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.8.0" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ "js_int", "ruma-common", @@ -2148,8 +2149,8 @@ dependencies = [ [[package]] name = "ruma-macros" -version = "0.11.3" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.12.0" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ "once_cell", "proc-macro-crate", @@ -2158,13 +2159,13 @@ dependencies = [ "ruma-identifiers-validation", "serde", "syn 2.0.48", - "toml 0.7.8", + "toml", ] [[package]] name = "ruma-push-gateway-api" -version = "0.7.1" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.8.0" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ "js_int", "ruma-common", @@ -2175,8 +2176,8 @@ dependencies = [ [[package]] name = "ruma-signatures" -version = "0.13.1" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.14.0" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ "base64", "ed25519-dalek", @@ -2191,8 +2192,8 @@ dependencies = [ [[package]] name = "ruma-state-res" -version = "0.9.1" -source = "git+https://github.com/ruma/ruma?rev=b4853aa8fa5e3a24e3689fc88044de9915f6ab67#b4853aa8fa5e3a24e3689fc88044de9915f6ab67" +version = "0.10.0" +source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" dependencies = [ "itertools", "js_int", @@ -2846,18 +2847,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "toml" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit 0.19.15", -] - [[package]] name = "toml" version = "0.8.8" @@ -2881,13 +2870,11 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.19.15" +version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" dependencies = [ "indexmap 2.2.1", - "serde", - "serde_spanned", "toml_datetime", "winnow", ] From 4c06f329c4d2f5128d6293de9bb0342559422746 Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Fri, 16 Feb 2024 21:13:59 +0000 Subject: [PATCH 05/10] refactor: appease clippy --- src/api/client_server/sync.rs | 2 +- src/service/rooms/event_handler/mod.rs | 13 ++++++++++--- src/service/rooms/spaces/mod.rs | 3 +-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 5e675297..490a947b 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -1618,7 +1618,7 @@ pub async fn sync_events_v4_route( .rooms .state_accessor .get_name(room_id)? - .or_else(|| name), + .or(name), avatar: if let Some(avatar) = avatar { ruma::JsOption::Some(avatar) } else { diff --git a/src/service/rooms/event_handler/mod.rs b/src/service/rooms/event_handler/mod.rs index e7db6f78..375d1ff0 100644 --- a/src/service/rooms/event_handler/mod.rs +++ b/src/service/rooms/event_handler/mod.rs @@ -966,14 +966,21 @@ impl Service { debug!("Resolving state"); - let lock = services().globals.stateres_mutex.lock(); - let state = match state_res::resolve(room_version_id, &fork_states, auth_chain_sets, |id| { + let fetch_event = |id: &_| { let res = services().rooms.timeline.get_pdu(id); if let Err(e) = &res { error!("LOOK AT ME Failed to fetch event: {}", e); } res.ok().flatten() - }) { + }; + + let lock = services().globals.stateres_mutex.lock(); + let state = match state_res::resolve( + room_version_id, + &fork_states, + auth_chain_sets, + fetch_event, + ) { Ok(new_state) => new_state, Err(_) => { return Err(Error::bad_database("State resolution failed, either an event could not be found or deserialization")); diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index 0e84221f..90523667 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -133,8 +133,7 @@ impl Service { .ok_or_else(|| Error::bad_database("Event in space state not found"))?; if serde_json::from_str::(pdu.content.get()) - .ok() - .and_then(|c| Some(c.via)) + .ok().map(|c| c.via) .map_or(true, |v| v.is_empty()) { continue; From 976a73a0e5e9aa7fc880a39f6478ec13943e2d3c Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Fri, 16 Feb 2024 21:19:40 +0000 Subject: [PATCH 06/10] style: appease rustfmt --- src/api/client_server/sync.rs | 6 +----- src/service/rooms/spaces/mod.rs | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 490a947b..86b3b248 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -1614,11 +1614,7 @@ pub async fn sync_events_v4_route( rooms.insert( room_id.clone(), sync_events::v4::SlidingSyncRoom { - name: services() - .rooms - .state_accessor - .get_name(room_id)? - .or(name), + name: services().rooms.state_accessor.get_name(room_id)?.or(name), avatar: if let Some(avatar) = avatar { ruma::JsOption::Some(avatar) } else { diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index 90523667..07d576a9 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -133,7 +133,8 @@ impl Service { .ok_or_else(|| Error::bad_database("Event in space state not found"))?; if serde_json::from_str::(pdu.content.get()) - .ok().map(|c| c.via) + .ok() + .map(|c| c.via) .map_or(true, |v| v.is_empty()) { continue; From ace9637bc299df4c59efbeb3e1c432b239b7a165 Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Fri, 23 Feb 2024 19:39:30 +0000 Subject: [PATCH 07/10] replace unwraps with expects --- src/api/client_server/membership.rs | 14 ++++++++++++-- src/api/client_server/sync.rs | 2 +- src/service/rooms/spaces/mod.rs | 4 +++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 09f70a03..5c78a1c2 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -64,7 +64,12 @@ pub async fn join_room_by_id_route( .map(|user| user.server_name().to_owned()), ); - servers.push(body.room_id.server_name().unwrap().into()); + servers.push( + body.room_id + .server_name() + .expect("Room IDs should always have a server name") + .into(), + ); join_room_by_id_helper( body.sender_user.as_deref(), @@ -105,7 +110,12 @@ pub async fn join_room_by_id_or_alias_route( .map(|user| user.server_name().to_owned()), ); - servers.push(room_id.server_name().unwrap().into()); + servers.push( + room_id + .server_name() + .expect("Room IDs should always have a server name") + .into(), + ); (servers, room_id) } diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 86b3b248..600a9737 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -1620,7 +1620,7 @@ pub async fn sync_events_v4_route( } else { match services().rooms.state_accessor.get_avatar(room_id)? { ruma::JsOption::Some(avatar) => { - js_option::JsOption::Some(avatar.url.unwrap()) + js_option::JsOption::from_option(avatar.url) } ruma::JsOption::Null => ruma::JsOption::Null, ruma::JsOption::Undefined => ruma::JsOption::Undefined, diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index 07d576a9..b0a9ed2a 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -185,7 +185,9 @@ impl Service { stack.push(children_ids); } } else { - let server = current_room.server_name().unwrap(); + let server = current_room + .server_name() + .expect("Room IDs should always have a server name"); if server == services().globals.server_name() { continue; } From 8aa915acb90552398530cc20efa1c71f788da9f6 Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Fri, 23 Feb 2024 20:29:17 +0000 Subject: [PATCH 08/10] bump ruma, support deprecated user login field --- Cargo.lock | 24 ++++++++--------- Cargo.toml | 2 +- src/api/client_server/session.rs | 45 ++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc17fda3..e20c3f0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2019,7 +2019,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.9.4" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "assign", "js_int", @@ -2038,7 +2038,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.9.0" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "js_int", "ruma-common", @@ -2050,7 +2050,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.17.4" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "as_variant", "assign", @@ -2069,7 +2069,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.12.1" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "as_variant", "base64", @@ -2097,7 +2097,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.27.11" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "as_variant", "indexmap 2.2.1", @@ -2119,7 +2119,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.8.0" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "js_int", "ruma-common", @@ -2131,7 +2131,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.3" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "js_int", "thiserror", @@ -2140,7 +2140,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.8.0" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "js_int", "ruma-common", @@ -2150,7 +2150,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.12.0" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "once_cell", "proc-macro-crate", @@ -2165,7 +2165,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.8.0" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "js_int", "ruma-common", @@ -2177,7 +2177,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.14.0" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "base64", "ed25519-dalek", @@ -2193,7 +2193,7 @@ dependencies = [ [[package]] name = "ruma-state-res" version = "0.10.0" -source = "git+https://github.com/ruma/ruma?rev=f1a8497ecb0cc24b0159f301336a3bf3896d476e#f1a8497ecb0cc24b0159f301336a3bf3896d476e" +source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" dependencies = [ "itertools", "js_int", diff --git a/Cargo.toml b/Cargo.toml index 0cf062f6..4bc9ad5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ tower-http = { version = "0.4.1", features = ["add-extension", "cors", "sensitiv # Used for matrix spec type definitions and helpers #ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } -ruma = { git = "https://github.com/ruma/ruma", rev = "f1a8497ecb0cc24b0159f301336a3bf3896d476e", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } +ruma = { git = "https://github.com/ruma/ruma", rev = "abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "4ec9c69bb7e09391add2382b3ebac97b6e8f4c64", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } diff --git a/src/api/client_server/session.rs b/src/api/client_server/session.rs index c17bd99b..23f0b457 100644 --- a/src/api/client_server/session.rs +++ b/src/api/client_server/session.rs @@ -42,24 +42,31 @@ pub async fn get_login_types_route( /// Note: You can use [`GET /_matrix/client/r0/login`](fn.get_supported_versions_route.html) to see /// supported login types. pub async fn login_route(body: Ruma) -> Result { + // To allow deprecated login methods + #![allow(deprecated)] // Validate login method // TODO: Other login methods let user_id = match &body.login_info { login::v3::LoginInfo::Password(login::v3::Password { identifier, password, + user, + address: _, + medium: _, }) => { - let username = if let UserIdentifier::UserIdOrLocalpart(user_id) = identifier { - user_id.to_lowercase() + let user_id = if let Some(UserIdentifier::UserIdOrLocalpart(user_id)) = identifier { + UserId::parse_with_server_name( + user_id.to_lowercase(), + services().globals.server_name(), + ) + } else if let Some(user) = user { + UserId::parse(user) } else { warn!("Bad login type: {:?}", &body.login_info); return Err(Error::BadRequest(ErrorKind::Forbidden, "Bad login type.")); - }; - let user_id = - UserId::parse_with_server_name(username, services().globals.server_name()) - .map_err(|_| { - Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid.") - })?; + } + .map_err(|_| Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))?; + let hash = services() .users .password_hash(&user_id)? @@ -105,22 +112,28 @@ pub async fn login_route(body: Ruma) -> Result { + login::v3::LoginInfo::ApplicationService(login::v3::ApplicationService { + identifier, + user, + }) => { if !body.from_appservice { return Err(Error::BadRequest( ErrorKind::Forbidden, "Forbidden login type.", )); }; - let username = if let UserIdentifier::UserIdOrLocalpart(user_id) = identifier { - user_id.to_lowercase() + if let Some(UserIdentifier::UserIdOrLocalpart(user_id)) = identifier { + UserId::parse_with_server_name( + user_id.to_lowercase(), + services().globals.server_name(), + ) + } else if let Some(user) = user { + UserId::parse(user) } else { + warn!("Bad login type: {:?}", &body.login_info); return Err(Error::BadRequest(ErrorKind::Forbidden, "Bad login type.")); - }; - - UserId::parse_with_server_name(username, services().globals.server_name()).map_err( - |_| Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."), - )? + } + .map_err(|_| Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))? } _ => { warn!("Unsupported or unknown login type: {:?}", &body.login_info); From b27e9ea95cdddce51eca99f0fd003de131c23556 Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Sun, 25 Feb 2024 08:49:20 +0000 Subject: [PATCH 09/10] chore: bump ruma to latest commit (as of 2024-02-25) --- Cargo.lock | 24 ++++++++++++------------ Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e20c3f0b..78e85266 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2019,7 +2019,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.9.4" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "assign", "js_int", @@ -2038,7 +2038,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.9.0" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "js_int", "ruma-common", @@ -2050,7 +2050,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.17.4" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "as_variant", "assign", @@ -2069,7 +2069,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.12.1" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "as_variant", "base64", @@ -2097,7 +2097,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.27.11" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "as_variant", "indexmap 2.2.1", @@ -2119,7 +2119,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.8.0" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "js_int", "ruma-common", @@ -2131,7 +2131,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.3" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "js_int", "thiserror", @@ -2140,7 +2140,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.8.0" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "js_int", "ruma-common", @@ -2150,7 +2150,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.12.0" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "once_cell", "proc-macro-crate", @@ -2165,7 +2165,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.8.0" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "js_int", "ruma-common", @@ -2177,7 +2177,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.14.0" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "base64", "ed25519-dalek", @@ -2193,7 +2193,7 @@ dependencies = [ [[package]] name = "ruma-state-res" version = "0.10.0" -source = "git+https://github.com/ruma/ruma?rev=abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3#abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3" +source = "git+https://github.com/ruma/ruma?rev=1a1c61ee1e8f0936e956a3b69c931ce12ee28475#1a1c61ee1e8f0936e956a3b69c931ce12ee28475" dependencies = [ "itertools", "js_int", diff --git a/Cargo.toml b/Cargo.toml index 4bc9ad5a..4f873cff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ tower-http = { version = "0.4.1", features = ["add-extension", "cors", "sensitiv # Used for matrix spec type definitions and helpers #ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } -ruma = { git = "https://github.com/ruma/ruma", rev = "abebde0cf1cbf3eb1cf8295b240c5d3f926da3a3", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } +ruma = { git = "https://github.com/ruma/ruma", rev = "1a1c61ee1e8f0936e956a3b69c931ce12ee28475", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "4ec9c69bb7e09391add2382b3ebac97b6e8f4c64", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } From 21a5fa3ef0ccb1ad9ae9ea6328146e6dd69e4d78 Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Sun, 25 Feb 2024 10:30:30 +0000 Subject: [PATCH 10/10] refactor: use re-exported JsOption from ruma rather than directly adding it as a dependency --- Cargo.lock | 1 - Cargo.toml | 3 --- src/api/client_server/sync.rs | 12 +++++------- src/service/rooms/state_accessor/mod.rs | 3 +-- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 78e85266..e99928e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -387,7 +387,6 @@ dependencies = [ "http", "hyper", "image", - "js_option", "jsonwebtoken", "lazy_static", "lru-cache", diff --git a/Cargo.toml b/Cargo.toml index 4f873cff..e8c1c8bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,9 +116,6 @@ async-trait = "0.1.68" sd-notify = { version = "0.4.1", optional = true } -# stupid ruma using JsOption instead of Option -js_option = "0.1" - [target.'cfg(unix)'.dependencies] nix = { version = "0.26.2", features = ["resource"] } diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 600a9737..04fdb2bb 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -20,7 +20,7 @@ use ruma::{ StateEventType, TimelineEventType, }, serde::Raw, - uint, DeviceId, OwnedDeviceId, OwnedUserId, RoomId, UInt, UserId, + uint, DeviceId, JsOption, OwnedDeviceId, OwnedUserId, RoomId, UInt, UserId, }; use std::{ collections::{hash_map::Entry, BTreeMap, BTreeSet, HashMap, HashSet}, @@ -1616,14 +1616,12 @@ pub async fn sync_events_v4_route( sync_events::v4::SlidingSyncRoom { name: services().rooms.state_accessor.get_name(room_id)?.or(name), avatar: if let Some(avatar) = avatar { - ruma::JsOption::Some(avatar) + JsOption::Some(avatar) } else { match services().rooms.state_accessor.get_avatar(room_id)? { - ruma::JsOption::Some(avatar) => { - js_option::JsOption::from_option(avatar.url) - } - ruma::JsOption::Null => ruma::JsOption::Null, - ruma::JsOption::Undefined => ruma::JsOption::Undefined, + JsOption::Some(avatar) => JsOption::from_option(avatar.url), + JsOption::Null => JsOption::Null, + JsOption::Undefined => JsOption::Undefined, } }, initial: Some(roomsince == &0), diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index f49d8a3c..903ad47b 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -5,7 +5,6 @@ use std::{ }; pub use data::Data; -use js_option::JsOption; use lru_cache::LruCache; use ruma::{ events::{ @@ -17,7 +16,7 @@ use ruma::{ }, StateEventType, }, - EventId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, + EventId, JsOption, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, }; use tracing::error;