use map_or in user_can_invite

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-04-03 16:01:01 -04:00 committed by June
parent ddcf43f1b8
commit b9e442b694

View file

@ -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<bool> {
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."))
}