- pub async fn is_mod_or_admin(
- pool: &DbPool,
- person_id: PersonId,
- community_id: CommunityId,
- ) -> Result<bool, Error> {
- let is_mod = CommunityModeratorView::for_community(pool, community_id)
- .await
- .map(|v| {
- v.into_iter()
- .map(|m| m.moderator.id)
- .collect::<Vec<PersonId>>()
- })
- .unwrap_or_default()
- .contains(&person_id);
- if is_mod {
- return Ok(true);
- }
-
- let is_admin = PersonView::admins(pool)
- .await
- .map(|v| {
- v.into_iter()
- .map(|a| a.person.id)
- .collect::<Vec<PersonId>>()
- })
- .unwrap_or_default()
- .contains(&person_id);
- Ok(is_admin)
- }
-}
-
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct CommunityQuery<'a> {
- #[builder(!default)]
- pool: &'a DbPool,
- listing_type: Option<ListingType>,
- sort: Option<SortType>,
- local_user: Option<&'a LocalUser>,
- search_term: Option<String>,
- is_mod_or_admin: Option<bool>,
- show_nsfw: Option<bool>,
- page: Option<i64>,
- limit: Option<i64>,
-}
-
-impl<'a> CommunityQuery<'a> {
- pub async fn list(self) -> Result<Vec<CommunityView>, Error> {