Cleanup and optimize several user_can conditions.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -92,12 +92,6 @@ pub async fn user_can_see_event(
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
let currently_member = self
|
|
||||||
.services
|
|
||||||
.state_cache
|
|
||||||
.is_joined(user_id, room_id)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let history_visibility = self
|
let history_visibility = self
|
||||||
.state_get_content(shortstatehash, &StateEventType::RoomHistoryVisibility, "")
|
.state_get_content(shortstatehash, &StateEventType::RoomHistoryVisibility, "")
|
||||||
.await
|
.await
|
||||||
@@ -106,18 +100,23 @@ pub async fn user_can_see_event(
|
|||||||
});
|
});
|
||||||
|
|
||||||
match history_visibility {
|
match history_visibility {
|
||||||
| HistoryVisibility::Invited => {
|
|
||||||
// Allow if any member on requesting server was AT LEAST invited, else deny
|
|
||||||
self.user_was_invited(shortstatehash, user_id)
|
|
||||||
.await
|
|
||||||
},
|
|
||||||
| HistoryVisibility::Joined => {
|
|
||||||
// Allow if any member on requested server was joined, else deny
|
|
||||||
self.user_was_joined(shortstatehash, user_id)
|
|
||||||
.await
|
|
||||||
},
|
|
||||||
| HistoryVisibility::WorldReadable => true,
|
| HistoryVisibility::WorldReadable => true,
|
||||||
| HistoryVisibility::Shared | _ => currently_member,
|
|
||||||
|
// Allow if any member on requesting server was AT LEAST invited, else deny
|
||||||
|
| HistoryVisibility::Invited =>
|
||||||
|
self.user_was_invited(shortstatehash, user_id)
|
||||||
|
.await,
|
||||||
|
|
||||||
|
// Allow if any member on requested server was joined, else deny
|
||||||
|
| HistoryVisibility::Joined =>
|
||||||
|
self.user_was_joined(shortstatehash, user_id)
|
||||||
|
.await,
|
||||||
|
|
||||||
|
| HistoryVisibility::Shared | _ =>
|
||||||
|
self.services
|
||||||
|
.state_cache
|
||||||
|
.is_joined(user_id, room_id)
|
||||||
|
.await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,16 +143,19 @@ pub async fn user_can_see_state_events(&self, user_id: &UserId, room_id: &RoomId
|
|||||||
|
|
||||||
match history_visibility {
|
match history_visibility {
|
||||||
| HistoryVisibility::WorldReadable => true,
|
| HistoryVisibility::WorldReadable => true,
|
||||||
| HistoryVisibility::Shared =>
|
|
||||||
self.services
|
|
||||||
.state_cache
|
|
||||||
.once_joined(user_id, room_id)
|
|
||||||
.await,
|
|
||||||
| HistoryVisibility::Invited =>
|
| HistoryVisibility::Invited =>
|
||||||
self.services
|
self.services
|
||||||
.state_cache
|
.state_cache
|
||||||
.is_invited(user_id, room_id)
|
.is_invited(user_id, room_id)
|
||||||
.await,
|
.await,
|
||||||
|
|
||||||
|
| HistoryVisibility::Shared =>
|
||||||
|
self.services
|
||||||
|
.state_cache
|
||||||
|
.once_joined(user_id, room_id)
|
||||||
|
.await,
|
||||||
|
|
||||||
| _ => false,
|
| _ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user