From 86990d5138abecb8496386c5c0a382292145e38b Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 29 Nov 2023 05:08:23 -0500 Subject: [PATCH] Registrations and Reports should sort by New when viewing unresolved / unread. (#4207) - Fixes #4206 --- crates/db_views/src/comment_report_view.rs | 14 ++++++++------ crates/db_views/src/post_report_view.rs | 16 +++++++++------- .../src/registration_application_view.rs | 12 +++++++----- docker/docker-compose.yml | 2 +- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index acf31eb4c..a26b984b2 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -105,16 +105,18 @@ fn queries<'a>() -> Queries< query = query.filter(post::community_id.eq(community_id)); } + // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest first (FIFO) if options.unresolved_only { - query = query.filter(comment_report::resolved.eq(false)); + query = query + .filter(comment_report::resolved.eq(false)) + .order_by(comment_report::published.asc()); + } else { + query = query.order_by(comment_report::published.desc()); } let (limit, offset) = limit_and_offset(options.page, options.limit)?; - query = query - .order_by(comment_report::published.asc()) - .limit(limit) - .offset(offset); + query = query.limit(limit).offset(offset); // If its not an admin, get only the ones you mod if !user.local_user.admin { @@ -475,8 +477,8 @@ mod tests { assert_eq!( reports, [ - expected_sara_report_view.clone(), expected_jessica_report_view.clone(), + expected_sara_report_view.clone(), ] ); diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 32d8f8392..843b1ee54 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -83,16 +83,18 @@ fn queries<'a>() -> Queries< query = query.filter(post::community_id.eq(community_id)); } + // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest first (FIFO) if options.unresolved_only { - query = query.filter(post_report::resolved.eq(false)); + query = query + .filter(post_report::resolved.eq(false)) + .order_by(post_report::published.asc()); + } else { + query = query.order_by(post_report::published.desc()); } let (limit, offset) = limit_and_offset(options.page, options.limit)?; - query = query - .order_by(post_report::published.asc()) - .limit(limit) - .offset(offset); + query = query.limit(limit).offset(offset); // If its not an admin, get only the ones you mod if !user.local_user.admin { @@ -337,8 +339,8 @@ mod tests { .await .unwrap(); - assert_eq!(reports[0].creator.id, inserted_sara.id); - assert_eq!(reports[1].creator.id, inserted_jessica.id); + assert_eq!(reports[1].creator.id, inserted_sara.id); + assert_eq!(reports[0].creator.id, inserted_jessica.id); // Make sure the counts are correct let report_count = PostReportView::get_report_count(pool, inserted_timmy.id, false, None) diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index 1b0b1a370..9a298eb77 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -49,8 +49,13 @@ fn queries<'a>() -> Queries< let list = move |mut conn: DbConn<'a>, options: RegistrationApplicationQuery| async move { let mut query = all_joins(registration_application::table.into_boxed()); + // If viewing all applications, order by newest, but if viewing unresolved only, show the oldest first (FIFO) if options.unread_only { - query = query.filter(registration_application::admin_id.is_null()) + query = query + .filter(registration_application::admin_id.is_null()) + .order_by(registration_application::published.asc()); + } else { + query = query.order_by(registration_application::published.desc()); } if options.verified_email_only { @@ -59,10 +64,7 @@ fn queries<'a>() -> Queries< let (limit, offset) = limit_and_offset(options.page, options.limit)?; - query = query - .limit(limit) - .offset(offset) - .order_by(registration_application::published.asc()); + query = query.limit(limit).offset(offset); query.load::(&mut conn).await }; diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index bd339aabb..9626af84a 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -55,7 +55,7 @@ services: lemmy-ui: # use "image" to pull down an already compiled lemmy-ui. make sure to comment out "build". - image: dessalines/lemmy-ui:0.19.0-rc.3 + image: dessalines/lemmy-ui:0.19.0-rc.8 # platform: linux/x86_64 # no arm64 support. uncomment platform if using m1. # use "build" to build your local lemmy ui image for development. make sure to comment out "image". # run: docker compose up --build