mirror of
https://github.com/LemmyNet/lemmy.git
synced 2026-05-12 12:19:00 -05:00
Adding a report list sort override. (#6457)
* Adding a report list sort override. - Fixes #6436 * Add a ReportSortType::Default option
This commit is contained in:
@@ -16,7 +16,17 @@ pub async fn list_reports(
|
||||
context: Data<LemmyContext>,
|
||||
local_user_view: LocalUserView,
|
||||
) -> LemmyResult<Json<PagedResponse<ReportCombinedView>>> {
|
||||
let my_reports_only = data.my_reports_only;
|
||||
let ListReports {
|
||||
unresolved_only,
|
||||
type_,
|
||||
post_id,
|
||||
community_id,
|
||||
sort,
|
||||
page_cursor,
|
||||
limit,
|
||||
show_community_rule_violations,
|
||||
my_reports_only,
|
||||
} = data;
|
||||
|
||||
// Only check mod or admin status when not viewing my reports
|
||||
if !my_reports_only.unwrap_or_default() {
|
||||
@@ -24,14 +34,15 @@ pub async fn list_reports(
|
||||
}
|
||||
|
||||
let reports = ReportCombinedQuery {
|
||||
community_id: data.community_id,
|
||||
post_id: data.post_id,
|
||||
type_: data.type_,
|
||||
unresolved_only: data.unresolved_only,
|
||||
show_community_rule_violations: data.show_community_rule_violations,
|
||||
community_id,
|
||||
post_id,
|
||||
type_,
|
||||
unresolved_only,
|
||||
show_community_rule_violations,
|
||||
my_reports_only,
|
||||
page_cursor: data.page_cursor,
|
||||
limit: data.limit,
|
||||
sort,
|
||||
page_cursor,
|
||||
limit,
|
||||
}
|
||||
.list(&mut context.pool(), &local_user_view)
|
||||
.await?;
|
||||
|
||||
@@ -61,6 +61,20 @@ pub enum LocalUserSortType {
|
||||
Old,
|
||||
}
|
||||
|
||||
/// The Report sort type.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
|
||||
#[cfg_attr(feature = "ts-rs", ts(export))]
|
||||
pub enum ReportSortType {
|
||||
#[default]
|
||||
/// By default, if viewing all reports, order by newest, but if viewing unresolved only, show
|
||||
/// the oldest first (FIFO)
|
||||
Default,
|
||||
New,
|
||||
Old,
|
||||
}
|
||||
|
||||
/// The person sort type.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::{CommentReportView, CommunityReportView, PostReportView, PrivateMessageReportView};
|
||||
use lemmy_db_schema::{
|
||||
ReportSortType,
|
||||
ReportType,
|
||||
newtypes::{
|
||||
CommentId,
|
||||
@@ -30,6 +31,9 @@ pub struct ListReports {
|
||||
pub post_id: Option<PostId>,
|
||||
/// if no community is given, it returns reports for all communities moderated by the auth user
|
||||
pub community_id: Option<CommunityId>,
|
||||
/// If this is None, then the default sort is Old / First In First Out if viewing unresolved
|
||||
/// reports, but new if viewing all reports. Setting this overrides the default.
|
||||
pub sort: Option<ReportSortType>,
|
||||
pub page_cursor: Option<PaginationCursor>,
|
||||
pub limit: Option<i64>,
|
||||
/// Only for admins: also show reports with `violates_instance_rules=false`
|
||||
|
||||
@@ -17,8 +17,9 @@ use diesel::{
|
||||
dsl::not,
|
||||
};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use i_love_jesus::asc_if;
|
||||
use i_love_jesus::{SortDirection, asc_if};
|
||||
use lemmy_db_schema::{
|
||||
ReportSortType,
|
||||
ReportType,
|
||||
newtypes::{
|
||||
CommentReportId,
|
||||
@@ -200,8 +201,9 @@ pub struct ReportCombinedQuery {
|
||||
pub unresolved_only: Option<bool>,
|
||||
/// For admins, also show reports with `violates_instance_rules=false`
|
||||
pub show_community_rule_violations: Option<bool>,
|
||||
pub page_cursor: Option<PaginationCursor>,
|
||||
pub my_reports_only: Option<bool>,
|
||||
pub sort: Option<ReportSortType>,
|
||||
pub page_cursor: Option<PaginationCursor>,
|
||||
pub limit: Option<i64>,
|
||||
}
|
||||
|
||||
@@ -251,15 +253,19 @@ impl ReportCombinedQuery {
|
||||
}
|
||||
}
|
||||
|
||||
// If viewing all reports, order by newest, but if viewing unresolved only, show the oldest
|
||||
// first (FIFO)
|
||||
let unresolved_only = self.unresolved_only.unwrap_or_default();
|
||||
let sort_direction = asc_if(unresolved_only);
|
||||
|
||||
if unresolved_only {
|
||||
query = query.filter(not(report_combined::resolved));
|
||||
};
|
||||
|
||||
let sort_direction = match self.sort.unwrap_or_default() {
|
||||
// By default, if viewing all reports, order by newest, but if viewing unresolved only, show
|
||||
// the oldest first (FIFO)
|
||||
ReportSortType::Default => asc_if(unresolved_only),
|
||||
ReportSortType::New => SortDirection::Desc,
|
||||
ReportSortType::Old => SortDirection::Asc,
|
||||
};
|
||||
|
||||
// Sorting by published
|
||||
let paginated_query =
|
||||
ReportCombinedView::paginate(query, &self.page_cursor, sort_direction, pool)
|
||||
|
||||
Reference in New Issue
Block a user