diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index 94404f449..adcfa8a0b 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -43,6 +43,7 @@ import { CommentReportView, CommentView, CommunityView, + ReportCombinedView, SaveUserSettings, } from "lemmy-js-client"; @@ -806,12 +807,7 @@ test("Report a comment", async () => { () => listReports(beta).then(p => p.reports.find(r => { - switch (r.type_) { - case "Comment": - return r.comment_report.reason === reason; - default: - return false; - } + return checkCommentReportReason(r, reason); }), ), e => !!e, @@ -891,3 +887,12 @@ test.skip("Fetch a deeply nested comment", async () => { expect(betaComment!.comment!.comment).toBeDefined(); expect(betaComment?.comment?.post).toBeDefined(); }); + +function checkCommentReportReason(rcv: ReportCombinedView, reason: string) { + switch (rcv.type_) { + case "Comment": + return rcv.comment_report.reason === reason; + default: + return false; + } +} diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index 7dd7dd483..7fbd8d0bc 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -41,7 +41,13 @@ import { } from "./shared"; import { PostView } from "lemmy-js-client/dist/types/PostView"; import { AdminBlockInstanceParams } from "lemmy-js-client/dist/types/AdminBlockInstanceParams"; -import { EditSite, PostReportView, ResolveObject } from "lemmy-js-client"; +import { + EditSite, + PostReport, + PostReportView, + ReportCombinedView, + ResolveObject, +} from "lemmy-js-client"; let betaCommunity: CommunityView | undefined; @@ -695,15 +701,7 @@ test("Report a post", async () => { () => listReports(beta).then(p => p.reports.find(r => { - switch (r.type_) { - case "Post": - return ( - r.post_report.original_post_name === - gammaReport.original_post_name - ); - default: - return false; - } + return checkReportName(r, gammaReport); }), ), res => !!res, @@ -837,3 +835,12 @@ test("Rewrite markdown links", async () => { `[link](http://lemmy-alpha:8541/post/${alphaPost1.post?.post.id})`, ); }); + +function checkReportName(rcv: ReportCombinedView, report: PostReport) { + switch (rcv.type_) { + case "Post": + return rcv.post_report.original_post_name === report.original_post_name; + default: + return false; + } +} diff --git a/crates/db_views/src/report_combined_view.rs b/crates/db_views/src/report_combined_view.rs index b1232940f..5944568e0 100644 --- a/crates/db_views/src/report_combined_view.rs +++ b/crates/db_views/src/report_combined_view.rs @@ -148,7 +148,6 @@ impl ReportCombinedQuery { pool: &mut DbPool<'_>, user: &LocalUserView, ) -> LemmyResult> { - let options = self; let my_person_id = user.local_user.person_id; let item_creator = aliases::person1.field(person::id); @@ -283,7 +282,7 @@ impl ReportCombinedQuery { )) .into_boxed(); - if let Some(community_id) = options.community_id { + if let Some(community_id) = self.community_id { query = query.filter(community::id.eq(community_id)); } @@ -294,9 +293,9 @@ impl ReportCombinedQuery { let mut query = PaginatedQueryBuilder::new(query); - let page_after = options.page_after.map(|c| c.0); + let page_after = self.page_after.map(|c| c.0); - if options.page_back.unwrap_or_default() { + if self.page_back.unwrap_or_default() { query = query.before(page_after).limit_and_offset_from_end(); } else { query = query.after(page_after); @@ -304,7 +303,7 @@ impl ReportCombinedQuery { // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest // first (FIFO) - if options.unresolved_only.unwrap_or_default() { + if self.unresolved_only.unwrap_or_default() { query = query .filter( post_report::resolved diff --git a/migrations/2024-12-02-181601_add_report_combined_table/up.sql b/migrations/2024-12-02-181601_add_report_combined_table/up.sql index 3b92dab93..40dd9b277 100644 --- a/migrations/2024-12-02-181601_add_report_combined_table/up.sql +++ b/migrations/2024-12-02-181601_add_report_combined_table/up.sql @@ -1,13 +1,5 @@ --- Creates combined tables for the following: --- +-- Creates combined tables for -- Reports: (comment, post, and private_message) --- Inbox: (Comment replies, post replies, comment mentions, post mentions, private messages) --- Profile: (Posts and Comments) --- Modlog: (lots of types) --- Search: (community, post, comment, user, url) --- TODO not sure about these two: --- Home: (comment, post) --- Community: (comment, post) CREATE TABLE report_combined ( id serial PRIMARY KEY, published timestamptz NOT NULL,