check if user is joined in the room in user_can_invite

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
Matthias Ahouansou 2024-04-03 18:43:31 -04:00 committed by June
parent c803891634
commit 172d71e365

View file

@ -142,6 +142,7 @@ 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> {
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| {
@ -149,6 +150,9 @@ impl Service {
})
})
.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