From b9e442b6949dab72706aea9fb3bb2a9dc030838a Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 3 Apr 2024 16:01:01 -0400 Subject: [PATCH] use map_or in user_can_invite Signed-off-by: strawberry --- src/service/rooms/state_accessor/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index fdd62edd..ce31dd92 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -143,12 +143,11 @@ 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(|pdu_event| { + .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 }) }) - .unwrap_or(Ok(false)) .map_err(|_| Error::bad_database("Invalid history visibility event in database.")) }