+impl CommunityView {
+ pub async fn read(
+ pool: &mut DbPool<'_>,
+ community_id: CommunityId,
+ my_person_id: Option<PersonId>,
+ is_mod_or_admin: bool,
+ ) -> Result<Self, Error> {
+ queries()
+ .read(pool, (community_id, my_person_id, is_mod_or_admin))
+ .await
+ }
+
+ pub async fn is_mod_or_admin(
+ pool: &mut DbPool<'_>,
+ person_id: PersonId,
+ community_id: CommunityId,
+ ) -> Result<bool, Error> {
+ let is_mod =
+ CommunityModeratorView::is_community_moderator(pool, community_id, person_id).await?;
+ if is_mod {
+ return Ok(true);
+ }
+
+ PersonView::is_admin(pool, person_id).await
+ }
+}
+
+#[derive(Default)]
+pub struct CommunityQuery<'a> {
+ pub listing_type: Option<ListingType>,
+ pub sort: Option<SortType>,
+ pub local_user: Option<&'a LocalUser>,
+ pub search_term: Option<String>,
+ pub is_mod_or_admin: bool,
+ pub show_nsfw: bool,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
+}
+
+impl<'a> CommunityQuery<'a> {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<CommunityView>, Error> {
+ queries().list(pool, self).await