diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs index 6e3bc894..f89903b4 100644 --- a/src/api/client/membership.rs +++ b/src/api/client/membership.rs @@ -364,6 +364,14 @@ pub(crate) async fn invite_user_route( user_id, } = &body.recipient { + if services.users.user_is_ignored(sender_user, user_id).await { + return Err!(Request(Forbidden("You cannot invite users you have ignored to rooms."))); + } else if services.users.user_is_ignored(user_id, sender_user).await { + // silently drop the invite to the recipient if they've been ignored by the + // sender, pretend it worked + return Ok(invite_user::v3::Response {}); + } + invite_helper(&services, sender_user, user_id, &body.room_id, body.reason.clone(), false).await?; Ok(invite_user::v3::Response {}) } else { diff --git a/src/api/client/room.rs b/src/api/client/room.rs index 1edf85d8..0d8e12a2 100644 --- a/src/api/client/room.rs +++ b/src/api/client/room.rs @@ -267,8 +267,16 @@ pub(crate) async fn create_room_route( let mut users = BTreeMap::from_iter([(sender_user.clone(), int!(100))]); if preset == RoomPreset::TrustedPrivateChat { - for invite_ in &body.invite { - users.insert(invite_.clone(), int!(100)); + for invite in &body.invite { + if services.users.user_is_ignored(sender_user, invite).await { + return Err!(Request(Forbidden("You cannot invite users you have ignored to rooms."))); + } else if services.users.user_is_ignored(invite, sender_user).await { + // silently drop the invite to the recipient if they've been ignored by the + // sender, pretend it worked + continue; + } + + users.insert(invite.clone(), int!(100)); } } @@ -476,6 +484,14 @@ pub(crate) async fn create_room_route( // 8. Events implied by invite (and TODO: invite_3pid) drop(state_lock); for user_id in &body.invite { + if services.users.user_is_ignored(sender_user, user_id).await { + return Err!(Request(Forbidden("You cannot invite users you have ignored to rooms."))); + } else if services.users.user_is_ignored(user_id, sender_user).await { + // silently drop the invite to the recipient if they've been ignored by the + // sender, pretend it worked + continue; + } + if let Err(e) = invite_helper(&services, sender_user, user_id, &room_id, None, body.is_direct) .boxed() .await