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
This commit is contained in:
Dessalines 2021-09-28 06:38:49 -04:00 committed by GitHub
parent 69d84445f8
commit 7758a7772e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 172 additions and 25 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "lemmy-js-client", "name": "lemmy-js-client",
"description": "A javascript / typescript client for Lemmy", "description": "A javascript / typescript client for Lemmy",
"version": "0.12.0", "version": "0.12.3-rc.5",
"author": "Dessalines <tyhou13@gmx.com>", "author": "Dessalines <tyhou13@gmx.com>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "./dist/index.js", "main": "./dist/index.js",

View file

@ -1,14 +1,19 @@
import fetch from 'node-fetch'; import fetch from 'node-fetch';
import { import {
CommentReportResponse,
CommentResponse, CommentResponse,
CreateComment, CreateComment,
CreateCommentLike, CreateCommentLike,
CreateCommentReport,
DeleteComment, DeleteComment,
EditComment, EditComment,
GetComments, GetComments,
GetCommentsResponse, GetCommentsResponse,
ListCommentReports,
ListCommentReportsResponse,
MarkCommentAsRead, MarkCommentAsRead,
RemoveComment, RemoveComment,
ResolveCommentReport,
SaveComment, SaveComment,
} from './interfaces/api/comment'; } from './interfaces/api/comment';
import { import {
@ -42,10 +47,15 @@ import {
GetSiteMetadata, GetSiteMetadata,
GetSiteMetadataResponse, GetSiteMetadataResponse,
LockPost, LockPost,
CreatePostReport,
PostReportResponse,
PostResponse, PostResponse,
RemovePost, RemovePost,
SavePost, SavePost,
StickyPost, StickyPost,
ResolvePostReport,
ListPostReports,
ListPostReportsResponse,
} from './interfaces/api/post'; } from './interfaces/api/post';
import { import {
CreateSite, CreateSite,
@ -97,6 +107,8 @@ import {
PersonMentionResponse, PersonMentionResponse,
BlockPerson, BlockPerson,
BlockPersonResponse, BlockPersonResponse,
GetReportCount,
GetReportCountResponse,
} from './interfaces/api/person'; } from './interfaces/api/person';
import { VERSION } from './interfaces/others'; import { VERSION } from './interfaces/others';
@ -345,6 +357,31 @@ export class LemmyHttp {
return this.wrapper(HttpType.Put, '/post/save', form); return this.wrapper(HttpType.Put, '/post/save', form);
} }
/**
* Report a post.
*/
async createPostReport(form: CreatePostReport): Promise<PostReportResponse> {
return this.wrapper(HttpType.Post, '/post/report', form);
}
/**
* Resolve a post report. Only a mod can do this.
*/
async resolvePostReport(
form: ResolvePostReport
): Promise<PostReportResponse> {
return this.wrapper(HttpType.Put, '/post/report/resolve', form);
}
/**
* List post reports.
*/
async listPostReports(
form: ListPostReports
): Promise<ListPostReportsResponse> {
return this.wrapper(HttpType.Get, '/post/report/list', form);
}
/** /**
* Fetch metadata for any given site. * Fetch metadata for any given site.
*/ */
@ -410,6 +447,33 @@ export class LemmyHttp {
return this.wrapper(HttpType.Get, '/comment/list', form); return this.wrapper(HttpType.Get, '/comment/list', form);
} }
/**
* Report a comment.
*/
async createCommentReport(
form: CreateCommentReport
): Promise<CommentReportResponse> {
return this.wrapper(HttpType.Post, '/comment/report', form);
}
/**
* Resolve a comment report. Only a mod can do this.
*/
async resolveCommentReport(
form: ResolveCommentReport
): Promise<CommentReportResponse> {
return this.wrapper(HttpType.Put, '/comment/report/resolve', form);
}
/**
* List comment reports.
*/
async listCommentReports(
form: ListCommentReports
): Promise<ListCommentReportsResponse> {
return this.wrapper(HttpType.Get, '/comment/report/list', form);
}
/** /**
* Get / fetch private messages. * Get / fetch private messages.
*/ */
@ -566,6 +630,13 @@ export class LemmyHttp {
return this.wrapper(HttpType.Put, '/user/change_password', form); return this.wrapper(HttpType.Put, '/user/change_password', form);
} }
/**
* Get counts for your reports
*/
async getReportCount(form: GetReportCount): Promise<GetReportCountResponse> {
return this.wrapper(HttpType.Get, '/user/report_count', form);
}
/** /**
* Add an admin to your site. * Add an admin to your site.
*/ */

View file

