diff --git a/packages/backend/src/misc/schema.ts b/packages/backend/src/misc/schema.ts index c793d3b2ed..73600832ce 100644 --- a/packages/backend/src/misc/schema.ts +++ b/packages/backend/src/misc/schema.ts @@ -33,8 +33,10 @@ import { packedGalleryPostSchema } from "@/models/schema/gallery-post.js"; import { packedEmojiSchema } from "@/models/schema/emoji.js"; import { packedNoteEdit } from "@/models/schema/note-edit.js"; import { packedNoteFileSchema } from "@/models/schema/note-file.js"; +import { packedAbuseUserReportSchema } from "@/models/schema/abuse-user-report.js"; export const refs = { + AbuseUserReport: packedAbuseUserReportSchema, UserLite: packedUserLiteSchema, UserDetailedNotMeOnly: packedUserDetailedNotMeOnlySchema, MeDetailedOnly: packedMeDetailedOnlySchema, diff --git a/packages/backend/src/models/repositories/abuse-user-report.ts b/packages/backend/src/models/repositories/abuse-user-report.ts index 16ce159955..b8d953d052 100644 --- a/packages/backend/src/models/repositories/abuse-user-report.ts +++ b/packages/backend/src/models/repositories/abuse-user-report.ts @@ -2,6 +2,7 @@ import { db } from "@/db/postgre.js"; import { Users } from "../index.js"; import { AbuseUserReport } from "@/models/entities/abuse-user-report.js"; import { awaitAll } from "@/prelude/await-all.js"; +import type { Packed } from "@/misc/schema.js"; export const AbuseUserReportRepository = db .getRepository(AbuseUserReport) @@ -10,7 +11,7 @@ export const AbuseUserReportRepository = db const report = typeof src === "object" ? src : await this.findOneByOrFail({ id: src }); - return await awaitAll({ + const packed: Packed<"AbuseUserReport"> = await awaitAll({ id: report.id, createdAt: report.createdAt.toISOString(), comment: report.comment, @@ -31,9 +32,10 @@ export const AbuseUserReportRepository = db : null, forwarded: report.forwarded, }); + return packed; }, - packMany(reports: any[]) { + packMany(reports: (AbuseUserReport["id"] | AbuseUserReport)[]) { return Promise.all(reports.map((x) => this.pack(x))); }, }); diff --git a/packages/backend/src/models/schema/abuse-user-report.ts b/packages/backend/src/models/schema/abuse-user-report.ts new file mode 100644 index 0000000000..47e56c7415 --- /dev/null +++ b/packages/backend/src/models/schema/abuse-user-report.ts @@ -0,0 +1,69 @@ +export const packedAbuseUserReportSchema = { + type: "object", + properties: { + id: { + type: "string", + optional: false, + nullable: false, + format: "id", + example: "xxxxxxxxxx", + }, + createdAt: { + type: "string", + optional: false, + nullable: false, + format: "date-time", + }, + comment: { + type: "string", + optional: false, + nullable: false, + }, + resolved: { + type: "boolean", + optional: false, + nullable: false, + }, + reporterId: { + type: "string", + optional: false, + nullable: false, + format: "id", + }, + targetUserId: { + type: "string", + optional: false, + nullable: false, + format: "id", + }, + assigneeId: { + type: "string", + optional: false, + nullable: true, + format: "id", + }, + reporter: { + type: "object", + optional: false, + nullable: false, + ref: "UserDetailed", + }, + targetUser: { + type: "object", + optional: false, + nullable: false, + ref: "UserDetailed", + }, + assignee: { + type: "object", + optional: true, + nullable: true, + ref: "UserDetailed", + }, + forwarded: { + type: "boolean", + optional: false, + nullable: false, + }, + }, +} as const; diff --git a/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts b/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts index 78034917f0..4063af5c5c 100644 --- a/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts +++ b/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts @@ -16,68 +16,7 @@ export const meta = { type: "object", optional: false, nullable: false, - properties: { - id: { - type: "string", - nullable: false, - optional: false, - format: "id", - example: "xxxxxxxxxx", - }, - createdAt: { - type: "string", - nullable: false, - optional: false, - format: "date-time", - }, - comment: { - type: "string", - nullable: false, - optional: false, - }, - resolved: { - type: "boolean", - nullable: false, - optional: false, - example: false, - }, - reporterId: { - type: "string", - nullable: false, - optional: false, - format: "id", - }, - targetUserId: { - type: "string", - nullable: false, - optional: false, - format: "id", - }, - assigneeId: { - type: "string", - nullable: true, - optional: false, - format: "id", - }, - reporter: { - type: "object", - nullable: false, - optional: false, - ref: "User", - }, - targetUser: { - type: "object", - nullable: false, - optional: false, - ref: "User", - }, - assignee: { - type: "object", - nullable: true, - optional: true, - ref: "User", - }, - }, + ref: "AbuseUserReport", }, }, } as const; diff --git a/packages/client/src/components/MkAbuseReport.vue b/packages/client/src/components/MkAbuseReport.vue index 5536523948..26b91fae2e 100644 --- a/packages/client/src/components/MkAbuseReport.vue +++ b/packages/client/src/components/MkAbuseReport.vue @@ -72,13 +72,14 @@ import MkSwitch from "@/components/form/switch.vue"; import MkKeyValue from "@/components/MkKeyValue.vue"; import * as os from "@/os"; import { i18n } from "@/i18n"; +import type { entities } from "firefish-js"; const props = defineProps<{ - report: any; + report: entities.AbuseUserReport; }>(); const emit = defineEmits<{ - (ev: "resolved", reportId: string): void; + resolved: [reportId: string]; }>(); const forward = ref(props.report.forwarded); diff --git a/packages/client/src/pages/admin/abuses.vue b/packages/client/src/pages/admin/abuses.vue index 174b4d5713..f94e24cf7c 100644 --- a/packages/client/src/pages/admin/abuses.vue +++ b/packages/client/src/pages/admin/abuses.vue @@ -99,12 +99,13 @@ import XAbuseReport from "@/components/MkAbuseReport.vue"; import { i18n } from "@/i18n"; import { definePageMetadata } from "@/scripts/page-metadata"; import icon from "@/scripts/icon"; +import type { entities } from "firefish-js"; const reports = ref>(); const state = ref("unresolved"); -const reporterOrigin = ref("combined"); -const targetUserOrigin = ref("combined"); +const reporterOrigin = ref("combined"); +const targetUserOrigin = ref("combined"); // const searchUsername = ref(""); // const searchHost = ref(""); diff --git a/packages/firefish-js/src/api.types.ts b/packages/firefish-js/src/api.types.ts index d3564573f0..81e9a4a72c 100644 --- a/packages/firefish-js/src/api.types.ts +++ b/packages/firefish-js/src/api.types.ts @@ -1,4 +1,5 @@ import type { + AbuseUserReport, Ad, Announcement, Antenna, @@ -68,7 +69,18 @@ type NoteSubmitReq = { export type Endpoints = { // admin - "admin/abuse-user-reports": { req: TODO; res: TODO }; + "admin/abuse-user-reports": { + req: { + limit?: number; + sinceId?: AbuseUserReport["id"]; + untilId?: AbuseUserReport["id"]; + state?: string; + reporterOrigin?: OriginType; + targetUserOrigin?: OriginType; + forwarded?: boolean; + }; + res: AbuseUserReport[]; + }; "admin/delete-all-files-of-a-user": { req: { userId: User["id"] }; res: null; diff --git a/packages/firefish-js/src/entities.ts b/packages/firefish-js/src/entities.ts index ce940a1481..8501d6c51f 100644 --- a/packages/firefish-js/src/entities.ts +++ b/packages/firefish-js/src/entities.ts @@ -18,10 +18,7 @@ export type UserLite = { avatarBlurhash: string; alsoKnownAs: string[]; movedToUri: any; - emojis: { - name: string; - url: string; - }[]; + emojis: EmojiLite[]; instance?: { name: Instance["name"]; softwareName: Instance["softwareName"]; @@ -171,10 +168,7 @@ export type Note = { votes: number; }[]; }; - emojis: { - name: string; - url: string; - }[]; + emojis: EmojiLite[]; uri?: string; url?: string; updatedAt?: DateString; @@ -191,10 +185,7 @@ export type NoteEdit = { updatedAt: string; fileIds: DriveFile["id"][]; files: DriveFile[]; - emojis: { - name: string; - url: string; - }[]; + emojis: EmojiLite[]; }; export type NoteReaction = { @@ -325,6 +316,8 @@ export type EmojiLite = { id: string; name: string; url: string; + width: number | null; + height: number | null; }; export type LiteInstanceMetadata = { @@ -547,3 +540,17 @@ export type UserSorting = | "+updatedAt" | "-updatedAt"; export type OriginType = "combined" | "local" | "remote"; + +export type AbuseUserReport = { + id: string; + createdAt: DateString; + comment: string; + resolved: boolean; + reporterId: User["id"]; + targetUserId: User["id"]; + assigneeId: User["id"] | null; + reporter: UserDetailed; + targetUser: UserDetailed; + assignee?: UserDetailed | null; + forwarded: boolean; +};