mirror of
https://github.com/LemmyNet/lemmy-js-client.git
synced 2024-11-25 22:01:12 +00:00
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:
parent
69d84445f8
commit
7758a7772e
8 changed files with 172 additions and 25 deletions
|
@ -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 <tyhou13@gmx.com>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "./dist/index.js",
|
||||
|
|
71
src/http.ts
71
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<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.
|
||||
*/
|
||||
|
@ -410,6 +447,33 @@ export class LemmyHttp {
|
|||
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.
|
||||
*/
|
||||
|
@ -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<GetReportCountResponse> {
|
||||
return this.wrapper(HttpType.Get, '/user/report_count', form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an admin to your site.
|
||||
*/
|
||||
|
|
|
@ -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[];
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -67,6 +67,13 @@ export enum UserOperation {
|
|||
GetSiteMetadata,
|
||||
BlockCommunity,
|
||||
BlockPerson,
|
||||
CreateCommentReport,
|
||||
ResolveCommentReport,
|
||||
ListCommentReports,
|
||||
CreatePostReport,
|
||||
ResolvePostReport,
|
||||
ListPostReports,
|
||||
GetReportCount,
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue