diff --git a/src/api/client/membership/invite.rs b/src/api/client/membership/invite.rs index 78cd4289f..1c124b5be 100644 --- a/src/api/client/membership/invite.rs +++ b/src/api/client/membership/invite.rs @@ -77,25 +77,27 @@ pub(crate) async fn invite_user_route( } } - match recipient_filter_level { - | FilterLevel::Allow => { - invite_helper( - &services, - sender_user, - recipient_user, - &body.room_id, - body.reason.clone(), - false, - ) - .boxed() - .await?; - - Ok(invite_user::v3::Response {}) - }, - | FilterLevel::Ignore => Ok(invite_user::v3::Response {}), - | FilterLevel::Block => - Err!(Request(InviteBlocked("{recipient_user} has blocked invites from you."))), + // return an error for blocked invites. ignored invites aren't handled here + // since the recipient's membership should still be changed to `invite`. + // they're filtered out in api::client::message::is_ignored_pdu + if matches!(recipient_filter_level, FilterLevel::Block) { + return Err!(Request(InviteBlocked( + "{recipient_user} has blocked invites from you." + ))); } + + invite_helper( + &services, + sender_user, + recipient_user, + &body.room_id, + body.reason.clone(), + false, + ) + .boxed() + .await?; + + Ok(invite_user::v3::Response {}) }, | _ => { Err!(Request(NotFound("User not found."))) diff --git a/src/api/client/room/create.rs b/src/api/client/room/create.rs index 597213256..fb9492906 100644 --- a/src/api/client/room/create.rs +++ b/src/api/client/room/create.rs @@ -115,22 +115,25 @@ pub(crate) async fn create_room_route( // drop invites if the creator has them blocked continue; } - match services - .users - .invite_filter_level(sender_user, recipient_user) - .await - { - | FilterLevel::Allow => { - invitees.insert(recipient_user.clone()); - }, - | FilterLevel::Ignore => { - continue; - }, - | FilterLevel::Block => - return Err!(Request(InviteBlocked( - "{recipient_user} has blocked invites from you." - ))), + + // if the recipient of the invite is local and has the sender blocked, error + // out. if the recipient is remote we can't tell yet, and if they're local and + // have the sender _ignored_ their invite will be filtered out in + // api::client::message::is_ignored_pdu + if services.globals.user_is_local(recipient_user) + && matches!( + services + .users + .invite_filter_level(sender_user, recipient_user) + .await, + FilterLevel::Block + ) { + return Err!(Request(InviteBlocked( + "{recipient_user} has blocked invites from you." + ))); } + + invitees.insert(recipient_user.clone()); } let _short_id = services diff --git a/src/service/rooms/state_cache/update.rs b/src/service/rooms/state_cache/update.rs index a1ff145d3..6ecc9e54c 100644 --- a/src/service/rooms/state_cache/update.rs +++ b/src/service/rooms/state_cache/update.rs @@ -122,24 +122,20 @@ pub async fn update_membership( self.mark_as_joined(user_id, room_id); }, | MembershipState::Invite => { - match self - .services - .users - .invite_filter_level(sender, user_id) - .await - { - | FilterLevel::Allow => { - self.mark_as_invited(user_id, room_id, last_state, invite_via) - .await; - }, - | FilterLevel::Ignore => { - // do nothing - }, - | FilterLevel::Block => - return Err!(Request(InviteBlocked( - "{user_id} has blocked invites from you." - ))), + // return an error for blocked invites. ignored invites aren't handled here + // since the recipient's membership should still be changed to `invite`. + // they're filtered out in api::client::message::is_ignored_pdu + if matches!( + self.services + .users + .invite_filter_level(sender, user_id) + .await, + FilterLevel::Block + ) { + return Err!(Request(InviteBlocked("{user_id} has blocked invites from you."))); } + self.mark_as_invited(user_id, room_id, last_state, invite_via) + .await; }, | MembershipState::Leave | MembershipState::Ban => { self.mark_as_left(user_id, room_id);