@ -103,32 +103,34 @@ export interface CreateCommentReport {
auth: string; auth: string;
} }
export interface CreateCommentReportResponse { export interface CommentReportResponse {
success: boolean; comment_report_view: CommentReportView;
} }
export interface ResolveCommentReport { export interface ResolveCommentReport {
report_id: number; report_id: number;
/**
* Either resolve or unresolve a report.
*/
resolved: boolean; resolved: boolean;
auth: string; auth: string;
} }
export interface ResolveCommentReportResponse {
// TODO this should probably return the view
report_id: number;
resolved: boolean;
}
export interface ListCommentReports { export interface ListCommentReports {
page?: number; page?: number;
limit?: number; limit?: number;
/** /**
* if no community is given, it returns reports for all communities moderated by the auth user. * 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; auth: string;
} }
export interface ListCommentReportsResponse { export interface ListCommentReportsResponse {
comments: CommentReportView[]; comment_reports: CommentReportView[];
} }

View file

@ -260,16 +260,16 @@ export interface PrivateMessageResponse {
private_message_view: PrivateMessageView; 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 { 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; auth: string;
} }
export interface GetReportCountResponse { export interface GetReportCountResponse {
community?: number; community_id?: number;
comment_reports: number; comment_reports: number;
post_reports: number; post_reports: number;
} }

View file

@ -124,30 +124,35 @@ export interface CreatePostReport {
auth: string; auth: string;
} }
export interface CreatePostReportResponse { export interface PostReportResponse {
success: boolean; post_report_view: PostReportView;
} }
export interface ResolvePostReport { export interface ResolvePostReport {
report_id: number; report_id: number;
/**
* Either resolve or unresolve a report.
*/
resolved: boolean; resolved: boolean;
auth: string; auth: string;
} }
export interface ResolvePostReportResponse {
report_id: number;
resolved: boolean;
}
export interface ListPostReports { export interface ListPostReports {
page?: number; page?: number;
limit?: 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; auth: string;
} }
export interface ListPostReportsResponse { export interface ListPostReportsResponse {
posts: PostReportView[]; post_reports: PostReportView[];
} }
export interface GetSiteMetadata { export interface GetSiteMetadata {

View file

@ -67,6 +67,13 @@ export enum UserOperation {
GetSiteMetadata, GetSiteMetadata,
BlockCommunity, BlockCommunity,
BlockPerson, BlockPerson,
CreateCommentReport,
ResolveCommentReport,
ListCommentReports,
CreatePostReport,
ResolvePostReport,
ListPostReports,
GetReportCount,
} }
/** /**

View file

@ -85,6 +85,9 @@ export interface PostReportView {
community: CommunitySafe; community: CommunitySafe;
creator: PersonSafe; creator: PersonSafe;
post_creator: PersonSafe; post_creator: PersonSafe;
creator_banned_from_community: boolean;
my_vote?: number;
counts: PostAggregates;
resolver?: PersonSafe; resolver?: PersonSafe;
} }
@ -109,6 +112,9 @@ export interface CommentReportView {
community: CommunitySafe; community: CommunitySafe;
creator: PersonSafe; creator: PersonSafe;
comment_creator: PersonSafe; comment_creator: PersonSafe;
counts: CommentAggregates;
creator_banned_from_community: boolean;
my_vote?: number;
resolver?: PersonSafe; resolver?: PersonSafe;
} }

View file

@ -1,11 +1,14 @@
import { import {
CreateComment, CreateComment,
CreateCommentLike, CreateCommentLike,
CreateCommentReport,
DeleteComment, DeleteComment,
EditComment, EditComment,
GetComments, GetComments,
ListCommentReports,
MarkCommentAsRead, MarkCommentAsRead,
RemoveComment, RemoveComment,
ResolveCommentReport,
SaveComment, SaveComment,
} from './interfaces/api/comment'; } from './interfaces/api/comment';
import { import {
@ -24,13 +27,16 @@ import {
import { import {
CreatePost, CreatePost,
CreatePostLike, CreatePostLike,
CreatePostReport,
DeletePost, DeletePost,
EditPost, EditPost,
GetPost, GetPost,
GetPosts, GetPosts,
GetSiteMetadata, GetSiteMetadata,
ListPostReports,
LockPost, LockPost,
RemovePost, RemovePost,
ResolvePostReport,
SavePost, SavePost,
StickyPost, StickyPost,
} from './interfaces/api/post'; } from './interfaces/api/post';
@ -66,6 +72,7 @@ import {
SaveUserSettings, SaveUserSettings,
ChangePassword, ChangePassword,
BlockPerson, BlockPerson,
GetReportCount,
} from './interfaces/api/person'; } from './interfaces/api/person';
import { UserJoin, PostJoin, CommunityJoin } from './interfaces/api/websocket'; import { UserJoin, PostJoin, CommunityJoin } from './interfaces/api/websocket';
import { UserOperation } from './interfaces/others'; import { UserOperation } from './interfaces/others';
@ -242,6 +249,27 @@ export class LemmyWebsocket {
return wrapper(UserOperation.SaveComment, form); 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. * Get / fetch posts, with various filters.
*/ */
@ -305,6 +333,27 @@ export class LemmyWebsocket {
return wrapper(UserOperation.SavePost, form); 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. * Fetch metadata for any given site.
*/ */
@ -452,6 +501,13 @@ export class LemmyWebsocket {
return wrapper(UserOperation.ChangePassword, form); return wrapper(UserOperation.ChangePassword, form);
} }
/**
* Get counts for your reports
*/
getReportCount(form: GetReportCount) {
return wrapper(UserOperation.GetReportCount, form);
}
/** /**
* Delete your account. * Delete your account.
*/ */