refactor: remove unecessery async

This commit is contained in:
Matthias Ahouansou 2024-07-01 15:12:44 +01:00
parent 98c7b89fca
commit a6da294c55
No known key found for this signature in database
3 changed files with 11 additions and 20 deletions

View file

@ -907,7 +907,6 @@ async fn join_room_by_id_helper(
.rooms .rooms
.state_accessor .state_accessor
.user_can_invite(room_id, &user, sender_user, &state_lock) .user_can_invite(room_id, &user, sender_user, &state_lock)
.await
.unwrap_or(false) .unwrap_or(false)
{ {
auth_user = Some(user); auth_user = Some(user);

View file

@ -1533,7 +1533,7 @@ pub async fn create_join_event_template_route(
}) })
.transpose()?; .transpose()?;
let join_authorized_via_users_server = || async { let join_authorized_via_users_server = || {
let join_rules_event_content = join_rules_event_content?; let join_rules_event_content = join_rules_event_content?;
if !services() if !services()
@ -1578,28 +1578,20 @@ pub async fn create_join_event_template_route(
.unwrap_or(false) .unwrap_or(false)
}) })
{ {
let members: Vec<_> = services() let auth_user = services()
.rooms .rooms
.state_cache .state_cache
.room_members(&body.room_id) .room_members(&body.room_id)
.filter_map(Result::ok) .filter_map(Result::ok)
.filter(|user| user.server_name() == services().globals.server_name()) .filter(|user| user.server_name() == services().globals.server_name())
.collect(); .find(|user| {
services()
let mut auth_user = None;
for user in members {
if services()
.rooms .rooms
.state_accessor .state_accessor
.user_can_invite(&body.room_id, &user, &body.user_id, &state_lock) .user_can_invite(&body.room_id, user, &body.user_id, &state_lock)
.await
.unwrap_or(false) .unwrap_or(false)
{ });
auth_user = Some(user);
break;
}
}
if auth_user.is_some() { if auth_user.is_some() {
Ok(auth_user).transpose() Ok(auth_user).transpose()
} else { } 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)?; let room_version_id = services().rooms.state.get_room_version(&body.room_id)?;
if !body.ver.contains(&room_version_id) { if !body.ver.contains(&room_version_id) {

View file

@ -305,7 +305,7 @@ impl Service {
}) })
} }
pub async fn user_can_invite( pub fn user_can_invite(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
sender: &UserId, sender: &UserId,