diff --git a/package.json b/package.json index 38d3e21..dfe46ac 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lemmy-js-client", "description": "A javascript / typescript client for Lemmy", - "version": "0.17.0-rc.45", + "version": "0.17.0-rc.46", "author": "Dessalines ", "license": "AGPL-3.0", "main": "./dist/index.js", diff --git a/src/http.ts b/src/http.ts index 50000c4..b3c3975 100644 --- a/src/http.ts +++ b/src/http.ts @@ -45,6 +45,7 @@ import { BlockPersonResponse, ChangePassword, CreatePrivateMessage, + CreatePrivateMessageReport, DeleteAccount, DeleteAccountResponse, DeletePrivateMessage, @@ -62,6 +63,8 @@ import { GetReportCountResponse, GetUnreadCount, GetUnreadCountResponse, + ListPrivateMessageReports, + ListPrivateMessageReportsResponse, Login, LoginResponse, MarkAllAsRead, @@ -72,9 +75,11 @@ import { PasswordReset, PasswordResetResponse, PersonMentionResponse, + PrivateMessageReportResponse, PrivateMessageResponse, PrivateMessagesResponse, Register, + ResolvePrivateMessageReport, SaveUserSettings, VerifyEmail, VerifyEmailResponse, @@ -731,6 +736,48 @@ export class LemmyHttp { ); } + /** + * Create a report for a private message. + * + * `HTTP.POST /private_message/report` + */ + async createPrivateMessageReport(form: CreatePrivateMessageReport) { + return this.wrapper( + HttpType.Post, + "/private_message/report", + form, + PrivateMessageReportResponse + ); + } + + /** + * Resolve a report for a private message. + * + * `HTTP.PUT /private_message/report/resolve` + */ + async resolvePrivateMessageReport(form: ResolvePrivateMessageReport) { + return this.wrapper( + HttpType.Put, + "/private_message/report/resolve", + form, + PrivateMessageReportResponse + ); + } + + /** + * List private message reports. + * + * `HTTP.GET /private_message/report/list` + */ + async listPrivateMessageReports(form: ListPrivateMessageReports) { + return this.wrapper( + HttpType.Get, + "/private_message/report/list", + form, + ListPrivateMessageReportsResponse + ); + } + /** * Register a new user. * diff --git a/src/interfaces/api/person.ts b/src/interfaces/api/person.ts index 7d2b2e4..247ff6b 100644 --- a/src/interfaces/api/person.ts +++ b/src/interfaces/api/person.ts @@ -10,6 +10,7 @@ import { PersonMentionView, PersonViewSafe, PostView, + PrivateMessageReportView, PrivateMessageView, } from "../views"; @@ -529,6 +530,57 @@ export class PrivateMessageResponse { private_message_view: PrivateMessageView; } +export class CreatePrivateMessageReport { + private_message_id: number; + reason: string; + auth: string; + + constructor(init: CreatePrivateMessageReport) { + Object.assign(this, init); + } +} + +export class PrivateMessageReportResponse { + @Type(() => PrivateMessageReportView) + private_message_report_view: PrivateMessageReportView; +} + +export class ResolvePrivateMessageReport { + report_id: number; + resolved: boolean; + auth: string; + + constructor(init: ResolvePrivateMessageReport) { + Object.assign(this, init); + } +} + +export class ListPrivateMessageReports { + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + page: Option; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + limit: Option; + /// Only shows the unresolved reports + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + unresolved_only: Option; + auth: string; + + constructor(init: ListPrivateMessageReports) { + Object.assign(this, init); + } +} + +export class ListPrivateMessageReportsResponse { + @Type(() => PrivateMessageReportView) + private_message_reports: PrivateMessageReportView[]; +} + export class GetReportCount { /** * If a community is supplied, returns the report count for only that community, otherwise returns the report count for all communities the user moderates. @@ -551,6 +603,10 @@ export class GetReportCountResponse { community_id: Option; comment_reports: number; post_reports: number; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + private_message_reports: Option; } export class GetUnreadCount { diff --git a/src/interfaces/api/site.ts b/src/interfaces/api/site.ts index ba7c10e..e1969c7 100644 --- a/src/interfaces/api/site.ts +++ b/src/interfaces/api/site.ts @@ -297,6 +297,9 @@ export class EditSite { @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() application_email_admins: Option; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() hide_modlog_mod_names: Option; auth: string; diff --git a/src/interfaces/others.ts b/src/interfaces/others.ts index ee83480..fd587b6 100644 --- a/src/interfaces/others.ts +++ b/src/interfaces/others.ts @@ -64,6 +64,9 @@ export enum UserOperation { EditPrivateMessage, DeletePrivateMessage, MarkPrivateMessageAsRead, + CreatePrivateMessageReport, + ResolvePrivateMessageReport, + ListPrivateMessageReports, GetPrivateMessages, UserJoin, GetComments, diff --git a/src/interfaces/source.ts b/src/interfaces/source.ts index 68ddd1e..7be32c2 100644 --- a/src/interfaces/source.ts +++ b/src/interfaces/source.ts @@ -500,3 +500,21 @@ export class Language { code: string; name: string; } + +export class PrivateMessageReport { + id: number; + creator_id: number; + private_message_id: number; + original_pm_text: string; + reason: string; + resolved: boolean; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + resolver_id: Option; + published: string; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + updated: Option; +} diff --git a/src/interfaces/views.ts b/src/interfaces/views.ts index b3646fe..8fc6d15 100644 --- a/src/interfaces/views.ts +++ b/src/interfaces/views.ts @@ -35,6 +35,7 @@ import { Post, PostReport, PrivateMessage, + PrivateMessageReport, RegistrationApplication, Site, } from "./source"; @@ -450,3 +451,19 @@ export interface CommentNode { children: CommentNode[]; depth: number; } + +export class PrivateMessageReportView { + @Type(() => PrivateMessageReport) + private_message_report: PrivateMessageReport; + @Type(() => PrivateMessage) + private_message: PrivateMessage; + @Type(() => PersonSafe) + private_message_creator: PersonSafe; + @Type(() => PersonSafe) + creator: PersonSafe; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + @Type(() => PersonSafe) + resolver: Option; +} diff --git a/src/websocket.ts b/src/websocket.ts index 9f9493c..71947be 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -30,6 +30,7 @@ import { BlockPerson, ChangePassword, CreatePrivateMessage, + CreatePrivateMessageReport, DeleteAccount, DeletePrivateMessage, EditPrivateMessage, @@ -40,6 +41,7 @@ import { GetReplies, GetReportCount, GetUnreadCount, + ListPrivateMessageReports, Login, MarkAllAsRead, MarkCommentReplyAsRead, @@ -48,6 +50,7 @@ import { PasswordChange, PasswordReset, Register, + ResolvePrivateMessageReport, SaveUserSettings, VerifyEmail, } from "./interfaces/api/person"; @@ -618,6 +621,27 @@ export class LemmyWebsocket { return wrapper(UserOperation.GetPrivateMessages, form); } + /** + * Create a report for a private message. + */ + createPrivateMessageReport(form: CreatePrivateMessageReport) { + return wrapper(UserOperation.CreatePrivateMessageReport, form); + } + + /** + * Resolve a report for a private message. + */ + resolvePrivateMessageReport(form: ResolvePrivateMessageReport) { + return wrapper(UserOperation.ResolvePrivateMessageReport, form); + } + + /** + * List private message reports. + */ + listPrivateMessageReports(form: ListPrivateMessageReports) { + return wrapper(UserOperation.ListPrivateMessageReports, form); + } + /** * Block a person. */