Addressing PR comments.

This commit is contained in:
Dessalines 2024-12-04 12:48:41 -05:00
parent e1affa8696
commit 921d53227c
4 changed files with 33 additions and 30 deletions

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -148,7 +148,6 @@ impl ReportCombinedQuery {
pool: &mut DbPool<'_>,
user: &LocalUserView,
) -> LemmyResult<Vec<ReportCombinedView>> {
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

View file

@ -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,