From a6da294c553839d1689ef6568afd213e0b61a59c Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Mon, 1 Jul 2024 15:12:44 +0100 Subject: [PATCH] refactor: remove unecessery async --- src/api/client_server/membership.rs | 1 - src/api/server_server.rs | 28 +++++++++---------------- src/service/rooms/state_accessor/mod.rs | 2 +- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 5c0169d2..9d09270e 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -907,7 +907,6 @@ async fn join_room_by_id_helper( .rooms .state_accessor .user_can_invite(room_id, &user, sender_user, &state_lock) - .await .unwrap_or(false) { auth_user = Some(user); diff --git a/src/api/server_server.rs b/src/api/server_server.rs index 7af4bdef..2fe90e0e 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -1533,7 +1533,7 @@ pub async fn create_join_event_template_route( }) .transpose()?; - let join_authorized_via_users_server = || async { + let join_authorized_via_users_server = || { let join_rules_event_content = join_rules_event_content?; if !services() @@ -1578,28 +1578,20 @@ pub async fn create_join_event_template_route( .unwrap_or(false) }) { - let members: Vec<_> = services() + let auth_user = services() .rooms .state_cache .room_members(&body.room_id) .filter_map(Result::ok) .filter(|user| user.server_name() == services().globals.server_name()) - .collect(); + .find(|user| { + services() + .rooms + .state_accessor + .user_can_invite(&body.room_id, user, &body.user_id, &state_lock) + .unwrap_or(false) + }); - let mut auth_user = None; - - for user in members { - if services() - .rooms - .state_accessor - .user_can_invite(&body.room_id, &user, &body.user_id, &state_lock) - .await - .unwrap_or(false) - { - auth_user = Some(user); - break; - } - } if auth_user.is_some() { Ok(auth_user).transpose() } else { @@ -1616,7 +1608,7 @@ pub async fn create_join_event_template_route( } }; - let join_authorized_via_users_server = join_authorized_via_users_server().await.transpose()?; + let join_authorized_via_users_server = join_authorized_via_users_server().transpose()?; let room_version_id = services().rooms.state.get_room_version(&body.room_id)?; if !body.ver.contains(&room_version_id) { diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index aa654aee..4eb33419 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -305,7 +305,7 @@ impl Service { }) } - pub async fn user_can_invite( + pub fn user_can_invite( &self, room_id: &RoomId, sender: &UserId,