"tokio",
"tracing",
"ts-rs",
- "typed-builder",
]
[[package]]
"serde",
"serde_with",
"ts-rs",
- "typed-builder",
]
[[package]]
let data: &ListCommentReports = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let person_id = local_user_view.person.id;
- let admin = local_user_view.person.admin;
let community_id = data.community_id;
let unresolved_only = data.unresolved_only;
let page = data.page;
let limit = data.limit;
- let comment_reports = CommentReportQuery::builder()
- .pool(&mut context.pool())
- .my_person_id(person_id)
- .admin(admin)
- .community_id(community_id)
- .unresolved_only(unresolved_only)
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ let comment_reports = CommentReportQuery {
+ community_id,
+ unresolved_only,
+ page,
+ limit,
+ }
+ .list(&mut context.pool(), &local_user_view.person)
+ .await?;
Ok(ListCommentReportsResponse { comment_reports })
}
let person_id = Some(local_user_view.person.id);
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
- let mentions = PersonMentionQuery::builder()
- .pool(&mut context.pool())
- .recipient_id(person_id)
- .my_person_id(person_id)
- .sort(sort)
- .unread_only(unread_only)
- .show_bot_accounts(show_bot_accounts)
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ let mentions = PersonMentionQuery {
+ recipient_id: person_id,
+ my_person_id: person_id,
+ sort,
+ unread_only,
+ show_bot_accounts,
+ page,
+ limit,
+ }
+ .list(&mut context.pool())
+ .await?;
Ok(GetPersonMentionsResponse { mentions })
}
let person_id = Some(local_user_view.person.id);
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
- let replies = CommentReplyQuery::builder()
- .pool(&mut context.pool())
- .recipient_id(person_id)
- .my_person_id(person_id)
- .sort(sort)
- .unread_only(unread_only)
- .show_bot_accounts(show_bot_accounts)
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ let replies = CommentReplyQuery {
+ recipient_id: person_id,
+ my_person_id: person_id,
+ sort,
+ unread_only,
+ show_bot_accounts,
+ page,
+ limit,
+ }
+ .list(&mut context.pool())
+ .await?;
Ok(GetRepliesResponse { replies })
}
let data: &ListPostReports = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let person_id = local_user_view.person.id;
- let admin = local_user_view.person.admin;
let community_id = data.community_id;
let unresolved_only = data.unresolved_only;
let page = data.page;
let limit = data.limit;
- let post_reports = PostReportQuery::builder()
- .pool(&mut context.pool())
- .my_person_id(person_id)
- .admin(admin)
- .community_id(community_id)
- .unresolved_only(unresolved_only)
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ let post_reports = PostReportQuery {
+ community_id,
+ unresolved_only,
+ page,
+ limit,
+ }
+ .list(&mut context.pool(), &local_user_view.person)
+ .await?;
Ok(ListPostReportsResponse { post_reports })
}
let unresolved_only = self.unresolved_only;
let page = self.page;
let limit = self.limit;
- let private_message_reports = PrivateMessageReportQuery::builder()
- .pool(&mut context.pool())
- .unresolved_only(unresolved_only)
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ let private_message_reports = PrivateMessageReportQuery {
+ unresolved_only,
+ page,
+ limit,
+ }
+ .list(&mut context.pool())
+ .await?;
Ok(ListPrivateMessageReportsResponse {
private_message_reports,
is_admin(&local_user_view)?;
let unread_only = data.unread_only;
- let verified_email_only = local_site.require_email_verification;
+ let verified_email_only = Some(local_site.require_email_verification);
let page = data.page;
let limit = data.limit;
- let registration_applications = RegistrationApplicationQuery::builder()
- .pool(&mut context.pool())
- .unread_only(unread_only)
- .verified_email_only(Some(verified_email_only))
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ let registration_applications = RegistrationApplicationQuery {
+ unread_only,
+ verified_email_only,
+ page,
+ limit,
+ }
+ .list(&mut context.pool())
+ .await?;
Ok(Self::Response {
registration_applications,
// Comments
// TODO Diesel doesn't allow updates with joins, so this has to be a loop
- let comments = CommentQuery::builder()
- .pool(pool)
- .creator_id(Some(banned_person_id))
- .community_id(Some(community_id))
- .build()
- .list()
- .await?;
+ let comments = CommentQuery {
+ creator_id: Some(banned_person_id),
+ community_id: Some(community_id),
+ ..Default::default()
+ }
+ .list(pool)
+ .await?;
for comment_view in &comments {
let comment_id = comment_view.comment.id;
let page = data.page;
let limit = data.limit;
let local_user = local_user_view.map(|l| l.local_user);
- let communities = CommunityQuery::builder()
- .pool(&mut context.pool())
- .listing_type(listing_type)
- .show_nsfw(show_nsfw)
- .sort(sort)
- .local_user(local_user.as_ref())
- .page(page)
- .limit(limit)
- .is_mod_or_admin(is_admin)
- .build()
- .list()
- .await?;
+ let communities = CommunityQuery {
+ listing_type,
+ show_nsfw,
+ sort,
+ local_user: local_user.as_ref(),
+ page,
+ limit,
+ is_mod_or_admin: is_admin,
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?;
// Return the jwt
Ok(ListCommunitiesResponse { communities })
// Fetch the cross_posts
let cross_posts = if let Some(url) = &post_view.post.url {
- let mut x_posts = PostQuery::builder()
- .pool(&mut context.pool())
- .url_search(Some(url.inner().as_str().into()))
- .build()
- .list()
- .await?;
+ let mut x_posts = PostQuery {
+ url_search: Some(url.inner().as_str().into()),
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?;
// Don't return this post as one of the cross_posts
x_posts.retain(|x| x.post.id != post_id);
let page = data.page;
let limit = data.limit;
let unread_only = data.unread_only;
- let mut messages = PrivateMessageQuery::builder()
- .pool(&mut context.pool())
- .recipient_id(person_id)
- .page(page)
- .limit(limit)
- .unread_only(unread_only)
- .build()
- .list()
- .await?;
+ let mut messages = PrivateMessageQuery {
+ page,
+ limit,
+ unread_only,
+ }
+ .list(&mut context.pool(), person_id)
+ .await?;
// Messages sent by ourselves should be marked as read. The `read` column in database is only
// for the recipient, and shouldnt be exposed to sender.
let limit = data.limit;
let parent_id = data.parent_id;
- let listing_type = listing_type_with_default(data.type_, &local_site, community_id)?;
+ let listing_type = Some(listing_type_with_default(
+ data.type_,
+ &local_site,
+ community_id,
+ )?);
// If a parent_id is given, fetch the comment to get the path
let parent_path = if let Some(parent_id) = parent_id {
let parent_path_cloned = parent_path.clone();
let post_id = data.post_id;
let local_user = local_user_view.map(|l| l.local_user);
- let comments = CommentQuery::builder()
- .pool(&mut context.pool())
- .listing_type(Some(listing_type))
- .sort(sort)
- .max_depth(max_depth)
- .saved_only(saved_only)
- .community_id(community_id)
- .parent_path(parent_path_cloned)
- .post_id(post_id)
- .local_user(local_user.as_ref())
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await
- .with_lemmy_type(LemmyErrorType::CouldntGetComments)?;
+ let comments = CommentQuery {
+ listing_type,
+ sort,
+ max_depth,
+ saved_only,
+ community_id,
+ parent_path: parent_path_cloned,
+ post_id,
+ local_user: local_user.as_ref(),
+ page,
+ limit,
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntGetComments)?;
Ok(Json(GetCommentsResponse { comments }))
}
};
let saved_only = data.saved_only;
- let listing_type = listing_type_with_default(data.type_, &local_site, community_id)?;
+ let listing_type = Some(listing_type_with_default(
+ data.type_,
+ &local_site,
+ community_id,
+ )?);
- let is_mod_or_admin =
+ let is_mod_or_admin = Some(
is_mod_or_admin_opt(&mut context.pool(), local_user_view.as_ref(), community_id)
.await
- .is_ok();
-
- let posts = PostQuery::builder()
- .pool(&mut context.pool())
- .local_user(local_user_view.map(|l| l.local_user).as_ref())
- .listing_type(Some(listing_type))
- .sort(sort)
- .community_id(community_id)
- .saved_only(saved_only)
- .page(page)
- .limit(limit)
- .is_mod_or_admin(Some(is_mod_or_admin))
- .build()
- .list()
- .await
- .with_lemmy_type(LemmyErrorType::CouldntGetPosts)?;
+ .is_ok(),
+ );
+
+ let posts = PostQuery {
+ local_user: local_user_view.map(|l| l.local_user).as_ref(),
+ listing_type,
+ sort,
+ community_id,
+ saved_only,
+ page,
+ limit,
+ is_mod_or_admin,
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntGetPosts)?;
Ok(Json(GetPostsResponse { posts }))
}
let local_user = local_user_view.map(|l| l.local_user);
let local_user_clone = local_user.clone();
- let posts = PostQuery::builder()
- .pool(&mut context.pool())
- .sort(sort)
- .saved_only(saved_only)
- .local_user(local_user.as_ref())
- .community_id(community_id)
- .is_mod_or_admin(is_admin)
- .page(page)
- .limit(limit)
- .creator_id(
+ let posts = PostQuery {
+ sort,
+ saved_only,
+ local_user:local_user.as_ref(),
+ community_id,
+ is_mod_or_admin: is_admin,
+ page,
+ limit,
+ creator_id:
// If its saved only, you don't care what creator it was
// Or, if its not saved, then you only want it for that specific creator
if !saved_only.unwrap_or(false) {
Some(person_details_id)
} else {
None
- },
- )
- .build()
- .list()
- .await?;
+ }
+ ,
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?;
- let comments = CommentQuery::builder()
- .pool(&mut context.pool())
- .local_user(local_user_clone.as_ref())
- .sort(sort.map(post_to_comment_sort_type))
- .saved_only(saved_only)
- .show_deleted_and_removed(Some(false))
- .community_id(community_id)
- .page(page)
- .limit(limit)
- .creator_id(
+ let comments = CommentQuery {
+ local_user: (local_user_clone.as_ref()),
+ sort: (sort.map(post_to_comment_sort_type)),
+ saved_only: (saved_only),
+ show_deleted_and_removed: (Some(false)),
+ community_id: (community_id),
+ page: (page),
+ limit: (limit),
+ creator_id: (
// If its saved only, you don't care what creator it was
// Or, if its not saved, then you only want it for that specific creator
if !saved_only.unwrap_or(false) {
Some(person_details_id)
} else {
None
- },
- )
- .build()
- .list()
- .await?;
+ }
+ ),
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?;
let moderates =
CommunityModeratorView::for_person(&mut context.pool(), person_details_id).await?;
let local_user = local_user_view.map(|l| l.local_user);
match search_type {
SearchType::Posts => {
- posts = PostQuery::builder()
- .pool(&mut context.pool())
- .sort(sort)
- .listing_type(listing_type)
- .community_id(community_id)
- .creator_id(creator_id)
- .local_user(local_user.as_ref())
- .search_term(Some(q))
- .is_mod_or_admin(is_admin)
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ posts = PostQuery {
+ sort: (sort),
+ listing_type: (listing_type),
+ community_id: (community_id),
+ creator_id: (creator_id),
+ local_user: (local_user.as_ref()),
+ search_term: (Some(q)),
+ is_mod_or_admin: (is_admin),
+ page: (page),
+ limit: (limit),
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?;
}
SearchType::Comments => {
- comments = CommentQuery::builder()
- .pool(&mut context.pool())
- .sort(sort.map(post_to_comment_sort_type))
- .listing_type(listing_type)
- .search_term(Some(q))
- .community_id(community_id)
- .creator_id(creator_id)
- .local_user(local_user.as_ref())
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ comments = CommentQuery {
+ sort: (sort.map(post_to_comment_sort_type)),
+ listing_type: (listing_type),
+ search_term: (Some(q)),
+ community_id: (community_id),
+ creator_id: (creator_id),
+ local_user: (local_user.as_ref()),
+ page: (page),
+ limit: (limit),
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?;
}
SearchType::Communities => {
- communities = CommunityQuery::builder()
- .pool(&mut context.pool())
- .sort(sort)
- .listing_type(listing_type)
- .search_term(Some(q))
- .local_user(local_user.as_ref())
- .is_mod_or_admin(is_admin)
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ communities = CommunityQuery {
+ sort: (sort),
+ listing_type: (listing_type),
+ search_term: (Some(q)),
+ local_user: (local_user.as_ref()),
+ is_mod_or_admin: (is_admin),
+ page: (page),
+ limit: (limit),
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?;
}
SearchType::Users => {
- users = PersonQuery::builder()
- .pool(&mut context.pool())
- .sort(sort)
- .search_term(Some(q))
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ users = PersonQuery {
+ sort: (sort),
+ search_term: (Some(q)),
+ page: (page),
+ limit: (limit),
+ }
+ .list(&mut context.pool())
+ .await?;
}
SearchType::All => {
// If the community or creator is included, dont search communities or users
data.community_id.is_some() || data.community_name.is_some() || data.creator_id.is_some();
let local_user_ = local_user.clone();
- posts = PostQuery::builder()
- .pool(&mut context.pool())
- .sort(sort)
- .listing_type(listing_type)
- .community_id(community_id)
- .creator_id(creator_id)
- .local_user(local_user_.as_ref())
- .search_term(Some(q))
- .is_mod_or_admin(is_admin)
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ posts = PostQuery {
+ sort: (sort),
+ listing_type: (listing_type),
+ community_id: (community_id),
+ creator_id: (creator_id),
+ local_user: (local_user_.as_ref()),
+ search_term: (Some(q)),
+ is_mod_or_admin: (is_admin),
+ page: (page),
+ limit: (limit),
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?;
let q = data.q.clone();
let local_user_ = local_user.clone();
- comments = CommentQuery::builder()
- .pool(&mut context.pool())
- .sort(sort.map(post_to_comment_sort_type))
- .listing_type(listing_type)
- .search_term(Some(q))
- .community_id(community_id)
- .creator_id(creator_id)
- .local_user(local_user_.as_ref())
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ comments = CommentQuery {
+ sort: (sort.map(post_to_comment_sort_type)),
+ listing_type: (listing_type),
+ search_term: (Some(q)),
+ community_id: (community_id),
+ creator_id: (creator_id),
+ local_user: (local_user_.as_ref()),
+ page: (page),
+ limit: (limit),
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?;
let q = data.q.clone();
communities = if community_or_creator_included {
vec![]
} else {
- CommunityQuery::builder()
- .pool(&mut context.pool())
- .sort(sort)
- .listing_type(listing_type)
- .search_term(Some(q))
- .local_user(local_user.as_ref())
- .is_mod_or_admin(is_admin)
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?
+ CommunityQuery {
+ sort: (sort),
+ listing_type: (listing_type),
+ search_term: (Some(q)),
+ local_user: (local_user.as_ref()),
+ is_mod_or_admin: (is_admin),
+ page: (page),
+ limit: (limit),
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?
};
let q = data.q.clone();
users = if community_or_creator_included {
vec![]
} else {
- PersonQuery::builder()
- .pool(&mut context.pool())
- .sort(sort)
- .search_term(Some(q))
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?
+ PersonQuery {
+ sort: (sort),
+ search_term: (Some(q)),
+ page: (page),
+ limit: (limit),
+ }
+ .list(&mut context.pool())
+ .await?
};
}
SearchType::Url => {
- posts = PostQuery::builder()
- .pool(&mut context.pool())
- .sort(sort)
- .listing_type(listing_type)
- .community_id(community_id)
- .creator_id(creator_id)
- .url_search(Some(q))
- .is_mod_or_admin(is_admin)
- .page(page)
- .limit(limit)
- .build()
- .list()
- .await?;
+ posts = PostQuery {
+ sort: (sort),
+ listing_type: (listing_type),
+ community_id: (community_id),
+ creator_id: (creator_id),
+ url_search: (Some(q)),
+ is_mod_or_admin: (is_admin),
+ page: (page),
+ limit: (limit),
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?;
}
};
serde = { workspace = true }
serde_with = { workspace = true }
tracing = { workspace = true, optional = true }
-typed-builder = { workspace = true }
ts-rs = { workspace = true, optional = true }
[dev-dependencies]
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool},
};
-use typed_builder::TypedBuilder;
impl CommentReportView {
/// returns the CommentReportView for the provided report_id
}
}
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct CommentReportQuery<'a, 'b: 'a> {
- #[builder(!default)]
- pool: &'a mut DbPool<'b>,
- #[builder(!default)]
- my_person_id: PersonId,
- #[builder(!default)]
- admin: bool,
- community_id: Option<CommunityId>,
- page: Option<i64>,
- limit: Option<i64>,
- unresolved_only: Option<bool>,
+#[derive(Default)]
+pub struct CommentReportQuery {
+ pub community_id: Option<CommunityId>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
+ pub unresolved_only: Option<bool>,
}
-impl<'a, 'b: 'a> CommentReportQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<CommentReportView>, Error> {
- let conn = &mut get_conn(self.pool).await?;
+impl CommentReportQuery {
+ pub async fn list(
+ self,
+ pool: &mut DbPool<'_>,
+ my_person: &Person,
+ ) -> Result<Vec<CommentReportView>, Error> {
+ let conn = &mut get_conn(pool).await?;
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
comment_like::table.on(
comment::id
.eq(comment_like::comment_id)
- .and(comment_like::person_id.eq(self.my_person_id)),
+ .and(comment_like::person_id.eq(my_person.id)),
),
)
.left_join(
.offset(offset);
// If its not an admin, get only the ones you mod
- let res = if !self.admin {
+ let res = if !my_person.admin {
query
.inner_join(
community_moderator::table.on(
community_moderator::community_id
.eq(post::community_id)
- .and(community_moderator::person_id.eq(self.my_person_id)),
+ .and(community_moderator::person_id.eq(my_person.id)),
),
)
.load::<<CommentReportView as JoinView>::JoinTuple>(conn)
};
// Do a batch read of timmys reports
- let reports = CommentReportQuery::builder()
- .pool(pool)
- .my_person_id(inserted_timmy.id)
- .admin(false)
- .build()
- .list()
+ let reports = CommentReportQuery::default()
+ .list(pool, &inserted_timmy)
.await
.unwrap();
// Do a batch read of timmys reports
// It should only show saras, which is unresolved
- let reports_after_resolve = CommentReportQuery::builder()
- .pool(pool)
- .my_person_id(inserted_timmy.id)
- .admin(false)
- .unresolved_only(Some(true))
- .build()
- .list()
- .await
- .unwrap();
+ let reports_after_resolve = CommentReportQuery {
+ unresolved_only: (Some(true)),
+ ..Default::default()
+ }
+ .list(pool, &inserted_timmy)
+ .await
+ .unwrap();
assert_eq!(reports_after_resolve[0], expected_sara_report_view);
assert_eq!(reports_after_resolve.len(), 1);
CommentSortType,
ListingType,
};
-use typed_builder::TypedBuilder;
type CommentViewTuple = (
Comment,
}
}
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct CommentQuery<'a, 'b: 'a> {
- #[builder(!default)]
- pool: &'a mut DbPool<'b>,
- listing_type: Option<ListingType>,
- sort: Option<CommentSortType>,
- community_id: Option<CommunityId>,
- post_id: Option<PostId>,
- parent_path: Option<Ltree>,
- creator_id: Option<PersonId>,
- local_user: Option<&'a LocalUser>,
- search_term: Option<String>,
- saved_only: Option<bool>,
- show_deleted_and_removed: Option<bool>,
- page: Option<i64>,
- limit: Option<i64>,
- max_depth: Option<i32>,
+#[derive(Default)]
+pub struct CommentQuery<'a> {
+ pub listing_type: Option<ListingType>,
+ pub sort: Option<CommentSortType>,
+ pub community_id: Option<CommunityId>,
+ pub post_id: Option<PostId>,
+ pub parent_path: Option<Ltree>,
+ pub creator_id: Option<PersonId>,
+ pub local_user: Option<&'a LocalUser>,
+ pub search_term: Option<String>,
+ pub saved_only: Option<bool>,
+ pub show_deleted_and_removed: Option<bool>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
+ pub max_depth: Option<i32>,
}
-impl<'a, 'b: 'a> CommentQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<CommentView>, Error> {
- let conn = &mut get_conn(self.pool).await?;
+impl<'a> CommentQuery<'a> {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<CommentView>, Error> {
+ let conn = &mut get_conn(pool).await?;
// The left join below will return None in this case
let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
let mut expected_comment_view_with_person = expected_comment_view_no_person.clone();
expected_comment_view_with_person.my_vote = Some(1);
- let read_comment_views_no_person = CommentQuery::builder()
- .pool(pool)
- .sort(Some(CommentSortType::Old))
- .post_id(Some(data.inserted_post.id))
- .build()
- .list()
- .await
- .unwrap();
+ let read_comment_views_no_person = CommentQuery {
+ sort: (Some(CommentSortType::Old)),
+ post_id: (Some(data.inserted_post.id)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
assert_eq!(
expected_comment_view_no_person,
read_comment_views_no_person[0]
);
- let read_comment_views_with_person = CommentQuery::builder()
- .pool(pool)
- .sort(Some(CommentSortType::Old))
- .post_id(Some(data.inserted_post.id))
- .local_user(Some(&data.inserted_local_user))
- .build()
- .list()
- .await
- .unwrap();
+ let read_comment_views_with_person = CommentQuery {
+ sort: (Some(CommentSortType::Old)),
+ post_id: (Some(data.inserted_post.id)),
+ local_user: (Some(&data.inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
assert_eq!(
expected_comment_view_with_person,
let data = init_data(pool).await;
let top_path = data.inserted_comment_0.path.clone();
- let read_comment_views_top_path = CommentQuery::builder()
- .pool(pool)
- .post_id(Some(data.inserted_post.id))
- .parent_path(Some(top_path))
- .build()
- .list()
- .await
- .unwrap();
+ let read_comment_views_top_path = CommentQuery {
+ post_id: (Some(data.inserted_post.id)),
+ parent_path: (Some(top_path)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
let child_path = data.inserted_comment_1.path.clone();
- let read_comment_views_child_path = CommentQuery::builder()
- .pool(pool)
- .post_id(Some(data.inserted_post.id))
- .parent_path(Some(child_path))
- .build()
- .list()
- .await
- .unwrap();
+ let read_comment_views_child_path = CommentQuery {
+ post_id: (Some(data.inserted_post.id)),
+ parent_path: (Some(child_path)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
// Make sure the comment parent-limited fetch is correct
assert_eq!(6, read_comment_views_top_path.len());
assert!(child_comments.contains(&data.inserted_comment_1));
assert!(!child_comments.contains(&data.inserted_comment_2));
- let read_comment_views_top_max_depth = CommentQuery::builder()
- .pool(pool)
- .post_id(Some(data.inserted_post.id))
- .max_depth(Some(1))
- .build()
- .list()
- .await
- .unwrap();
+ let read_comment_views_top_max_depth = CommentQuery {
+ post_id: (Some(data.inserted_post.id)),
+ max_depth: (Some(1)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
// Make sure a depth limited one only has the top comment
assert_eq!(
assert_eq!(1, read_comment_views_top_max_depth.len());
let child_path = data.inserted_comment_1.path.clone();
- let read_comment_views_parent_max_depth = CommentQuery::builder()
- .pool(pool)
- .post_id(Some(data.inserted_post.id))
- .parent_path(Some(child_path))
- .max_depth(Some(1))
- .sort(Some(CommentSortType::New))
- .build()
- .list()
- .await
- .unwrap();
+ let read_comment_views_parent_max_depth = CommentQuery {
+ post_id: (Some(data.inserted_post.id)),
+ parent_path: (Some(child_path)),
+ max_depth: (Some(1)),
+ sort: (Some(CommentSortType::New)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
// Make sure a depth limited one, and given child comment 1, has 3
assert!(read_comment_views_parent_max_depth[2]
// by default, user has all languages enabled and should see all comments
// (except from blocked user)
- let all_languages = CommentQuery::builder()
- .pool(pool)
- .local_user(Some(&data.inserted_local_user))
- .build()
- .list()
- .await
- .unwrap();
+ let all_languages = CommentQuery {
+ local_user: (Some(&data.inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
assert_eq!(5, all_languages.len());
// change user lang to finnish, should only show one post in finnish and one undetermined
LocalUserLanguage::update(pool, vec![finnish_id], data.inserted_local_user.id)
.await
.unwrap();
- let finnish_comments = CommentQuery::builder()
- .pool(pool)
- .local_user(Some(&data.inserted_local_user))
- .build()
- .list()
- .await
- .unwrap();
+ let finnish_comments = CommentQuery {
+ local_user: (Some(&data.inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
assert_eq!(2, finnish_comments.len());
let finnish_comment = finnish_comments
.iter()
LocalUserLanguage::update(pool, vec![UNDETERMINED_ID], data.inserted_local_user.id)
.await
.unwrap();
- let undetermined_comment = CommentQuery::builder()
- .pool(pool)
- .local_user(Some(&data.inserted_local_user))
- .build()
- .list()
- .await
- .unwrap();
+ let undetermined_comment = CommentQuery {
+ local_user: (Some(&data.inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
assert_eq!(1, undetermined_comment.len());
cleanup(data, pool).await;
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool},
};
-use typed_builder::TypedBuilder;
type PostReportViewTuple = (
PostReport,
}
}
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PostReportQuery<'a, 'b: 'a> {
- #[builder(!default)]
- pool: &'a mut DbPool<'b>,
- #[builder(!default)]
- my_person_id: PersonId,
- #[builder(!default)]
- admin: bool,
- community_id: Option<CommunityId>,
- page: Option<i64>,
- limit: Option<i64>,
- unresolved_only: Option<bool>,
+#[derive(Default)]
+pub struct PostReportQuery {
+ pub community_id: Option<CommunityId>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
+ pub unresolved_only: Option<bool>,
}
-impl<'a, 'b: 'a> PostReportQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<PostReportView>, Error> {
- let conn = &mut get_conn(self.pool).await?;
+impl PostReportQuery {
+ pub async fn list(
+ self,
+ pool: &mut DbPool<'_>,
+ my_person: &Person,
+ ) -> Result<Vec<PostReportView>, Error> {
+ let conn = &mut get_conn(pool).await?;
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
let mut query = post_report::table
post_like::table.on(
post::id
.eq(post_like::post_id)
- .and(post_like::person_id.eq(self.my_person_id)),
+ .and(post_like::person_id.eq(my_person.id)),
),
)
.inner_join(post_aggregates::table.on(post_report::post_id.eq(post_aggregates::post_id)))
.offset(offset);
// If its not an admin, get only the ones you mod
- let res = if !self.admin {
+ let res = if !my_person.admin {
query
.inner_join(
community_moderator::table.on(
community_moderator::community_id
.eq(post::community_id)
- .and(community_moderator::person_id.eq(self.my_person_id)),
+ .and(community_moderator::person_id.eq(my_person.id)),
),
)
.load::<PostReportViewTuple>(conn)
};
// Do a batch read of timmys reports
- let reports = PostReportQuery::builder()
- .pool(pool)
- .my_person_id(inserted_timmy.id)
- .admin(false)
- .build()
- .list()
+ let reports = PostReportQuery::default()
+ .list(pool, &inserted_timmy)
.await
.unwrap();
// Do a batch read of timmys reports
// It should only show saras, which is unresolved
- let reports_after_resolve = PostReportQuery::builder()
- .pool(pool)
- .my_person_id(inserted_timmy.id)
- .admin(false)
- .unresolved_only(Some(true))
- .build()
- .list()
- .await
- .unwrap();
+ let reports_after_resolve = PostReportQuery {
+ unresolved_only: (Some(true)),
+ ..Default::default()
+ }
+ .list(pool, &inserted_timmy)
+ .await
+ .unwrap();
assert_eq!(reports_after_resolve[0], expected_sara_report_view);
// Make sure the counts are correct
SortType,
};
use tracing::debug;
-use typed_builder::TypedBuilder;
type PostViewTuple = (
Post,
}
}
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PostQuery<'a, 'b: 'a> {
- #[builder(!default)]
- pool: &'a mut DbPool<'b>,
- listing_type: Option<ListingType>,
- sort: Option<SortType>,
- creator_id: Option<PersonId>,
- community_id: Option<CommunityId>,
- local_user: Option<&'a LocalUser>,
- search_term: Option<String>,
- url_search: Option<String>,
- saved_only: Option<bool>,
+#[derive(Default)]
+pub struct PostQuery<'a> {
+ pub listing_type: Option<ListingType>,
+ pub sort: Option<SortType>,
+ pub creator_id: Option<PersonId>,
+ pub community_id: Option<CommunityId>,
+ pub local_user: Option<&'a LocalUser>,
+ pub search_term: Option<String>,
+ pub url_search: Option<String>,
+ pub saved_only: Option<bool>,
/// Used to show deleted or removed posts for admins
- is_mod_or_admin: Option<bool>,
- page: Option<i64>,
- limit: Option<i64>,
+ pub is_mod_or_admin: Option<bool>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
}
-impl<'a, 'b: 'a> PostQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<PostView>, Error> {
- let conn = &mut get_conn(self.pool).await?;
+impl<'a> PostQuery<'a> {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PostView>, Error> {
+ let conn = &mut get_conn(pool).await?;
// The left join below will return None in this case
let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
.await
.unwrap();
- let read_post_listing = PostQuery::builder()
- .pool(pool)
- .sort(Some(SortType::New))
- .community_id(Some(data.inserted_community.id))
- .local_user(Some(&inserted_local_user))
- .build()
- .list()
- .await
- .unwrap();
+ let read_post_listing = PostQuery {
+ sort: (Some(SortType::New)),
+ community_id: (Some(data.inserted_community.id)),
+ local_user: (Some(&inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
let post_listing_single_with_person = PostView::read(
pool,
.await
.unwrap();
- let post_listings_with_bots = PostQuery::builder()
- .pool(pool)
- .sort(Some(SortType::New))
- .community_id(Some(data.inserted_community.id))
- .local_user(Some(&inserted_local_user))
- .build()
- .list()
- .await
- .unwrap();
+ let post_listings_with_bots = PostQuery {
+ sort: (Some(SortType::New)),
+ community_id: (Some(data.inserted_community.id)),
+ local_user: (Some(&inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
// should include bot post which has "undetermined" language
assert_eq!(2, post_listings_with_bots.len());
let pool = &mut pool.into();
let data = init_data(pool).await;
- let read_post_listing_multiple_no_person = PostQuery::builder()
- .pool(pool)
- .sort(Some(SortType::New))
- .community_id(Some(data.inserted_community.id))
- .build()
- .list()
- .await
- .unwrap();
+ let read_post_listing_multiple_no_person = PostQuery {
+ sort: (Some(SortType::New)),
+ community_id: (Some(data.inserted_community.id)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
let read_post_listing_single_no_person =
PostView::read(pool, data.inserted_post.id, None, None)
};
CommunityBlock::block(pool, &community_block).await.unwrap();
- let read_post_listings_with_person_after_block = PostQuery::builder()
- .pool(pool)
- .sort(Some(SortType::New))
- .community_id(Some(data.inserted_community.id))
- .local_user(Some(&data.inserted_local_user))
- .build()
- .list()
- .await
- .unwrap();
+ let read_post_listings_with_person_after_block = PostQuery {
+ sort: (Some(SortType::New)),
+ community_id: (Some(data.inserted_community.id)),
+ local_user: (Some(&data.inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
// Should be 0 posts after the community block
assert_eq!(0, read_post_listings_with_person_after_block.len());
.await
.unwrap();
- let read_post_listing = PostQuery::builder()
- .pool(pool)
- .sort(Some(SortType::New))
- .community_id(Some(data.inserted_community.id))
- .local_user(Some(&inserted_local_user))
- .build()
- .list()
- .await
- .unwrap();
+ let read_post_listing = PostQuery {
+ sort: (Some(SortType::New)),
+ community_id: (Some(data.inserted_community.id)),
+ local_user: (Some(&inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
assert_eq!(1, read_post_listing.len());
assert_eq!(expected_post_with_upvote, read_post_listing[0]);
Post::create(pool, &post_spanish).await.unwrap();
- let post_listings_all = PostQuery::builder()
- .pool(pool)
- .sort(Some(SortType::New))
- .local_user(Some(&data.inserted_local_user))
- .build()
- .list()
- .await
- .unwrap();
+ let post_listings_all = PostQuery {
+ sort: (Some(SortType::New)),
+ local_user: (Some(&data.inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
// no language filters specified, all posts should be returned
assert_eq!(3, post_listings_all.len());
.await
.unwrap();
- let post_listing_french = PostQuery::builder()
- .pool(pool)
- .sort(Some(SortType::New))
- .local_user(Some(&data.inserted_local_user))
- .build()
- .list()
- .await
- .unwrap();
+ let post_listing_french = PostQuery {
+ sort: (Some(SortType::New)),
+ local_user: (Some(&data.inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
// only one post in french and one undetermined should be returned
assert_eq!(2, post_listing_french.len());
)
.await
.unwrap();
- let post_listings_french_und = PostQuery::builder()
- .pool(pool)
- .sort(Some(SortType::New))
- .local_user(Some(&data.inserted_local_user))
- .build()
- .list()
- .await
- .unwrap();
+ let post_listings_french_und = PostQuery {
+ sort: (Some(SortType::New)),
+ local_user: (Some(&data.inserted_local_user)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
// french post and undetermined language post should be returned
assert_eq!(2, post_listings_french_und.len());
.unwrap();
// Make sure you don't see the deleted post in the results
- let post_listings_no_admin = PostQuery::builder()
- .pool(pool)
- .sort(Some(SortType::New))
- .local_user(Some(&data.inserted_local_user))
- .is_mod_or_admin(Some(false))
- .build()
- .list()
- .await
- .unwrap();
+ let post_listings_no_admin = PostQuery {
+ sort: (Some(SortType::New)),
+ local_user: (Some(&data.inserted_local_user)),
+ is_mod_or_admin: (Some(false)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
assert_eq!(1, post_listings_no_admin.len());
// Make sure they see both
- let post_listings_is_admin = PostQuery::builder()
- .pool(pool)
- .sort(Some(SortType::New))
- .local_user(Some(&data.inserted_local_user))
- .is_mod_or_admin(Some(true))
- .build()
- .list()
- .await
- .unwrap();
+ let post_listings_is_admin = PostQuery {
+ sort: (Some(SortType::New)),
+ local_user: (Some(&data.inserted_local_user)),
+ is_mod_or_admin: (Some(true)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
assert_eq!(2, post_listings_is_admin.len());
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool},
};
-use typed_builder::TypedBuilder;
type PrivateMessageReportViewTuple = (
PrivateMessageReport,
}
}
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PrivateMessageReportQuery<'a, 'b: 'a> {
- #[builder(!default)]
- pool: &'a mut DbPool<'b>,
- page: Option<i64>,
- limit: Option<i64>,
- unresolved_only: Option<bool>,
+#[derive(Default)]
+pub struct PrivateMessageReportQuery {
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
+ pub unresolved_only: Option<bool>,
}
-impl<'a, 'b: 'a> PrivateMessageReportQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<PrivateMessageReportView>, Error> {
- let conn = &mut get_conn(self.pool).await?;
+impl PrivateMessageReportQuery {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PrivateMessageReportView>, Error> {
+ let conn = &mut get_conn(pool).await?;
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
let mut query = private_message_report::table
.await
.unwrap();
- let reports = PrivateMessageReportQuery::builder()
- .pool(pool)
- .build()
- .list()
+ let reports = PrivateMessageReportQuery::default()
+ .list(pool)
.await
.unwrap();
assert_eq!(1, reports.len());
.await
.unwrap();
- let reports = PrivateMessageReportQuery::builder()
- .pool(pool)
- .unresolved_only(Some(false))
- .build()
- .list()
- .await
- .unwrap();
+ let reports = PrivateMessageReportQuery {
+ unresolved_only: (Some(false)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
assert_eq!(1, reports.len());
assert!(reports[0].private_message_report.resolved);
assert!(reports[0].resolver.is_some());
utils::{get_conn, limit_and_offset, DbPool},
};
use tracing::debug;
-use typed_builder::TypedBuilder;
type PrivateMessageViewTuple = (PrivateMessage, Person, Person);
}
}
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PrivateMessageQuery<'a, 'b: 'a> {
- #[builder(!default)]
- pool: &'a mut DbPool<'b>,
- #[builder(!default)]
- recipient_id: PersonId,
- unread_only: Option<bool>,
- page: Option<i64>,
- limit: Option<i64>,
+#[derive(Default)]
+pub struct PrivateMessageQuery {
+ pub unread_only: Option<bool>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
}
-impl<'a, 'b: 'a> PrivateMessageQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<PrivateMessageView>, Error> {
- let conn = &mut get_conn(self.pool).await?;
+impl PrivateMessageQuery {
+ pub async fn list(
+ self,
+ pool: &mut DbPool<'_>,
+ recipient_id: PersonId,
+ ) -> Result<Vec<PrivateMessageView>, Error> {
+ let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
let mut query = private_message::table
if self.unread_only.unwrap_or(false) {
query = query
.filter(private_message::read.eq(false))
- .filter(private_message::recipient_id.eq(self.recipient_id));
+ .filter(private_message::recipient_id.eq(recipient_id));
}
// Otherwise, I want the ALL view to show both sent and received
else {
query = query.filter(
private_message::recipient_id
- .eq(self.recipient_id)
- .or(private_message::creator_id.eq(self.recipient_id)),
+ .eq(recipient_id)
+ .or(private_message::creator_id.eq(recipient_id)),
)
}
traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool},
};
-use typed_builder::TypedBuilder;
type RegistrationApplicationViewTuple =
(RegistrationApplication, LocalUser, Person, Option<Person>);
}
}
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct RegistrationApplicationQuery<'a, 'b: 'a> {
- #[builder(!default)]
- pool: &'a mut DbPool<'b>,
- unread_only: Option<bool>,
- verified_email_only: Option<bool>,
- page: Option<i64>,
- limit: Option<i64>,
+#[derive(Default)]
+pub struct RegistrationApplicationQuery {
+ pub unread_only: Option<bool>,
+ pub verified_email_only: Option<bool>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
}
-impl<'a, 'b: 'a> RegistrationApplicationQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<RegistrationApplicationView>, Error> {
- let conn = &mut get_conn(self.pool).await?;
+impl RegistrationApplicationQuery {
+ pub async fn list(
+ self,
+ pool: &mut DbPool<'_>,
+ ) -> Result<Vec<RegistrationApplicationView>, Error> {
+ let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
let mut query = registration_application::table
assert_eq!(read_sara_app_view, expected_sara_app_view);
// Do a batch read of the applications
- let apps = RegistrationApplicationQuery::builder()
- .pool(pool)
- .unread_only(Some(true))
- .build()
- .list()
- .await
- .unwrap();
+ let apps = RegistrationApplicationQuery {
+ unread_only: (Some(true)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
assert_eq!(
apps,
// Do a batch read of apps again
// It should show only jessicas which is unresolved
- let apps_after_resolve = RegistrationApplicationQuery::builder()
- .pool(pool)
- .unread_only(Some(true))
- .build()
- .list()
- .await
- .unwrap();
+ let apps_after_resolve = RegistrationApplicationQuery {
+ unread_only: (Some(true)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
assert_eq!(apps_after_resolve, vec![read_jess_app_view]);
// Make sure the counts are correct
assert_eq!(unread_count_after_approve, 1);
// Make sure the not undenied_only has all the apps
- let all_apps = RegistrationApplicationQuery::builder()
- .pool(pool)
- .build()
- .list()
+ let all_apps = RegistrationApplicationQuery::default()
+ .list(pool)
.await
.unwrap();
assert_eq!(all_apps.len(), 2);
], optional = true }
serde = { workspace = true }
serde_with = { workspace = true }
-typed-builder = { workspace = true }
ts-rs = { workspace = true, optional = true }
utils::{get_conn, limit_and_offset, DbPool},
CommentSortType,
};
-use typed_builder::TypedBuilder;
type CommentReplyViewTuple = (
CommentReply,
}
}
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct CommentReplyQuery<'a, 'b: 'a> {
- #[builder(!default)]
- pool: &'a mut DbPool<'b>,
- my_person_id: Option<PersonId>,
- recipient_id: Option<PersonId>,
- sort: Option<CommentSortType>,
- unread_only: Option<bool>,
- show_bot_accounts: Option<bool>,
- page: Option<i64>,
- limit: Option<i64>,
+#[derive(Default)]
+pub struct CommentReplyQuery {
+ pub my_person_id: Option<PersonId>,
+ pub recipient_id: Option<PersonId>,
+ pub sort: Option<CommentSortType>,
+ pub unread_only: Option<bool>,
+ pub show_bot_accounts: Option<bool>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
}
-impl<'a, 'b: 'a> CommentReplyQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<CommentReplyView>, Error> {
- let conn = &mut get_conn(self.pool).await?;
+impl CommentReplyQuery {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<CommentReplyView>, Error> {
+ let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
ListingType,
SortType,
};
-use typed_builder::TypedBuilder;
type CommunityViewTuple = (
Community,
}
}
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct CommunityQuery<'a, 'b: 'a> {
- #[builder(!default)]
- pool: &'a mut DbPool<'b>,
- 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>,
+#[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: Option<bool>,
+ pub show_nsfw: Option<bool>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
}
-impl<'a, 'b: 'a> CommunityQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<CommunityView>, Error> {
+impl<'a> CommunityQuery<'a> {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<CommunityView>, Error> {
use SortType::*;
- let conn = &mut get_conn(self.pool).await?;
+ let conn = &mut get_conn(pool).await?;
// The left join below will return None in this case
let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
utils::{get_conn, limit_and_offset, DbPool},
CommentSortType,
};
-use typed_builder::TypedBuilder;
type PersonMentionViewTuple = (
PersonMention,
}
}
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PersonMentionQuery<'a, 'b: 'a> {
- #[builder(!default)]
- pool: &'a mut DbPool<'b>,
- my_person_id: Option<PersonId>,
- recipient_id: Option<PersonId>,
- sort: Option<CommentSortType>,
- unread_only: Option<bool>,
- show_bot_accounts: Option<bool>,
- page: Option<i64>,
- limit: Option<i64>,
+#[derive(Default)]
+pub struct PersonMentionQuery {
+ pub my_person_id: Option<PersonId>,
+ pub recipient_id: Option<PersonId>,
+ pub sort: Option<CommentSortType>,
+ pub unread_only: Option<bool>,
+ pub show_bot_accounts: Option<bool>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
}
-impl<'a, 'b: 'a> PersonMentionQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<PersonMentionView>, Error> {
- let conn = &mut get_conn(self.pool).await?;
+impl PersonMentionQuery {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PersonMentionView>, Error> {
+ let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
SortType,
};
use std::iter::Iterator;
-use typed_builder::TypedBuilder;
type PersonViewTuple = (Person, PersonAggregates);
}
}
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PersonQuery<'a, 'b: 'a> {
- #[builder(!default)]
- pool: &'a mut DbPool<'b>,
- sort: Option<SortType>,
- search_term: Option<String>,
- page: Option<i64>,
- limit: Option<i64>,
+#[derive(Default)]
+pub struct PersonQuery {
+ pub sort: Option<SortType>,
+ pub search_term: Option<String>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
}
-impl<'a, 'b: 'a> PersonQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<PersonView>, Error> {
- let conn = &mut get_conn(self.pool).await?;
+impl PersonQuery {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PersonView>, Error> {
+ let conn = &mut get_conn(pool).await?;
let mut query = person::table
.inner_join(person_aggregates::table)
.select((person::all_columns, person_aggregates::all_columns))
) -> Result<HttpResponse, LemmyError> {
let site_view = SiteView::read_local(&mut context.pool()).await?;
- let posts = PostQuery::builder()
- .pool(&mut context.pool())
- .listing_type(Some(listing_type))
- .sort(Some(sort_type))
- .limit(Some(limit))
- .page(Some(page))
- .build()
- .list()
- .await?;
+ let posts = PostQuery {
+ listing_type: (Some(listing_type)),
+ sort: (Some(sort_type)),
+ limit: (Some(limit)),
+ page: (Some(page)),
+ ..Default::default()
+ }
+ .list(&mut context.pool())
+ .await?;
let items = create_post_items(posts, &context.settings().get_protocol_and_hostname())?;
let site_view = SiteView::read_local(pool).await?;
let person = Person::read_from_name(pool, user_name, false).await?;
- let posts = PostQuery::builder()
- .pool(pool)
- .listing_type(Some(ListingType::All))
- .sort(Some(*sort_type))
- .creator_id(Some(person.id))
- .limit(Some(*limit))
- .page(Some(*page))
- .build()
- .list()
- .await?;
+ let posts = PostQuery {
+ listing_type: (Some(ListingType::All)),
+ sort: (Some(*sort_type)),
+ creator_id: (Some(person.id)),
+ limit: (Some(*limit)),
+ page: (Some(*page)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await?;
let items = create_post_items(posts, protocol_and_hostname)?;
let site_view = SiteView::read_local(pool).await?;
let community = Community::read_from_name(pool, community_name, false).await?;
- let posts = PostQuery::builder()
- .pool(pool)
- .sort(Some(*sort_type))
- .community_id(Some(community.id))
- .limit(Some(*limit))
- .page(Some(*page))
- .build()
- .list()
- .await?;
+ let posts = PostQuery {
+ sort: (Some(*sort_type)),
+ community_id: (Some(community.id)),
+ limit: (Some(*limit)),
+ page: (Some(*page)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await?;
let items = create_post_items(posts, protocol_and_hostname)?;
let local_user_id = LocalUserId(Claims::decode(jwt, jwt_secret)?.claims.sub);
let local_user = LocalUser::read(pool, local_user_id).await?;
- let posts = PostQuery::builder()
- .pool(pool)
- .listing_type(Some(ListingType::Subscribed))
- .local_user(Some(&local_user))
- .sort(Some(*sort_type))
- .limit(Some(*limit))
- .page(Some(*page))
- .build()
- .list()
- .await?;
+ let posts = PostQuery {
+ listing_type: (Some(ListingType::Subscribed)),
+ local_user: (Some(&local_user)),
+ sort: (Some(*sort_type)),
+ limit: (Some(*limit)),
+ page: (Some(*page)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await?;
let items = create_post_items(posts, protocol_and_hostname)?;
let sort = CommentSortType::New;
- let replies = CommentReplyQuery::builder()
- .pool(pool)
- .recipient_id(Some(person_id))
- .my_person_id(Some(person_id))
- .show_bot_accounts(Some(show_bot_accounts))
- .sort(Some(sort))
- .limit(Some(RSS_FETCH_LIMIT))
- .build()
- .list()
- .await?;
-
- let mentions = PersonMentionQuery::builder()
- .pool(pool)
- .recipient_id(Some(person_id))
- .my_person_id(Some(person_id))
- .show_bot_accounts(Some(show_bot_accounts))
- .sort(Some(sort))
- .limit(Some(RSS_FETCH_LIMIT))
- .build()
- .list()
- .await?;
+ let replies = CommentReplyQuery {
+ recipient_id: (Some(person_id)),
+ my_person_id: (Some(person_id)),
+ show_bot_accounts: (Some(show_bot_accounts)),
+ sort: (Some(sort)),
+ limit: (Some(RSS_FETCH_LIMIT)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await?;
+
+ let mentions = PersonMentionQuery {
+ recipient_id: (Some(person_id)),
+ my_person_id: (Some(person_id)),
+ show_bot_accounts: (Some(show_bot_accounts)),
+ sort: (Some(sort)),
+ limit: (Some(RSS_FETCH_LIMIT)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await?;
let items = create_reply_and_mention_items(replies, mentions, protocol_and_hostname)?;