From 7758a7772e4f1d3af43def7fb4eb83122af93aa5 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 28 Sep 2021 06:38:49 -0400 Subject: [PATCH] Updating reporting API. (#32) * Updating reporting API. * v0.12.3-rc.1 * Fix names * v0.12.3-rc.2 * Adding creator_banned and counts to report views * v0.12.3-rc.3 * Adding unresolved_only * v0.12.3-rc.4 * Adding my_vote to report views * v0.12.3-rc.5 * Fix comment --- package.json | 2 +- src/http.ts | 71 +++++++++++++++++++++++++++++++++++ src/interfaces/api/comment.ts | 22 ++++++----- src/interfaces/api/person.ts | 10 ++--- src/interfaces/api/post.ts | 23 +++++++----- src/interfaces/others.ts | 7 ++++ src/interfaces/views.ts | 6 +++ src/websocket.ts | 56 +++++++++++++++++++++++++++ 8 files changed, 172 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 79b35ea..8129a55 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lemmy-js-client", "description": "A javascript / typescript client for Lemmy", - "version": "0.12.0", + "version": "0.12.3-rc.5", "author": "Dessalines ", "license": "AGPL-3.0", "main": "./dist/index.js", diff --git a/src/http.ts b/src/http.ts index f305944..22e8d9f 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1,14 +1,19 @@ import fetch from 'node-fetch'; import { + CommentReportResponse, CommentResponse, CreateComment, CreateCommentLike, + CreateCommentReport, DeleteComment, EditComment, GetComments, GetCommentsResponse, + ListCommentReports, + ListCommentReportsResponse, MarkCommentAsRead, RemoveComment, + ResolveCommentReport, SaveComment, } from './interfaces/api/comment'; import { @@ -42,10 +47,15 @@ import { GetSiteMetadata, GetSiteMetadataResponse, LockPost, + CreatePostReport, + PostReportResponse, PostResponse, RemovePost, SavePost, StickyPost, + ResolvePostReport, + ListPostReports, + ListPostReportsResponse, } from './interfaces/api/post'; import { CreateSite, @@ -97,6 +107,8 @@ import { PersonMentionResponse, BlockPerson, BlockPersonResponse, + GetReportCount, + GetReportCountResponse, } from './interfaces/api/person'; import { VERSION } from './interfaces/others'; @@ -345,6 +357,31 @@ export class LemmyHttp { return this.wrapper(HttpType.Put, '/post/save', form); } + /** + * Report a post. + */ + async createPostReport(form: CreatePostReport): Promise { + return this.wrapper(HttpType.Post, '/post/report', form); + } + + /** + * Resolve a post report. Only a mod can do this. + */ + async resolvePostReport( + form: ResolvePostReport + ): Promise { + return this.wrapper(HttpType.Put, '/post/report/resolve', form); + } + + /** + * List post reports. + */ + async listPostReports( + form: ListPostReports + ): Promise { + return this.wrapper(HttpType.Get, '/post/report/list', form); + } + /** * Fetch metadata for any given site. */ @@ -410,6 +447,33 @@ export class LemmyHttp { return this.wrapper(HttpType.Get, '/comment/list', form); } + /** + * Report a comment. + */ + async createCommentReport( + form: CreateCommentReport + ): Promise { + return this.wrapper(HttpType.Post, '/comment/report', form); + } + + /** + * Resolve a comment report. Only a mod can do this. + */ + async resolveCommentReport( + form: ResolveCommentReport + ): Promise { + return this.wrapper(HttpType.Put, '/comment/report/resolve', form); + } + + /** + * List comment reports. + */ + async listCommentReports( + form: ListCommentReports + ): Promise { + return this.wrapper(HttpType.Get, '/comment/report/list', form); + } + /** * Get / fetch private messages. */ @@ -566,6 +630,13 @@ export class LemmyHttp { return this.wrapper(HttpType.Put, '/user/change_password', form); } + /** + * Get counts for your reports + */ + async getReportCount(form: GetReportCount): Promise { + return this.wrapper(HttpType.Get, '/user/report_count', form); + } + /** * Add an admin to your site. */ diff --git a/src/interfaces/api/comment.ts b/src/interfaces/api/comment.ts index d042116..2a5c77e 100644 --- a/src/interfaces/api/comment.ts +++ b/src/interfaces/api/comment.ts @@ -103,32 +103,34 @@ export interface CreateCommentReport { auth: string; } -export interface CreateCommentReportResponse { - success: boolean; +export interface CommentReportResponse { + comment_report_view: CommentReportView; } export interface ResolveCommentReport { report_id: number; + /** + * Either resolve or unresolve a report. + */ resolved: boolean; auth: string; } -export interface ResolveCommentReportResponse { - // TODO this should probably return the view - report_id: number; - resolved: boolean; -} - export interface ListCommentReports { page?: number; limit?: number; /** * if no community is given, it returns reports for all communities moderated by the auth user. */ - community?: number; + community_id?: number; + + /** + * Only shows the unresolved reports. + */ + unresolved_only?: boolean; auth: string; } export interface ListCommentReportsResponse { - comments: CommentReportView[]; + comment_reports: CommentReportView[]; } diff --git a/src/interfaces/api/person.ts b/src/interfaces/api/person.ts index 05d69c0..c023f0c 100644 --- a/src/interfaces/api/person.ts +++ b/src/interfaces/api/person.ts @@ -260,16 +260,16 @@ export interface PrivateMessageResponse { private_message_view: PrivateMessageView; } -/** - * If a community is supplied, returns the report count for only that community, otherwise returns the report count for all communities the user moderates. - */ export interface GetReportCount { - community?: number; + /** + * If a community is supplied, returns the report count for only that community, otherwise returns the report count for all communities the user moderates. + */ + community_id?: number; auth: string; } export interface GetReportCountResponse { - community?: number; + community_id?: number; comment_reports: number; post_reports: number; } diff --git a/src/interfaces/api/post.ts b/src/interfaces/api/post.ts index 99dbc9c..0a52422 100644 --- a/src/interfaces/api/post.ts +++ b/src/interfaces/api/post.ts @@ -124,30 +124,35 @@ export interface CreatePostReport { auth: string; } -export interface CreatePostReportResponse { - success: boolean; +export interface PostReportResponse { + post_report_view: PostReportView; } export interface ResolvePostReport { report_id: number; + /** + * Either resolve or unresolve a report. + */ resolved: boolean; auth: string; } -export interface ResolvePostReportResponse { - report_id: number; - resolved: boolean; -} - export interface ListPostReports { page?: number; limit?: number; - community?: number; + /** + * if no community is given, it returns reports for all communities moderated by the auth user. + */ + community_id?: number; + /** + * Only shows the unresolved reports. + */ + unresolved_only?: boolean; auth: string; } export interface ListPostReportsResponse { - posts: PostReportView[]; + post_reports: PostReportView[]; } export interface GetSiteMetadata { diff --git a/src/interfaces/others.ts b/src/interfaces/others.ts index 2d381a9..4af1fe6 100644 --- a/src/interfaces/others.ts +++ b/src/interfaces/others.ts @@ -67,6 +67,13 @@ export enum UserOperation { GetSiteMetadata, BlockCommunity, BlockPerson, + CreateCommentReport, + ResolveCommentReport, + ListCommentReports, + CreatePostReport, + ResolvePostReport, + ListPostReports, + GetReportCount, } /** diff --git a/src/interfaces/views.ts b/src/interfaces/views.ts index d18de8f..7ffa61e 100644 --- a/src/interfaces/views.ts +++ b/src/interfaces/views.ts @@ -85,6 +85,9 @@ export interface PostReportView { community: CommunitySafe; creator: PersonSafe; post_creator: PersonSafe; + creator_banned_from_community: boolean; + my_vote?: number; + counts: PostAggregates; resolver?: PersonSafe; } @@ -109,6 +112,9 @@ export interface CommentReportView { community: CommunitySafe; creator: PersonSafe; comment_creator: PersonSafe; + counts: CommentAggregates; + creator_banned_from_community: boolean; + my_vote?: number; resolver?: PersonSafe; } diff --git a/src/websocket.ts b/src/websocket.ts index 8e40545..829cefe 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -1,11 +1,14 @@ import { CreateComment, CreateCommentLike, + CreateCommentReport, DeleteComment, EditComment, GetComments, + ListCommentReports, MarkCommentAsRead, RemoveComment, + ResolveCommentReport, SaveComment, } from './interfaces/api/comment'; import { @@ -24,13 +27,16 @@ import { import { CreatePost, CreatePostLike, + CreatePostReport, DeletePost, EditPost, GetPost, GetPosts, GetSiteMetadata, + ListPostReports, LockPost, RemovePost, + ResolvePostReport, SavePost, StickyPost, } from './interfaces/api/post'; @@ -66,6 +72,7 @@ import { SaveUserSettings, ChangePassword, BlockPerson, + GetReportCount, } from './interfaces/api/person'; import { UserJoin, PostJoin, CommunityJoin } from './interfaces/api/websocket'; import { UserOperation } from './interfaces/others'; @@ -242,6 +249,27 @@ export class LemmyWebsocket { return wrapper(UserOperation.SaveComment, form); } + /** + * Report a comment. + */ + createCommentReport(form: CreateCommentReport) { + return wrapper(UserOperation.CreateCommentReport, form); + } + + /** + * Resolve a comment report. Only a mod can do this. + */ + resolveCommentReport(form: ResolveCommentReport) { + return wrapper(UserOperation.ResolveCommentReport, form); + } + + /** + * List comment reports. + */ + listCommentReports(form: ListCommentReports) { + return wrapper(UserOperation.ListCommentReports, form); + } + /** * Get / fetch posts, with various filters. */ @@ -305,6 +333,27 @@ export class LemmyWebsocket { return wrapper(UserOperation.SavePost, form); } + /** + * Report a post. + */ + createPostReport(form: CreatePostReport) { + return wrapper(UserOperation.CreatePostReport, form); + } + + /** + * Resolve a post report. Only a mod can do this. + */ + resolvePostReport(form: ResolvePostReport) { + return wrapper(UserOperation.ResolvePostReport, form); + } + + /** + * List post reports. + */ + listPostReports(form: ListPostReports) { + return wrapper(UserOperation.ListPostReports, form); + } + /** * Fetch metadata for any given site. */ @@ -452,6 +501,13 @@ export class LemmyWebsocket { return wrapper(UserOperation.ChangePassword, form); } + /** + * Get counts for your reports + */ + getReportCount(form: GetReportCount) { + return wrapper(UserOperation.GetReportCount, form); + } + /** * Delete your account. */