From 172d71e36596e41a22e7caeb720453a96d8e5b4a Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Wed, 3 Apr 2024 18:43:31 -0400 Subject: [PATCH] check if user is joined in the room in `user_can_invite` Signed-off-by: strawberry --- src/service/rooms/state_accessor/mod.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index ce31dd92..59995ba5 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -142,13 +142,17 @@ impl Service { /// Whether a user's power level is sufficient to invite other users pub fn user_can_invite(&self, user_id: &UserId, room_id: &RoomId) -> Result { - self.room_state_get(room_id, &StateEventType::RoomPowerLevels, "")? - .map_or(Ok(false), |pdu_event| { - serde_json::from_str(pdu_event.content.get()).map(|content: RoomPowerLevelsEventContent| { - content.users.get(user_id).unwrap_or(&content.users_default) >= &content.invite + if services().rooms.state_cache.is_joined(user_id, room_id)? { + self.room_state_get(room_id, &StateEventType::RoomPowerLevels, "")? + .map_or(Ok(false), |pdu_event| { + serde_json::from_str(pdu_event.content.get()).map(|content: RoomPowerLevelsEventContent| { + content.users.get(user_id).unwrap_or(&content.users_default) >= &content.invite + }) }) - }) - .map_err(|_| Error::bad_database("Invalid history visibility event in database.")) + .map_err(|_| Error::bad_database("Invalid history visibility event in database.")) + } else { + Ok(false) + } } /// Whether a user is allowed to see an event, based on