mirror of
https://github.com/LemmyNet/lemmy-js-client.git
synced 2024-11-26 14:21:12 +00:00
Adding rust-style Options using @sniptt/monads
- Also added serialization with class-transformer
This commit is contained in:
parent
b2bd89c105
commit
052ea66973
15 changed files with 2438 additions and 652 deletions
|
@ -16,16 +16,17 @@
|
|||
},
|
||||
"repository": "https://github.com/LemmyNet/lemmy-js-client",
|
||||
"devDependencies": {
|
||||
"@sniptt/monads": "^0.5.10",
|
||||
"@types/node": "^17.0.33",
|
||||
"@types/node-fetch": "^3.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.23.0",
|
||||
"@typescript-eslint/parser": "^5.23.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"eslint": "^8.15.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"husky": "^8.0.1",
|
||||
"lint-staged": "^12.4.1",
|
||||
"node-fetch": "^3.2.4",
|
||||
"option-t": "^32.2.0",
|
||||
"prettier": "^2.6.2",
|
||||
"prettier-plugin-import-sort": "^0.0.7",
|
||||
"prettier-plugin-organize-imports": "^2.3.4",
|
||||
|
|
669
src/http.ts
669
src/http.ts
File diff suppressed because it is too large
Load diff
|
@ -1,3 +1,4 @@
|
|||
export * from "./http";
|
||||
export * from "./interfaces";
|
||||
export * from "./utils";
|
||||
export * from "./websocket";
|
||||
|
|
|
@ -1,74 +1,154 @@
|
|||
import { Option, Some } from "@sniptt/monads";
|
||||
import { Expose, Transform } from "class-transformer";
|
||||
import { toUndefined } from "../../utils";
|
||||
import { ListingType, SortType } from "../others";
|
||||
import { CommentReportView, CommentView } from "../views";
|
||||
|
||||
export interface CreateComment {
|
||||
export class CreateComment {
|
||||
content: string;
|
||||
parent_id?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
parent_id: Option<number>;
|
||||
post_id: number;
|
||||
/**
|
||||
* An optional front end ID, to tell which is comment is coming back.
|
||||
*/
|
||||
form_id?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
form_id: Option<string>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
content: string,
|
||||
parent_id: Option<number>,
|
||||
post_id: number,
|
||||
form_id: Option<string>,
|
||||
auth: string
|
||||
) {
|
||||
this.content = content;
|
||||
this.parent_id = parent_id;
|
||||
this.post_id = post_id;
|
||||
this.form_id = form_id;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface EditComment {
|
||||
export class EditComment {
|
||||
content: string;
|
||||
comment_id: number;
|
||||
/**
|
||||
* An optional front end ID, to tell which is comment is coming back.
|
||||
*/
|
||||
form_id?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
form_id: Option<string>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
content: string,
|
||||
comment_id: number,
|
||||
form_id: Option<string>,
|
||||
auth: string
|
||||
) {
|
||||
this.content = content;
|
||||
this.comment_id = comment_id;
|
||||
this.form_id = form_id;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only the creator can delete the comment.
|
||||
*/
|
||||
export interface DeleteComment {
|
||||
export class DeleteComment {
|
||||
comment_id: number;
|
||||
deleted: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(comment_id: number, deleted: boolean, auth: string) {
|
||||
this.comment_id = comment_id;
|
||||
this.deleted = deleted;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only a mod or admin can remove the comment.
|
||||
*/
|
||||
export interface RemoveComment {
|
||||
export class RemoveComment {
|
||||
comment_id: number;
|
||||
removed: boolean;
|
||||
reason?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
reason: Option<string>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
comment_id: number,
|
||||
removed: boolean,
|
||||
reason: Option<string>,
|
||||
auth: string
|
||||
) {
|
||||
this.comment_id = comment_id;
|
||||
this.removed = removed;
|
||||
this.reason = reason;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only the recipient can do this.
|
||||
*/
|
||||
export interface MarkCommentAsRead {
|
||||
export class MarkCommentAsRead {
|
||||
comment_id: number;
|
||||
read: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(comment_id: number, read: boolean, auth: string) {
|
||||
this.comment_id = comment_id;
|
||||
this.read = read;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SaveComment {
|
||||
export class SaveComment {
|
||||
comment_id: number;
|
||||
save: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(comment_id: number, save: boolean, auth: string) {
|
||||
this.comment_id = comment_id;
|
||||
this.save = save;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface CommentResponse {
|
||||
export class CommentResponse {
|
||||
comment_view: CommentView;
|
||||
recipient_ids: number[];
|
||||
/**
|
||||
* An optional front end ID, to tell which is comment is coming back.
|
||||
*/
|
||||
form_id?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
form_id: Option<string>;
|
||||
}
|
||||
|
||||
export interface CreateCommentLike {
|
||||
export class CreateCommentLike {
|
||||
comment_id: number;
|
||||
score: number;
|
||||
auth: string;
|
||||
|
||||
constructor(comment_id: number, score: number, auth: string) {
|
||||
this.comment_id = comment_id;
|
||||
this.score = score;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,55 +157,137 @@ export interface CreateCommentLike {
|
|||
* You can use either `community_id` or `community_name` as an id.
|
||||
* To get posts for a federated community by name, use `name@instance.tld` .
|
||||
*/
|
||||
export interface GetComments {
|
||||
type_?: ListingType;
|
||||
sort?: SortType;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
community_id?: number;
|
||||
community_name?: string;
|
||||
saved_only?: boolean;
|
||||
auth?: string;
|
||||
export class GetComments {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
type_: Option<ListingType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
sort: Option<SortType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_id: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_name: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
saved_only: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
auth: Option<string>;
|
||||
|
||||
constructor(
|
||||
type_: Option<ListingType>,
|
||||
sort: Option<SortType>,
|
||||
page: Option<number>,
|
||||
limit: Option<number>,
|
||||
community_id: Option<number>,
|
||||
community_name: Option<string>,
|
||||
saved_only: Option<boolean>,
|
||||
auth: Option<string>
|
||||
) {
|
||||
this.type_ = type_;
|
||||
this.sort = sort;
|
||||
this.page = page;
|
||||
this.limit = limit;
|
||||
this.community_id = community_id;
|
||||
this.community_name = community_name;
|
||||
this.saved_only = saved_only;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetCommentsResponse {
|
||||
export class GetCommentsResponse {
|
||||
comments: CommentView[];
|
||||
}
|
||||
|
||||
export interface CreateCommentReport {
|
||||
export class CreateCommentReport {
|
||||
comment_id: number;
|
||||
reason: string;
|
||||
auth: string;
|
||||
|
||||
constructor(comment_id: number, reason: string, auth: string) {
|
||||
this.comment_id = comment_id;
|
||||
this.reason = reason;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface CommentReportResponse {
|
||||
export class CommentReportResponse {
|
||||
comment_report_view: CommentReportView;
|
||||
}
|
||||
|
||||
export interface ResolveCommentReport {
|
||||
export class ResolveCommentReport {
|
||||
report_id: number;
|
||||
/**
|
||||
* Either resolve or unresolve a report.
|
||||
*/
|
||||
resolved: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(report_id: number, resolved: boolean, auth: string) {
|
||||
this.report_id = report_id;
|
||||
this.resolved = resolved;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ListCommentReports {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
export class ListCommentReports {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
/**
|
||||
* if no community is given, it returns reports for all communities moderated by the auth user.
|
||||
*/
|
||||
community_id?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_id: Option<number>;
|
||||
|
||||
/**
|
||||
* Only shows the unresolved reports.
|
||||
*/
|
||||
unresolved_only?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
unresolved_only: Option<boolean>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
page: Option<number>,
|
||||
limit: Option<number>,
|
||||
community_id: Option<number>,
|
||||
unresolved_only: Option<boolean>,
|
||||
auth: string
|
||||
) {
|
||||
this.page = page;
|
||||
this.limit = limit;
|
||||
this.community_id = community_id;
|
||||
this.unresolved_only = unresolved_only;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ListCommentReportsResponse {
|
||||
export class ListCommentReportsResponse {
|
||||
comment_reports: CommentReportView[];
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import { Option, Some } from "@sniptt/monads";
|
||||
import { Expose, Transform } from "class-transformer";
|
||||
import { toUndefined } from "../../utils";
|
||||
import { ListingType, SortType } from "../others";
|
||||
import { Site } from "../source";
|
||||
import {
|
||||
|
@ -11,47 +14,129 @@ import {
|
|||
*
|
||||
* To get a federated community by name, use `name@instance.tld` .
|
||||
*/
|
||||
export interface GetCommunity {
|
||||
id?: number;
|
||||
name?: string;
|
||||
auth?: string;
|
||||
export class GetCommunity {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
id: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
name: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
auth: Option<string>;
|
||||
|
||||
constructor(id: Option<number>, name: Option<string>, auth: Option<string>) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetCommunityResponse {
|
||||
export class GetCommunityResponse {
|
||||
community_view: CommunityView;
|
||||
site?: Site;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
site: Option<Site>;
|
||||
moderators: CommunityModeratorView[];
|
||||
online: number;
|
||||
}
|
||||
|
||||
export interface CreateCommunity {
|
||||
export class CreateCommunity {
|
||||
name: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
banner?: string;
|
||||
nsfw?: boolean;
|
||||
posting_restricted_to_mods?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
description: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
icon: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
banner: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
nsfw: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
posting_restricted_to_mods: Option<boolean>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
name: string,
|
||||
title: string,
|
||||
description: Option<string>,
|
||||
icon: Option<string>,
|
||||
banner: Option<string>,
|
||||
nsfw: Option<boolean>,
|
||||
posting_restricted_to_mods: Option<boolean>,
|
||||
auth: string
|
||||
) {
|
||||
this.name = name;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.icon = icon;
|
||||
this.banner = banner;
|
||||
this.nsfw = nsfw;
|
||||
this.posting_restricted_to_mods = posting_restricted_to_mods;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface CommunityResponse {
|
||||
export class CommunityResponse {
|
||||
community_view: CommunityView;
|
||||
}
|
||||
|
||||
export interface ListCommunities {
|
||||
type_?: ListingType;
|
||||
sort?: SortType;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
auth?: string;
|
||||
export class ListCommunities {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
type_: Option<ListingType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
sort: Option<SortType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
auth: Option<string>;
|
||||
|
||||
constructor(
|
||||
type_: Option<ListingType>,
|
||||
sort: Option<SortType>,
|
||||
page: Option<number>,
|
||||
limit: Option<number>,
|
||||
auth: Option<string>
|
||||
) {
|
||||
this.type_ = type_;
|
||||
this.sort = sort;
|
||||
this.page = page;
|
||||
this.limit = limit;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ListCommunitiesResponse {
|
||||
export class ListCommunitiesResponse {
|
||||
communities: CommunityView[];
|
||||
}
|
||||
|
||||
export interface BanFromCommunity {
|
||||
export class BanFromCommunity {
|
||||
community_id: number;
|
||||
person_id: number;
|
||||
ban: boolean;
|
||||
|
@ -59,84 +144,205 @@ export interface BanFromCommunity {
|
|||
/**
|
||||
* Removes/Restores their comments and posts for that community.
|
||||
*/
|
||||
remove_data?: boolean;
|
||||
reason?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
remove_data: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
reason: Option<string>;
|
||||
/**
|
||||
* The expire time in Unix seconds
|
||||
*/
|
||||
expires?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
expires: Option<number>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
community_id: number,
|
||||
person_id: number,
|
||||
ban: boolean,
|
||||
remove_data: Option<boolean>,
|
||||
reason: Option<string>,
|
||||
expires: Option<number>,
|
||||
auth: string
|
||||
) {
|
||||
this.community_id = community_id;
|
||||
this.person_id = person_id;
|
||||
this.ban = ban;
|
||||
this.remove_data = remove_data;
|
||||
this.reason = reason;
|
||||
this.expires = expires;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface BanFromCommunityResponse {
|
||||
export class BanFromCommunityResponse {
|
||||
person_view: PersonViewSafe;
|
||||
banned: boolean;
|
||||
}
|
||||
|
||||
export interface AddModToCommunity {
|
||||
export class AddModToCommunity {
|
||||
community_id: number;
|
||||
person_id: number;
|
||||
added: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
community_id: number,
|
||||
person_id: number,
|
||||
added: boolean,
|
||||
auth: string
|
||||
) {
|
||||
this.community_id = community_id;
|
||||
this.person_id = person_id;
|
||||
this.added = added;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface AddModToCommunityResponse {
|
||||
export class AddModToCommunityResponse {
|
||||
moderators: CommunityModeratorView[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Only mods can edit a community.
|
||||
*/
|
||||
export interface EditCommunity {
|
||||
export class EditCommunity {
|
||||
community_id: number;
|
||||
title?: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
banner?: string;
|
||||
nsfw?: boolean;
|
||||
posting_restricted_to_mods?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
title: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
description: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
icon: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
banner: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
nsfw: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
posting_restricted_to_mods: Option<boolean>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
community_id: number,
|
||||
title: Option<string>,
|
||||
description: Option<string>,
|
||||
icon: Option<string>,
|
||||
banner: Option<string>,
|
||||
nsfw: Option<boolean>,
|
||||
posting_restricted_to_mods: Option<boolean>,
|
||||
auth: string
|
||||
) {
|
||||
this.community_id = community_id;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.icon = icon;
|
||||
this.banner = banner;
|
||||
this.nsfw = nsfw;
|
||||
this.posting_restricted_to_mods = posting_restricted_to_mods;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface DeleteCommunity {
|
||||
export class DeleteCommunity {
|
||||
community_id: number;
|
||||
deleted: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(community_id: number, deleted: boolean, auth: string) {
|
||||
this.community_id = community_id;
|
||||
this.deleted = deleted;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only admins can remove a community.
|
||||
*/
|
||||
export interface RemoveCommunity {
|
||||
export class RemoveCommunity {
|
||||
community_id: number;
|
||||
removed: boolean;
|
||||
reason?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
reason: Option<string>;
|
||||
/**
|
||||
* The expire time in Unix seconds
|
||||
*/
|
||||
expires?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
expires: Option<number>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
community_id: number,
|
||||
removed: boolean,
|
||||
reason: Option<string>,
|
||||
expires: Option<number>,
|
||||
auth: string
|
||||
) {
|
||||
this.community_id = community_id;
|
||||
this.removed = removed;
|
||||
this.reason = reason;
|
||||
this.expires = expires;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface FollowCommunity {
|
||||
export class FollowCommunity {
|
||||
community_id: number;
|
||||
follow: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(community_id: number, follow: boolean, auth: string) {
|
||||
this.community_id = community_id;
|
||||
this.follow = follow;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface TransferCommunity {
|
||||
export class TransferCommunity {
|
||||
community_id: number;
|
||||
person_id: number;
|
||||
auth: string;
|
||||
|
||||
constructor(community_id: number, person_id: number, auth: string) {
|
||||
this.community_id = community_id;
|
||||
this.person_id = person_id;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface BlockCommunity {
|
||||
export class BlockCommunity {
|
||||
community_id: number;
|
||||
block: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(community_id: number, block: boolean, auth: string) {
|
||||
this.community_id = community_id;
|
||||
this.block = block;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface BlockCommunityResponse {
|
||||
export class BlockCommunityResponse {
|
||||
community_view: CommunityView;
|
||||
blocked: boolean;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import { Option, Some } from "@sniptt/monads";
|
||||
import { Expose, Transform } from "class-transformer";
|
||||
import { toUndefined } from "../../utils";
|
||||
import { SortType } from "../others";
|
||||
import {
|
||||
CommentView,
|
||||
|
@ -8,9 +11,14 @@ import {
|
|||
PrivateMessageView,
|
||||
} from "../views";
|
||||
|
||||
export interface Login {
|
||||
export class Login {
|
||||
username_or_email: string;
|
||||
password: string;
|
||||
|
||||
constructor(username_or_email: string, password: string) {
|
||||
this.username_or_email = username_or_email;
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,37 +26,77 @@ export interface Login {
|
|||
*
|
||||
* Only the first user to register will be able to be the admin.
|
||||
*/
|
||||
export interface Register {
|
||||
export class Register {
|
||||
username: string;
|
||||
/**
|
||||
* Email is mandatory if email verification is enabled on the server
|
||||
*/
|
||||
email?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
email: Option<string>;
|
||||
password: string;
|
||||
password_verify: string;
|
||||
show_nsfw: boolean;
|
||||
/**
|
||||
* Captcha is only checked if these are enabled in the server.
|
||||
*/
|
||||
captcha_uuid?: string;
|
||||
captcha_answer?: string;
|
||||
honeypot?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
captcha_uuid: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
captcha_answer: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
honeypot: Option<string>;
|
||||
/**
|
||||
* An answer is mandatory if require application is enabled on the server
|
||||
*/
|
||||
answer?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
answer: Option<string>;
|
||||
|
||||
constructor(
|
||||
username: string,
|
||||
email: Option<string>,
|
||||
password: string,
|
||||
password_verify: string,
|
||||
show_nsfw: boolean,
|
||||
captcha_uuid: Option<string>,
|
||||
captcha_answer: Option<string>,
|
||||
honeypot: Option<string>,
|
||||
answer: Option<string>
|
||||
) {
|
||||
this.username = username;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.password_verify = password_verify;
|
||||
this.show_nsfw = show_nsfw;
|
||||
this.captcha_uuid = captcha_uuid;
|
||||
this.captcha_answer = captcha_answer;
|
||||
this.honeypot = honeypot;
|
||||
this.answer = answer;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetCaptcha {}
|
||||
export class GetCaptcha {}
|
||||
|
||||
export interface GetCaptchaResponse {
|
||||
export class GetCaptchaResponse {
|
||||
/**
|
||||
* Will be undefined if captchas are disabled.
|
||||
*/
|
||||
ok?: CaptchaResponse;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
ok: Option<CaptchaResponse>;
|
||||
}
|
||||
|
||||
export interface CaptchaResponse {
|
||||
export class CaptchaResponse {
|
||||
/**
|
||||
* A Base64 encoded png.
|
||||
*/
|
||||
|
@ -57,7 +105,10 @@ export interface CaptchaResponse {
|
|||
/**
|
||||
* A Base64 encoded wav file.
|
||||
*/
|
||||
wav?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
wav: Option<string>;
|
||||
|
||||
/**
|
||||
* A UUID to match the one given on request.
|
||||
|
@ -65,259 +116,584 @@ export interface CaptchaResponse {
|
|||
uuid: string;
|
||||
}
|
||||
|
||||
export interface SaveUserSettings {
|
||||
show_nsfw?: boolean;
|
||||
export class SaveUserSettings {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
show_nsfw: Option<boolean>;
|
||||
|
||||
/**
|
||||
* Default for this is `browser`.
|
||||
*/
|
||||
theme?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
theme: Option<string>;
|
||||
|
||||
/**
|
||||
* The [[SortType]].
|
||||
*
|
||||
* The Sort types from above, zero indexed as a number
|
||||
*/
|
||||
default_sort_type?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
default_sort_type: Option<number>;
|
||||
|
||||
/**
|
||||
* The [[ListingType]].
|
||||
*
|
||||
* Post listing types are `All, Subscribed, Community`
|
||||
*/
|
||||
default_listing_type?: number;
|
||||
lang?: string;
|
||||
avatar?: string;
|
||||
banner?: string;
|
||||
display_name?: string;
|
||||
email?: string;
|
||||
bio?: string;
|
||||
matrix_user_id?: string;
|
||||
show_avatars?: boolean;
|
||||
show_scores?: boolean;
|
||||
send_notifications_to_email?: boolean;
|
||||
bot_account?: boolean;
|
||||
show_bot_accounts?: boolean;
|
||||
show_read_posts?: boolean;
|
||||
show_new_post_notifs?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
default_listing_type: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
lang: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
avatar: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
banner: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
display_name: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
email: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
bio: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
matrix_user_id: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
show_avatars: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
show_scores: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
send_notifications_to_email: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
bot_account: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
show_bot_accounts: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
show_read_posts: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
show_new_post_notifs: Option<boolean>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
show_nsfw: Option<boolean>,
|
||||
theme: Option<string>,
|
||||
default_sort_type: Option<number>,
|
||||
default_listing_type: Option<number>,
|
||||
lang: Option<string>,
|
||||
avatar: Option<string>,
|
||||
banner: Option<string>,
|
||||
display_name: Option<string>,
|
||||
email: Option<string>,
|
||||
bio: Option<string>,
|
||||
matrix_user_id: Option<string>,
|
||||
show_avatars: Option<boolean>,
|
||||
show_scores: Option<boolean>,
|
||||
send_notifications_to_email: Option<boolean>,
|
||||
bot_account: Option<boolean>,
|
||||
show_bot_accounts: Option<boolean>,
|
||||
show_read_posts: Option<boolean>,
|
||||
show_new_post_notifs: Option<boolean>,
|
||||
auth: string
|
||||
) {
|
||||
this.show_nsfw = show_nsfw;
|
||||
this.theme = theme;
|
||||
this.default_sort_type = default_sort_type;
|
||||
this.default_listing_type = default_listing_type;
|
||||
this.lang = lang;
|
||||
this.avatar = avatar;
|
||||
this.banner = banner;
|
||||
this.display_name = display_name;
|
||||
this.email = email;
|
||||
this.bio = bio;
|
||||
this.matrix_user_id = matrix_user_id;
|
||||
this.show_avatars = show_avatars;
|
||||
this.show_scores = show_scores;
|
||||
this.send_notifications_to_email = send_notifications_to_email;
|
||||
this.bot_account = bot_account;
|
||||
this.show_bot_accounts = show_bot_accounts;
|
||||
this.show_read_posts = show_read_posts;
|
||||
this.show_new_post_notifs = show_new_post_notifs;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ChangePassword {
|
||||
export class ChangePassword {
|
||||
new_password: string;
|
||||
new_password_verify: string;
|
||||
old_password: string;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
new_password: string,
|
||||
new_password_verify: string,
|
||||
old_password: string,
|
||||
auth: string
|
||||
) {
|
||||
this.new_password = new_password;
|
||||
this.new_password_verify = new_password_verify;
|
||||
this.old_password = old_password;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The `jwt` string should be stored and used anywhere `auth` is called for.
|
||||
*/
|
||||
export interface LoginResponse {
|
||||
export class LoginResponse {
|
||||
/**
|
||||
* This is None in response to `Register` if email verification is enabled, or the server requires registration applications.
|
||||
*/
|
||||
jwt?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
jwt: Option<string>;
|
||||
verify_email_sent: boolean;
|
||||
registration_created: boolean;
|
||||
}
|
||||
|
||||
export interface GetPersonDetails {
|
||||
person_id?: number;
|
||||
export class GetPersonDetails {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
person_id: Option<number>;
|
||||
/**
|
||||
* To get details for a federated user, use `person@instance.tld`.
|
||||
*/
|
||||
username?: string;
|
||||
sort?: SortType;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
community_id?: number;
|
||||
saved_only?: boolean;
|
||||
auth?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
username: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
sort: Option<SortType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_id: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
saved_only: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
auth: Option<string>;
|
||||
|
||||
constructor(
|
||||
person_id: Option<number>,
|
||||
username: Option<string>,
|
||||
sort: Option<SortType>,
|
||||
page: Option<number>,
|
||||
limit: Option<number>,
|
||||
community_id: Option<number>,
|
||||
saved_only: Option<boolean>,
|
||||
auth: Option<string>
|
||||
) {
|
||||
this.person_id = person_id;
|
||||
this.username = username;
|
||||
this.sort = sort;
|
||||
this.page = page;
|
||||
this.limit = limit;
|
||||
this.community_id = community_id;
|
||||
this.saved_only = saved_only;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetPersonDetailsResponse {
|
||||
export class GetPersonDetailsResponse {
|
||||
person_view: PersonViewSafe;
|
||||
comments: CommentView[];
|
||||
posts: PostView[];
|
||||
moderates: CommunityModeratorView[];
|
||||
}
|
||||
|
||||
export interface GetRepliesResponse {
|
||||
export class GetRepliesResponse {
|
||||
replies: CommentView[];
|
||||
}
|
||||
|
||||
export interface GetPersonMentionsResponse {
|
||||
export class GetPersonMentionsResponse {
|
||||
mentions: PersonMentionView[];
|
||||
}
|
||||
|
||||
export interface MarkAllAsRead {
|
||||
export class MarkAllAsRead {
|
||||
auth: string;
|
||||
|
||||
constructor(auth: string) {
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface AddAdmin {
|
||||
export class AddAdmin {
|
||||
person_id: number;
|
||||
added: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(person_id: number, added: boolean, auth: string) {
|
||||
this.person_id = person_id;
|
||||
this.added = added;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface AddAdminResponse {
|
||||
export class AddAdminResponse {
|
||||
admins: PersonViewSafe[];
|
||||
}
|
||||
|
||||
export interface BanPerson {
|
||||
export class BanPerson {
|
||||
person_id: number;
|
||||
ban: boolean;
|
||||
|
||||
/**
|
||||
* Removes/Restores their comments, posts, and communities
|
||||
*/
|
||||
remove_data?: boolean;
|
||||
reason?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
remove_data: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
reason: Option<string>;
|
||||
/**
|
||||
* The expire time in Unix seconds
|
||||
*/
|
||||
expires?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
expires: Option<number>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
person_id: number,
|
||||
ban: boolean,
|
||||
remove_data: Option<boolean>,
|
||||
reason: Option<string>,
|
||||
expires: Option<number>,
|
||||
auth: string
|
||||
) {
|
||||
this.person_id = person_id;
|
||||
this.ban = ban;
|
||||
this.remove_data = remove_data;
|
||||
this.reason = reason;
|
||||
this.expires = expires;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface BanPersonResponse {
|
||||
export class BanPersonResponse {
|
||||
person_view: PersonViewSafe;
|
||||
banned: boolean;
|
||||
}
|
||||
|
||||
export interface GetReplies {
|
||||
sort?: SortType;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
unread_only?: boolean;
|
||||
export class GetReplies {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
sort: Option<SortType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
unread_only: Option<boolean>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
sort: Option<SortType>,
|
||||
page: Option<number>,
|
||||
limit: Option<number>,
|
||||
unread_only: Option<boolean>,
|
||||
auth: string
|
||||
) {
|
||||
this.sort = sort;
|
||||
this.page = page;
|
||||
this.limit = limit;
|
||||
this.unread_only = unread_only;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetPersonMentions {
|
||||
sort?: SortType;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
unread_only?: boolean;
|
||||
export class GetPersonMentions {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
sort: Option<SortType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
unread_only: Option<boolean>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
sort: Option<SortType>,
|
||||
page: Option<number>,
|
||||
limit: Option<number>,
|
||||
unread_only: Option<boolean>,
|
||||
auth: string
|
||||
) {
|
||||
this.sort = sort;
|
||||
this.page = page;
|
||||
this.limit = limit;
|
||||
this.unread_only = unread_only;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface MarkPersonMentionAsRead {
|
||||
export class MarkPersonMentionAsRead {
|
||||
person_mention_id: number;
|
||||
read: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(person_mention_id: number, read: boolean, auth: string) {
|
||||
this.person_mention_id = person_mention_id;
|
||||
this.read = read;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface PersonMentionResponse {
|
||||
export class PersonMentionResponse {
|
||||
person_mention_view: PersonMentionView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently deletes your posts and comments
|
||||
*/
|
||||
export interface DeleteAccount {
|
||||
export class DeleteAccount {
|
||||
password: string;
|
||||
auth: string;
|
||||
|
||||
constructor(password: string, auth: string) {
|
||||
this.password = password;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface DeleteAccountResponse {}
|
||||
export class DeleteAccountResponse {}
|
||||
|
||||
export interface PasswordReset {
|
||||
export class PasswordReset {
|
||||
email: string;
|
||||
|
||||
constructor(email: string) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
|
||||
export interface PasswordResetResponse {}
|
||||
export class PasswordResetResponse {}
|
||||
|
||||
export interface PasswordChange {
|
||||
export class PasswordChange {
|
||||
token: string;
|
||||
password: string;
|
||||
password_verify: string;
|
||||
|
||||
constructor(token: string, password: string, password_verify: string) {
|
||||
this.token = token;
|
||||
this.password = password;
|
||||
this.password_verify = password_verify;
|
||||
}
|
||||
}
|
||||
|
||||
export interface CreatePrivateMessage {
|
||||
export class CreatePrivateMessage {
|
||||
content: string;
|
||||
recipient_id: number;
|
||||
auth: string;
|
||||
|
||||
constructor(content: string, recipient_id: number, auth: string) {
|
||||
this.content = content;
|
||||
this.recipient_id = recipient_id;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface EditPrivateMessage {
|
||||
export class EditPrivateMessage {
|
||||
private_message_id: number;
|
||||
content: string;
|
||||
auth: string;
|
||||
|
||||
constructor(private_message_id: number, content: string, auth: string) {
|
||||
this.private_message_id = private_message_id;
|
||||
this.content = content;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface DeletePrivateMessage {
|
||||
export class DeletePrivateMessage {
|
||||
private_message_id: number;
|
||||
deleted: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(private_message_id: number, deleted: boolean, auth: string) {
|
||||
this.private_message_id = private_message_id;
|
||||
this.deleted = deleted;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface MarkPrivateMessageAsRead {
|
||||
export class MarkPrivateMessageAsRead {
|
||||
private_message_id: number;
|
||||
read: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(private_message_id: number, read: boolean, auth: string) {
|
||||
this.private_message_id = private_message_id;
|
||||
this.read = read;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetPrivateMessages {
|
||||
unread_only?: boolean;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
export class GetPrivateMessages {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
unread_only: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
auth: string;
|
||||
}
|
||||
|
||||
export interface PrivateMessagesResponse {
|
||||
export class PrivateMessagesResponse {
|
||||
private_messages: PrivateMessageView[];
|
||||
}
|
||||
|
||||
export interface PrivateMessageResponse {
|
||||
export class PrivateMessageResponse {
|
||||
private_message_view: PrivateMessageView;
|
||||
}
|
||||
|
||||
export interface GetReportCount {
|
||||
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.
|
||||
*/
|
||||
community_id?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_id: Option<number>;
|
||||
auth: string;
|
||||
|
||||
constructor(community_id: Option<number>, auth: string) {
|
||||
this.community_id = community_id;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetReportCountResponse {
|
||||
community_id?: number;
|
||||
export class GetReportCountResponse {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_id: Option<number>;
|
||||
comment_reports: number;
|
||||
post_reports: number;
|
||||
}
|
||||
|
||||
export interface GetUnreadCount {
|
||||
export class GetUnreadCount {
|
||||
auth: string;
|
||||
|
||||
constructor(auth: string) {
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetUnreadCountResponse {
|
||||
export class GetUnreadCountResponse {
|
||||
replies: number;
|
||||
mentions: number;
|
||||
private_messages: number;
|
||||
}
|
||||
|
||||
export interface VerifyEmail {
|
||||
export class VerifyEmail {
|
||||
token: string;
|
||||
|
||||
constructor(token: string) {
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
|
||||
export interface VerifyEmailResponse {}
|
||||
export class VerifyEmailResponse {}
|
||||
|
||||
export interface BlockPerson {
|
||||
export class BlockPerson {
|
||||
person_id: number;
|
||||
block: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(person_id: number, block: boolean, auth: string) {
|
||||
this.person_id = person_id;
|
||||
this.block = block;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface BlockPersonResponse {
|
||||
export class BlockPersonResponse {
|
||||
person_view: PersonViewSafe;
|
||||
blocked: boolean;
|
||||
}
|
||||
|
||||
export interface GetBannedPersons {
|
||||
export class GetBannedPersons {
|
||||
auth: string;
|
||||
|
||||
constructor(auth: string) {
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface BannedPersonsResponse {
|
||||
export class BannedPersonsResponse {
|
||||
banned: PersonViewSafe[];
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import { Option, Some } from "@sniptt/monads";
|
||||
import { Expose, Transform } from "class-transformer";
|
||||
import { toUndefined } from "../../utils";
|
||||
import { ListingType, SiteMetadata, SortType } from "../others";
|
||||
import {
|
||||
CommentView,
|
||||
|
@ -7,26 +10,64 @@ import {
|
|||
PostView,
|
||||
} from "../views";
|
||||
|
||||
export interface CreatePost {
|
||||
export class CreatePost {
|
||||
name: string;
|
||||
url?: string;
|
||||
body?: string;
|
||||
nsfw?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
url: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
body: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
nsfw: Option<boolean>;
|
||||
community_id: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
honeypot: Option<string>;
|
||||
auth: string;
|
||||
honeypot?: string;
|
||||
|
||||
constructor(
|
||||
name: string,
|
||||
url: Option<string>,
|
||||
body: Option<string>,
|
||||
nsfw: Option<boolean>,
|
||||
community_id: number,
|
||||
honeypot: Option<string>,
|
||||
auth: string
|
||||
) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.body = body;
|
||||
this.nsfw = nsfw;
|
||||
this.community_id = community_id;
|
||||
this.honeypot = honeypot;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface PostResponse {
|
||||
export class PostResponse {
|
||||
post_view: PostView;
|
||||
}
|
||||
|
||||
export interface GetPost {
|
||||
export class GetPost {
|
||||
id: number;
|
||||
auth?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
auth: Option<string>;
|
||||
|
||||
constructor(id: number, auth: Option<string>) {
|
||||
this.id = id;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetPostResponse {
|
||||
export class GetPostResponse {
|
||||
post_view: PostView;
|
||||
community_view: CommunityView;
|
||||
comments: CommentView[];
|
||||
|
@ -34,25 +75,69 @@ export interface GetPostResponse {
|
|||
online: number;
|
||||
}
|
||||
|
||||
export interface GetPosts {
|
||||
type_?: ListingType;
|
||||
sort?: SortType;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
community_id?: number;
|
||||
export class GetPosts {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
type_: Option<ListingType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
sort: Option<SortType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_id: Option<number>;
|
||||
/**
|
||||
* To get posts for a federated community by name, use `name@instance.tld` .
|
||||
*/
|
||||
community_name?: string;
|
||||
saved_only?: boolean;
|
||||
auth?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_name: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
saved_only: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
auth: Option<string>;
|
||||
|
||||
constructor(
|
||||
type_: Option<ListingType>,
|
||||
sort: Option<SortType>,
|
||||
page: Option<number>,
|
||||
limit: Option<number>,
|
||||
community_id: Option<number>,
|
||||
community_name: Option<string>,
|
||||
saved_only: Option<boolean>,
|
||||
auth: Option<string>
|
||||
) {
|
||||
this.type_ = type_;
|
||||
this.sort = sort;
|
||||
this.page = page;
|
||||
this.limit = limit;
|
||||
this.community_id = community_id;
|
||||
this.community_name = community_name;
|
||||
this.saved_only = saved_only;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetPostsResponse {
|
||||
export class GetPostsResponse {
|
||||
posts: PostView[];
|
||||
}
|
||||
|
||||
export interface CreatePostLike {
|
||||
export class CreatePostLike {
|
||||
post_id: number;
|
||||
|
||||
/**
|
||||
|
@ -60,107 +145,228 @@ export interface CreatePostLike {
|
|||
*/
|
||||
score: number;
|
||||
auth: string;
|
||||
|
||||
constructor(post_id: number, score: number, auth: string) {
|
||||
this.post_id = post_id;
|
||||
this.score = score;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface EditPost {
|
||||
export class EditPost {
|
||||
post_id: number;
|
||||
name?: string;
|
||||
url?: string;
|
||||
body?: string;
|
||||
nsfw?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
name: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
url: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
body: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
nsfw: Option<boolean>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
post_id: number,
|
||||
name: Option<string>,
|
||||
url: Option<string>,
|
||||
body: Option<string>,
|
||||
nsfw: Option<boolean>,
|
||||
auth: string
|
||||
) {
|
||||
this.post_id = post_id;
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.body = body;
|
||||
this.nsfw = nsfw;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface DeletePost {
|
||||
export class DeletePost {
|
||||
post_id: number;
|
||||
deleted: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(post_id: number, deleted: boolean, auth: string) {
|
||||
this.post_id = post_id;
|
||||
this.deleted = deleted;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only admins and mods can remove a post.
|
||||
*/
|
||||
export interface RemovePost {
|
||||
export class RemovePost {
|
||||
post_id: number;
|
||||
removed: boolean;
|
||||
reason?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
reason: Option<string>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
post_id: number,
|
||||
removed: boolean,
|
||||
reason: Option<string>,
|
||||
auth: string
|
||||
) {
|
||||
this.post_id = post_id;
|
||||
this.removed = removed;
|
||||
this.reason = reason;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a post as read.
|
||||
*/
|
||||
export interface MarkPostAsRead {
|
||||
export class MarkPostAsRead {
|
||||
post_id: number;
|
||||
read: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(post_id: number, read: boolean, auth: string) {
|
||||
this.post_id = post_id;
|
||||
this.read = read;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only admins and mods can lock a post.
|
||||
*/
|
||||
export interface LockPost {
|
||||
export class LockPost {
|
||||
post_id: number;
|
||||
locked: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(post_id: number, locked: boolean, auth: string) {
|
||||
this.post_id = post_id;
|
||||
this.locked = locked;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only admins and mods can sticky a post.
|
||||
*/
|
||||
export interface StickyPost {
|
||||
export class StickyPost {
|
||||
post_id: number;
|
||||
stickied: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(post_id: number, stickied: boolean, auth: string) {
|
||||
this.post_id = post_id;
|
||||
this.stickied = stickied;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SavePost {
|
||||
export class SavePost {
|
||||
post_id: number;
|
||||
save: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(post_id: number, save: boolean, auth: string) {
|
||||
this.post_id = post_id;
|
||||
this.save = save;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface CreatePostReport {
|
||||
export class CreatePostReport {
|
||||
post_id: number;
|
||||
reason: string;
|
||||
auth: string;
|
||||
|
||||
constructor(post_id: number, reason: string, auth: string) {
|
||||
this.post_id = post_id;
|
||||
this.reason = reason;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface PostReportResponse {
|
||||
export class PostReportResponse {
|
||||
post_report_view: PostReportView;
|
||||
}
|
||||
|
||||
export interface ResolvePostReport {
|
||||
export class ResolvePostReport {
|
||||
report_id: number;
|
||||
/**
|
||||
* Either resolve or unresolve a report.
|
||||
*/
|
||||
resolved: boolean;
|
||||
auth: string;
|
||||
|
||||
constructor(report_id: number, resolved: boolean, auth: string) {
|
||||
this.report_id = report_id;
|
||||
this.resolved = resolved;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ListPostReports {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
export class ListPostReports {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
/**
|
||||
* if no community is given, it returns reports for all communities moderated by the auth user.
|
||||
*/
|
||||
community_id?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_id: Option<number>;
|
||||
/**
|
||||
* Only shows the unresolved reports.
|
||||
*/
|
||||
unresolved_only?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
unresolved_only: Option<boolean>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
page: Option<number>,
|
||||
limit: Option<number>,
|
||||
community_id: Option<number>,
|
||||
unresolved_only: Option<boolean>,
|
||||
auth: string
|
||||
) {
|
||||
this.page = page;
|
||||
this.limit = limit;
|
||||
this.community_id = community_id;
|
||||
this.unresolved_only = unresolved_only;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ListPostReportsResponse {
|
||||
export class ListPostReportsResponse {
|
||||
post_reports: PostReportView[];
|
||||
}
|
||||
|
||||
export interface GetSiteMetadata {
|
||||
export class GetSiteMetadata {
|
||||
url: string;
|
||||
|
||||
constructor(url: string) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetSiteMetadataResponse {
|
||||
export class GetSiteMetadataResponse {
|
||||
metadata: SiteMetadata;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { Option } from "option-t/esm/PlainOption";
|
||||
import { Option, Some } from "@sniptt/monads";
|
||||
import { Expose, Transform } from "class-transformer";
|
||||
import { toUndefined } from "../../utils";
|
||||
import { ListingType, SearchType, SortType } from "../others";
|
||||
import {
|
||||
CommentView,
|
||||
|
@ -27,23 +29,74 @@ import {
|
|||
/**
|
||||
* Search lemmy for different types of data.
|
||||
*/
|
||||
export interface Search {
|
||||
export class Search {
|
||||
/**
|
||||
* The search query string.
|
||||
*/
|
||||
q: string;
|
||||
type_?: SearchType;
|
||||
community_id?: number;
|
||||
community_name?: string;
|
||||
creator_id?: number;
|
||||
sort?: SortType;
|
||||
listing_type?: ListingType;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
auth?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
type_: Option<SearchType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_id: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_name: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
creator_id: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
sort: Option<SortType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
listing_type: Option<ListingType>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
auth: Option<string>;
|
||||
|
||||
constructor(
|
||||
q: string,
|
||||
type_: Option<SearchType>,
|
||||
community_id: Option<number>,
|
||||
community_name: Option<string>,
|
||||
creator_id: Option<number>,
|
||||
sort: Option<SortType>,
|
||||
listing_type: Option<ListingType>,
|
||||
page: Option<number>,
|
||||
limit: Option<number>,
|
||||
auth: Option<string>
|
||||
) {
|
||||
this.q = q;
|
||||
this.type_ = type_;
|
||||
this.community_id = community_id;
|
||||
this.community_name = community_name;
|
||||
this.creator_id = creator_id;
|
||||
this.sort = sort;
|
||||
this.listing_type = listing_type;
|
||||
this.page = page;
|
||||
this.limit = limit;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SearchResponse {
|
||||
export class SearchResponse {
|
||||
/**
|
||||
* The [[SearchType]].
|
||||
*/
|
||||
|
@ -54,15 +107,44 @@ export interface SearchResponse {
|
|||
users: PersonViewSafe[];
|
||||
}
|
||||
|
||||
export interface GetModlog {
|
||||
mod_person_id?: number;
|
||||
community_id?: number;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
auth?: string;
|
||||
export class GetModlog {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
mod_person_id: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_id: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
auth: Option<string>;
|
||||
|
||||
constructor(
|
||||
mod_person_id: Option<number>,
|
||||
community_id: Option<number>,
|
||||
page: Option<number>,
|
||||
limit: Option<number>,
|
||||
auth: Option<string>
|
||||
) {
|
||||
this.mod_person_id = mod_person_id;
|
||||
this.community_id = community_id;
|
||||
this.page = page;
|
||||
this.limit = limit;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetModlogResponse {
|
||||
export class GetModlogResponse {
|
||||
removed_posts: ModRemovePostView[];
|
||||
locked_posts: ModLockPostView[];
|
||||
stickied_posts: ModStickyPostView[];
|
||||
|
@ -75,66 +157,246 @@ export interface GetModlogResponse {
|
|||
added: ModAddView[];
|
||||
}
|
||||
|
||||
export interface CreateSite {
|
||||
export class CreateSite {
|
||||
name: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
sidebar: Option<string>;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
banner?: string;
|
||||
enable_downvotes?: boolean;
|
||||
open_registration?: boolean;
|
||||
enable_nsfw?: boolean;
|
||||
community_creation_admin_only?: boolean;
|
||||
require_email_verification?: boolean;
|
||||
require_application?: boolean;
|
||||
application_question?: string;
|
||||
private_instance?: boolean;
|
||||
default_theme?: string;
|
||||
default_post_listing_type?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
description: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
icon: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
banner: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
enable_downvotes: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
open_registration: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
enable_nsfw: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_creation_admin_only: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
require_email_verification: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
require_application: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
application_question: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
private_instance: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
default_theme: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
default_post_listing_type: Option<string>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
name: string,
|
||||
sidebar: Option<string>,
|
||||
description: Option<string>,
|
||||
icon: Option<string>,
|
||||
banner: Option<string>,
|
||||
enable_downvotes: Option<boolean>,
|
||||
open_registration: Option<boolean>,
|
||||
enable_nsfw: Option<boolean>,
|
||||
community_creation_admin_only: Option<boolean>,
|
||||
require_email_verification: Option<boolean>,
|
||||
require_application: Option<boolean>,
|
||||
application_question: Option<string>,
|
||||
private_instance: Option<boolean>,
|
||||
default_theme: Option<string>,
|
||||
default_post_listing_type: Option<string>,
|
||||
auth: string
|
||||
) {
|
||||
this.name = name;
|
||||
this.sidebar = sidebar;
|
||||
this.description = description;
|
||||
this.icon = icon;
|
||||
this.banner = banner;
|
||||
this.enable_downvotes = enable_downvotes;
|
||||
this.open_registration = open_registration;
|
||||
this.enable_nsfw = enable_nsfw;
|
||||
this.community_creation_admin_only = community_creation_admin_only;
|
||||
this.require_email_verification = require_email_verification;
|
||||
this.require_application = require_application;
|
||||
this.application_question = application_question;
|
||||
this.private_instance = private_instance;
|
||||
this.default_theme = default_theme;
|
||||
this.default_post_listing_type = default_post_listing_type;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface EditSite {
|
||||
name?: string;
|
||||
export class EditSite {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
name: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
sidebar: Option<string>;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
banner?: string;
|
||||
enable_downvotes?: boolean;
|
||||
open_registration?: boolean;
|
||||
enable_nsfw?: boolean;
|
||||
community_creation_admin_only?: boolean;
|
||||
require_email_verification?: boolean;
|
||||
require_application?: boolean;
|
||||
application_question?: string;
|
||||
private_instance?: boolean;
|
||||
default_theme?: string;
|
||||
legal_information?: string;
|
||||
default_post_listing_type?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
description: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
icon: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
banner: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
enable_downvotes: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
open_registration: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
enable_nsfw: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community_creation_admin_only: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
require_email_verification: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
require_application: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
application_question: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
private_instance: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
default_theme: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
legal_information: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
default_post_listing_type: Option<string>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
name: Option<string>,
|
||||
sidebar: Option<string>,
|
||||
description: Option<string>,
|
||||
icon: Option<string>,
|
||||
banner: Option<string>,
|
||||
enable_downvotes: Option<boolean>,
|
||||
open_registration: Option<boolean>,
|
||||
enable_nsfw: Option<boolean>,
|
||||
community_creation_admin_only: Option<boolean>,
|
||||
require_email_verification: Option<boolean>,
|
||||
require_application: Option<boolean>,
|
||||
application_question: Option<string>,
|
||||
private_instance: Option<boolean>,
|
||||
default_theme: Option<string>,
|
||||
legal_information: Option<string>,
|
||||
default_post_listing_type: Option<string>,
|
||||
auth: string
|
||||
) {
|
||||
this.name = name;
|
||||
this.sidebar = sidebar;
|
||||
this.description = description;
|
||||
this.icon = icon;
|
||||
this.banner = banner;
|
||||
this.enable_downvotes = enable_downvotes;
|
||||
this.open_registration = open_registration;
|
||||
this.enable_nsfw = enable_nsfw;
|
||||
this.community_creation_admin_only = community_creation_admin_only;
|
||||
this.require_email_verification = require_email_verification;
|
||||
this.require_application = require_application;
|
||||
this.application_question = application_question;
|
||||
this.private_instance = private_instance;
|
||||
this.default_theme = default_theme;
|
||||
this.legal_information = legal_information;
|
||||
this.default_post_listing_type = default_post_listing_type;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetSite {
|
||||
auth?: string;
|
||||
export class GetSite {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
auth: Option<string>;
|
||||
|
||||
constructor(auth: Option<string>) {
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SiteResponse {
|
||||
export class SiteResponse {
|
||||
site_view: SiteView;
|
||||
}
|
||||
|
||||
export interface GetSiteResponse {
|
||||
export class GetSiteResponse {
|
||||
/**
|
||||
* Optional, because the site might not be set up yet.
|
||||
*/
|
||||
site_view?: SiteView;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
site_view: Option<SiteView>;
|
||||
admins: PersonViewSafe[];
|
||||
online: number;
|
||||
version: string;
|
||||
/**
|
||||
* If you're logged in, you'll get back extra user info.
|
||||
*/
|
||||
my_user?: MyUserInfo;
|
||||
federated_instances?: FederatedInstances;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
my_user: Option<MyUserInfo>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
federated_instances: Option<FederatedInstances>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,70 +410,149 @@ export interface MyUserInfo {
|
|||
person_blocks: PersonBlockView[];
|
||||
}
|
||||
|
||||
export interface LeaveAdmin {
|
||||
export class LeaveAdmin {
|
||||
auth: string;
|
||||
|
||||
constructor(auth: string) {
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetSiteConfig {
|
||||
export class GetSiteConfig {
|
||||
auth: string;
|
||||
|
||||
constructor(auth: string) {
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetSiteConfigResponse {
|
||||
export class GetSiteConfigResponse {
|
||||
config_hjson: string;
|
||||
}
|
||||
|
||||
export interface SaveSiteConfig {
|
||||
export class SaveSiteConfig {
|
||||
config_hjson: string;
|
||||
auth: string;
|
||||
|
||||
constructor(config_hjson: string, auth: string) {
|
||||
this.config_hjson = config_hjson;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface FederatedInstances {
|
||||
export class FederatedInstances {
|
||||
linked: string[];
|
||||
allowed?: string[];
|
||||
blocked?: string[];
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
allowed: Option<string[]>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
blocked: Option<string[]>;
|
||||
}
|
||||
|
||||
export interface ResolveObject {
|
||||
export class ResolveObject {
|
||||
q: string;
|
||||
auth?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
auth: Option<string>;
|
||||
|
||||
constructor(q: string, auth: Option<string>) {
|
||||
this.q = q;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ResolveObjectResponse {
|
||||
comment?: CommentView;
|
||||
post?: PostView;
|
||||
community?: CommunityView;
|
||||
person?: PersonViewSafe;
|
||||
export class ResolveObjectResponse {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
comment: Option<CommentView>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
post: Option<PostView>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
community: Option<CommunityView>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
person: Option<PersonViewSafe>;
|
||||
}
|
||||
|
||||
export interface ListRegistrationApplications {
|
||||
export class ListRegistrationApplications {
|
||||
/**
|
||||
* Only shows the unread applications (IE those without an admin actor)
|
||||
*/
|
||||
unread_only?: boolean;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
unread_only: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
page: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
limit: Option<number>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
unread_only: Option<boolean>,
|
||||
page: Option<number>,
|
||||
limit: Option<number>,
|
||||
auth: string
|
||||
) {
|
||||
this.unread_only = unread_only;
|
||||
this.page = page;
|
||||
this.limit = limit;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ListRegistrationApplicationsResponse {
|
||||
export class ListRegistrationApplicationsResponse {
|
||||
registration_applications: RegistrationApplicationView[];
|
||||
}
|
||||
|
||||
export interface ApproveRegistrationApplication {
|
||||
export class ApproveRegistrationApplication {
|
||||
id: number;
|
||||
approve: boolean;
|
||||
deny_reason?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
deny_reason: Option<string>;
|
||||
auth: string;
|
||||
|
||||
constructor(
|
||||
id: number,
|
||||
approve: boolean,
|
||||
deny_reason: Option<string>,
|
||||
auth: string
|
||||
) {
|
||||
this.id = id;
|
||||
this.approve = approve;
|
||||
this.deny_reason = deny_reason;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface RegistrationApplicationResponse {
|
||||
export class RegistrationApplicationResponse {
|
||||
registration_application: RegistrationApplicationView;
|
||||
}
|
||||
|
||||
export interface GetUnreadRegistrationApplicationCount {
|
||||
export class GetUnreadRegistrationApplicationCount {
|
||||
auth: string;
|
||||
|
||||
constructor(auth: string) {
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetUnreadRegistrationApplicationCountResponse {
|
||||
export class GetUnreadRegistrationApplicationCountResponse {
|
||||
registration_applications: number;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import { Option, Some } from "@sniptt/monads";
|
||||
import { Expose, Transform } from "class-transformer";
|
||||
import { toUndefined } from "../utils";
|
||||
export const VERSION = "v3";
|
||||
|
||||
/**
|
||||
|
@ -148,48 +151,24 @@ export enum SearchType {
|
|||
Url = "Url",
|
||||
}
|
||||
|
||||
/**
|
||||
* A websocket response. Includes the return type.
|
||||
* Can be used like:
|
||||
*
|
||||
* ```ts
|
||||
* if (op == UserOperation.Search) {
|
||||
* let data = wsJsonToRes<SearchResponse>(msg).data;
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export interface WebSocketResponse<ResponseType> {
|
||||
op: UserOperation;
|
||||
/**
|
||||
* This contains the data for a websocket response.
|
||||
*
|
||||
* The correct response type if given is in [[LemmyHttp]].
|
||||
*/
|
||||
data: ResponseType;
|
||||
}
|
||||
|
||||
/**
|
||||
* A websocket JSON response that includes the errors.
|
||||
*/
|
||||
export interface WebSocketJsonResponse<ResponseType> {
|
||||
op?: string;
|
||||
|
||||
/**
|
||||
* This contains the data for a websocket response.
|
||||
*
|
||||
* The correct response type if given is in [[LemmyHttp]].
|
||||
*/
|
||||
data?: ResponseType;
|
||||
error?: string;
|
||||
reconnect?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* A holder for a site's metadata ( such as opengraph tags ), used for post links.
|
||||
*/
|
||||
export interface SiteMetadata {
|
||||
title?: string;
|
||||
description?: string;
|
||||
image?: string;
|
||||
html?: string;
|
||||
export class SiteMetadata {
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
title: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
description: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
image: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
html: Option<string>;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
import { Option } from "option-t/esm/PlainOption";
|
||||
import { Option, Some } from "@sniptt/monads";
|
||||
import { Expose, Transform } from "class-transformer";
|
||||
import { toUndefined } from "../utils";
|
||||
|
||||
export interface LocalUserSettings {
|
||||
export class LocalUserSettings {
|
||||
id: number;
|
||||
person_id: number;
|
||||
email?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
email: Option<string>;
|
||||
show_nsfw: boolean;
|
||||
theme: string;
|
||||
default_sort_type: number;
|
||||
|
@ -19,43 +24,82 @@ export interface LocalUserSettings {
|
|||
accepted_application: boolean;
|
||||
}
|
||||
|
||||
export interface PersonSafe {
|
||||
export class PersonSafe {
|
||||
id: number;
|
||||
name: string;
|
||||
display_name?: string;
|
||||
avatar?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
display_name: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
avatar: Option<string>;
|
||||
banned: boolean;
|
||||
published: string;
|
||||
updated?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
updated: Option<string>;
|
||||
actor_id: string;
|
||||
bio?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
bio: Option<string>;
|
||||
local: boolean;
|
||||
banner?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
banner: Option<string>;
|
||||
deleted: boolean;
|
||||
inbox_url: string;
|
||||
shared_inbox_url: string;
|
||||
matrix_user_id?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
matrix_user_id: Option<string>;
|
||||
admin: boolean;
|
||||
bot_account: boolean;
|
||||
ban_expires?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
ban_expires: Option<string>;
|
||||
}
|
||||
|
||||
export interface Site {
|
||||
export class Site {
|
||||
id: number;
|
||||
name: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
sidebar: Option<string>;
|
||||
published: string;
|
||||
updated?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
updated: Option<string>;
|
||||
enable_downvotes: boolean;
|
||||
open_registration: boolean;
|
||||
enable_nsfw: boolean;
|
||||
icon?: string;
|
||||
banner?: string;
|
||||
description?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
icon: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
banner: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
description: Option<string>;
|
||||
community_creation_admin_only: boolean;
|
||||
require_email_verification: boolean;
|
||||
require_application: boolean;
|
||||
application_question?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
application_question: Option<string>;
|
||||
private_instance: boolean;
|
||||
default_theme: string;
|
||||
default_post_listing_type: string;
|
||||
|
@ -63,10 +107,13 @@ export interface Site {
|
|||
last_refreshed_at: string;
|
||||
inbox_url: string;
|
||||
public_key: string;
|
||||
legal_information?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
legal_information: Option<string>;
|
||||
}
|
||||
|
||||
export interface PrivateMessage {
|
||||
export class PrivateMessage {
|
||||
id: number;
|
||||
creator_id: number;
|
||||
recipient_id: number;
|
||||
|
@ -74,190 +121,304 @@ export interface PrivateMessage {
|
|||
deleted: boolean;
|
||||
read: boolean;
|
||||
published: string;
|
||||
updated?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
updated: Option<string>;
|
||||
ap_id: string;
|
||||
local: boolean;
|
||||
}
|
||||
|
||||
export interface PostReport {
|
||||
export class PostReport {
|
||||
id: number;
|
||||
creator_id: number;
|
||||
post_id: number;
|
||||
original_post_name: string;
|
||||
original_post_url?: string;
|
||||
original_post_body?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
original_post_url: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
original_post_body: Option<string>;
|
||||
reason: string;
|
||||
resolved: boolean;
|
||||
resolver_id?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
resolver_id: Option<number>;
|
||||
published: string;
|
||||
updated?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
updated: Option<string>;
|
||||
}
|
||||
|
||||
export interface Post {
|
||||
export class Post {
|
||||
id: number;
|
||||
name: string;
|
||||
url?: string;
|
||||
body?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
url: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
body: Option<string>;
|
||||
creator_id: number;
|
||||
community_id: number;
|
||||
removed: boolean;
|
||||
locked: boolean;
|
||||
published: string;
|
||||
updated?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
updated: Option<string>;
|
||||
deleted: boolean;
|
||||
nsfw: boolean;
|
||||
stickied: boolean;
|
||||
embed_title?: string;
|
||||
embed_description?: string;
|
||||
embed_html?: string;
|
||||
thumbnail_url?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
embed_title: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
embed_description: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
embed_html: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
thumbnail_url: Option<string>;
|
||||
ap_id: string;
|
||||
local: boolean;
|
||||
}
|
||||
|
||||
export interface PasswordResetRequest {
|
||||
export class PasswordResetRequest {
|
||||
id: number;
|
||||
local_user_id: number;
|
||||
token_encrypted: string;
|
||||
published: string;
|
||||
}
|
||||
|
||||
export interface ModRemovePost {
|
||||
export class ModRemovePost {
|
||||
id: number;
|
||||
mod_person_id: number;
|
||||
post_id: number;
|
||||
reason?: string;
|
||||
removed?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
reason: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
removed: Option<boolean>;
|
||||
when_: string;
|
||||
}
|
||||
|
||||
export interface ModLockPost {
|
||||
export class ModLockPost {
|
||||
id: number;
|
||||
mod_person_id: number;
|
||||
post_id: number;
|
||||
locked?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
locked: Option<boolean>;
|
||||
when_: string;
|
||||
}
|
||||
|
||||
export interface ModStickyPost {
|
||||
export class ModStickyPost {
|
||||
id: number;
|
||||
mod_person_id: number;
|
||||
post_id: number;
|
||||
stickied?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
stickied: Option<boolean>;
|
||||
when_: string;
|
||||
}
|
||||
|
||||
export interface ModRemoveComment {
|
||||
export class ModRemoveComment {
|
||||
id: number;
|
||||
mod_person_id: number;
|
||||
comment_id: number;
|
||||
reason?: string;
|
||||
removed?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
reason: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
removed: Option<boolean>;
|
||||
when_: string;
|
||||
}
|
||||
|
||||
export interface ModRemoveCommunity {
|
||||
export class ModRemoveCommunity {
|
||||
id: number;
|
||||
mod_person_id: number;
|
||||
community_id: number;
|
||||
reason?: string;
|
||||
removed?: boolean;
|
||||
expires?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
reason: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
removed: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
expires: Option<string>;
|
||||
when_: string;
|
||||
}
|
||||
|
||||
export interface ModBanFromCommunity {
|
||||
export class ModBanFromCommunity {
|
||||
id: number;
|
||||
mod_person_id: number;
|
||||
other_person_id: number;
|
||||
community_id: number;
|
||||
reason?: string;
|
||||
banned?: boolean;
|
||||
expires?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
reason: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
banned: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
expires: Option<string>;
|
||||
when_: string;
|
||||
}
|
||||
|
||||
export interface ModBan {
|
||||
export class ModBan {
|
||||
id: number;
|
||||
mod_person_id: number;
|
||||
other_person_id: number;
|
||||
reason?: string;
|
||||
banned?: boolean;
|
||||
expires?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
reason: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
banned: Option<boolean>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
expires: Option<string>;
|
||||
when_: string;
|
||||
}
|
||||
|
||||
export interface ModAddCommunity {
|
||||
export class ModAddCommunity {
|
||||
id: number;
|
||||
mod_person_id: number;
|
||||
other_person_id: number;
|
||||
community_id: number;
|
||||
removed?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
removed: Option<boolean>;
|
||||
when_: string;
|
||||
}
|
||||
|
||||
export interface ModTransferCommunity {
|
||||
export class ModTransferCommunity {
|
||||
id: number;
|
||||
mod_person_id: number;
|
||||
other_person_id: number;
|
||||
community_id: number;
|
||||
removed?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
removed: Option<boolean>;
|
||||
when_: string;
|
||||
}
|
||||
|
||||
export interface ModAdd {
|
||||
export class ModAdd {
|
||||
id: number;
|
||||
mod_person_id: number;
|
||||
other_person_id: number;
|
||||
removed?: boolean;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
removed: Option<boolean>;
|
||||
when_: string;
|
||||
}
|
||||
|
||||
export interface CommunitySafe {
|
||||
export class CommunitySafe {
|
||||
id: number;
|
||||
name: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
description: Option<string>;
|
||||
removed: boolean;
|
||||
published: string;
|
||||
updated?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
updated: Option<string>;
|
||||
deleted: boolean;
|
||||
nsfw: boolean;
|
||||
actor_id: string;
|
||||
local: boolean;
|
||||
icon?: string;
|
||||
banner?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
icon: Option<string>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
banner: Option<string>;
|
||||
posting_restricted_to_mods: boolean;
|
||||
}
|
||||
|
||||
export interface CommentReport {
|
||||
export class CommentReport {
|
||||
id: number;
|
||||
creator_id: number;
|
||||
comment_id: number;
|
||||
original_comment_text: string;
|
||||
reason: string;
|
||||
resolved: boolean;
|
||||
resolver_id?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
resolver_id: Option<number>;
|
||||
published: string;
|
||||
updated?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
updated: Option<string>;
|
||||
}
|
||||
|
||||
export interface Comment {
|
||||
export class Comment {
|
||||
id: number;
|
||||
creator_id: number;
|
||||
post_id: number;
|
||||
parent_id?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
parent_id: Option<number>;
|
||||
content: string;
|
||||
removed: boolean;
|
||||
read: boolean; // Whether the recipient has read the comment or not
|
||||
published: string;
|
||||
updated?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
updated: Option<string>;
|
||||
deleted: boolean;
|
||||
ap_id: string;
|
||||
local: boolean;
|
||||
}
|
||||
|
||||
export interface PersonMention {
|
||||
export class PersonMention {
|
||||
id: number;
|
||||
recipient_id: number;
|
||||
comment_id: number;
|
||||
|
@ -265,11 +426,17 @@ export interface PersonMention {
|
|||
published: string;
|
||||
}
|
||||
|
||||
export interface RegistrationApplication {
|
||||
export class RegistrationApplication {
|
||||
id: number;
|
||||
local_user_id: number;
|
||||
answer: string;
|
||||
admin_id?: number;
|
||||
deny_reason?: string;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
admin_id: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
deny_reason: Option<string>;
|
||||
published: string;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import { Option, Some } from "@sniptt/monads";
|
||||
import { Expose, Transform } from "class-transformer";
|
||||
import { toUndefined } from "../utils";
|
||||
import {
|
||||
CommentAggregates,
|
||||
CommunityAggregates,
|
||||
|
@ -29,12 +32,12 @@ import {
|
|||
Site,
|
||||
} from "./source";
|
||||
|
||||
export interface PersonViewSafe {
|
||||
export class PersonViewSafe {
|
||||
person: PersonSafe;
|
||||
counts: PersonAggregates;
|
||||
}
|
||||
|
||||
export interface PersonMentionView {
|
||||
export class PersonMentionView {
|
||||
person_mention: PersonMention;
|
||||
comment: Comment;
|
||||
creator: PersonSafe;
|
||||
|
@ -46,27 +49,30 @@ export interface PersonMentionView {
|
|||
subscribed: boolean;
|
||||
saved: boolean;
|
||||
creator_blocked: boolean;
|
||||
my_vote?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
my_vote: Option<number>;
|
||||
}
|
||||
|
||||
export interface LocalUserSettingsView {
|
||||
export class LocalUserSettingsView {
|
||||
local_user: LocalUserSettings;
|
||||
person: PersonSafe;
|
||||
counts: PersonAggregates;
|
||||
}
|
||||
|
||||
export interface SiteView {
|
||||
export class SiteView {
|
||||
site: Site;
|
||||
counts: SiteAggregates;
|
||||
}
|
||||
|
||||
export interface PrivateMessageView {
|
||||
export class PrivateMessageView {
|
||||
private_message: PrivateMessage;
|
||||
creator: PersonSafe;
|
||||
recipient: PersonSafe;
|
||||
}
|
||||
|
||||
export interface PostView {
|
||||
export class PostView {
|
||||
post: Post;
|
||||
creator: PersonSafe;
|
||||
community: CommunitySafe;
|
||||
|
@ -76,25 +82,37 @@ export interface PostView {
|
|||
saved: boolean;
|
||||
read: boolean;
|
||||
creator_blocked: boolean;
|
||||
my_vote?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
my_vote: Option<number>;
|
||||
}
|
||||
|
||||
export interface PostReportView {
|
||||
export class PostReportView {
|
||||
post_report: PostReport;
|
||||
post: Post;
|
||||
community: CommunitySafe;
|
||||
creator: PersonSafe;
|
||||
post_creator: PersonSafe;
|
||||
creator_banned_from_community: boolean;
|
||||
my_vote?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
my_vote: Option<number>;
|
||||
counts: PostAggregates;
|
||||
resolver?: PersonSafe;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
resolver: Option<PersonSafe>;
|
||||
}
|
||||
|
||||
export interface CommentView {
|
||||
export class CommentView {
|
||||
comment: Comment;
|
||||
creator: PersonSafe;
|
||||
recipient?: PersonSafe;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
recipient: Option<PersonSafe>;
|
||||
post: Post;
|
||||
community: CommunitySafe;
|
||||
counts: CommentAggregates;
|
||||
|
@ -102,10 +120,13 @@ export interface CommentView {
|
|||
subscribed: boolean;
|
||||
saved: boolean;
|
||||
creator_blocked: boolean;
|
||||
my_vote?: number;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
my_vote: Option<number>;
|
||||
}
|
||||
|
||||
export interface CommentReportView {
|
||||
export class CommentReportView {
|
||||
comment_report: CommentReport;
|
||||
comment: Comment;
|
||||
post: Post;
|
||||
|
@ -114,51 +135,57 @@ export interface CommentReportView {
|
|||
comment_creator: PersonSafe;
|
||||
counts: CommentAggregates;
|
||||
creator_banned_from_community: boolean;
|
||||
my_vote?: number;
|
||||
resolver?: PersonSafe;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
my_vote: Option<number>;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
resolver: Option<PersonSafe>;
|
||||
}
|
||||
|
||||
export interface ModAddCommunityView {
|
||||
export class ModAddCommunityView {
|
||||
mod_add_community: ModAddCommunity;
|
||||
moderator: PersonSafe;
|
||||
community: CommunitySafe;
|
||||
modded_person: PersonSafe;
|
||||
}
|
||||
|
||||
export interface ModTransferCommunityView {
|
||||
export class ModTransferCommunityView {
|
||||
mod_transfer_community: ModTransferCommunity;
|
||||
moderator: PersonSafe;
|
||||
community: CommunitySafe;
|
||||
modded_person: PersonSafe;
|
||||
}
|
||||
|
||||
export interface ModAddView {
|
||||
export class ModAddView {
|
||||
mod_add: ModAdd;
|
||||
moderator: PersonSafe;
|
||||
modded_person: PersonSafe;
|
||||
}
|
||||
|
||||
export interface ModBanFromCommunityView {
|
||||
export class ModBanFromCommunityView {
|
||||
mod_ban_from_community: ModBanFromCommunity;
|
||||
moderator: PersonSafe;
|
||||
community: CommunitySafe;
|
||||
banned_person: PersonSafe;
|
||||
}
|
||||
|
||||
export interface ModBanView {
|
||||
export class ModBanView {
|
||||
mod_ban: ModBan;
|
||||
moderator: PersonSafe;
|
||||
banned_person: PersonSafe;
|
||||
}
|
||||
|
||||
export interface ModLockPostView {
|
||||
export class ModLockPostView {
|
||||
mod_lock_post: ModLockPost;
|
||||
moderator: PersonSafe;
|
||||
post: Post;
|
||||
community: CommunitySafe;
|
||||
}
|
||||
|
||||
export interface ModRemoveCommentView {
|
||||
export class ModRemoveCommentView {
|
||||
mod_remove_comment: ModRemoveComment;
|
||||
moderator: PersonSafe;
|
||||
comment: Comment;
|
||||
|
@ -167,61 +194,64 @@ export interface ModRemoveCommentView {
|
|||
community: CommunitySafe;
|
||||
}
|
||||
|
||||
export interface ModRemoveCommunityView {
|
||||
export class ModRemoveCommunityView {
|
||||
mod_remove_community: ModRemoveCommunity;
|
||||
moderator: PersonSafe;
|
||||
community: CommunitySafe;
|
||||
}
|
||||
|
||||
export interface ModRemovePostView {
|
||||
export class ModRemovePostView {
|
||||
mod_remove_post: ModRemovePost;
|
||||
moderator: PersonSafe;
|
||||
post: Post;
|
||||
community: CommunitySafe;
|
||||
}
|
||||
|
||||
export interface ModStickyPostView {
|
||||
export class ModStickyPostView {
|
||||
mod_sticky_post: ModStickyPost;
|
||||
moderator: PersonSafe;
|
||||
post: Post;
|
||||
community: CommunitySafe;
|
||||
}
|
||||
|
||||
export interface CommunityFollowerView {
|
||||
export class CommunityFollowerView {
|
||||
community: CommunitySafe;
|
||||
follower: PersonSafe;
|
||||
}
|
||||
|
||||
export interface CommunityBlockView {
|
||||
export class CommunityBlockView {
|
||||
person: PersonSafe;
|
||||
community: CommunitySafe;
|
||||
}
|
||||
|
||||
export interface CommunityModeratorView {
|
||||
export class CommunityModeratorView {
|
||||
community: CommunitySafe;
|
||||
moderator: PersonSafe;
|
||||
}
|
||||
|
||||
export interface CommunityPersonBanView {
|
||||
export class CommunityPersonBanView {
|
||||
community: CommunitySafe;
|
||||
person: PersonSafe;
|
||||
}
|
||||
|
||||
export interface PersonBlockView {
|
||||
export class PersonBlockView {
|
||||
person: PersonSafe;
|
||||
target: PersonSafe;
|
||||
}
|
||||
|
||||
export interface CommunityView {
|
||||
export class CommunityView {
|
||||
community: CommunitySafe;
|
||||
subscribed: boolean;
|
||||
blocked: boolean;
|
||||
counts: CommunityAggregates;
|
||||
}
|
||||
|
||||
export interface RegistrationApplicationView {
|
||||
export class RegistrationApplicationView {
|
||||
registration_application: RegistrationApplication;
|
||||
creator_local_user: LocalUserSettings;
|
||||
creator: PersonSafe;
|
||||
admin?: PersonSafe;
|
||||
@Transform(({ value }) => Some(value), { toClassOnly: true })
|
||||
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
|
||||
@Expose()
|
||||
admin: Option<PersonSafe>;
|
||||
}
|
||||
|
|
8
src/utils.ts
Normal file
8
src/utils.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { Option } from "@sniptt/monads";
|
||||
|
||||
/**
|
||||
* Converts an option to an undefined. Necessary for API requests.
|
||||
*/
|
||||
export function toUndefined<T>(opt: Option<T>) {
|
||||
return opt.isSome() ? opt.unwrap() : undefined;
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
import { ClassConstructor, deserialize, serialize } from "class-transformer";
|
||||
import {
|
||||
CreateComment,
|
||||
CreateCommentLike,
|
||||
|
@ -499,7 +500,7 @@ export class LemmyWebsocket {
|
|||
/**
|
||||
* Gets the site, and your user data.
|
||||
*/
|
||||
getSite(form: GetSite = {}) {
|
||||
getSite(form: GetSite) {
|
||||
return wrapper(UserOperation.GetSite, form);
|
||||
}
|
||||
|
||||
|
@ -645,7 +646,38 @@ export class LemmyWebsocket {
|
|||
}
|
||||
|
||||
function wrapper<MessageType>(op: UserOperation, data: MessageType) {
|
||||
let send = { op: UserOperation[op], data: data };
|
||||
let send = { op: UserOperation[op], data: serialize(data) };
|
||||
console.log(send);
|
||||
return JSON.stringify(send);
|
||||
}
|
||||
|
||||
/**
|
||||
* A websocket JSON response that includes the errors.
|
||||
*/
|
||||
// interface WebSocketJsonResponse {
|
||||
// op?: string;
|
||||
|
||||
// /**
|
||||
// * This contains the data for a websocket response.
|
||||
// *
|
||||
// * The correct response type if given is in [[LemmyHttp]].
|
||||
// */
|
||||
// data?: ResponseType;
|
||||
// error?: string;
|
||||
// reconnect?: boolean;
|
||||
// }
|
||||
|
||||
export function wsUserOp(msg: any): UserOperation {
|
||||
let opStr: string = msg.op;
|
||||
return UserOperation[opStr as keyof typeof UserOperation];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a websocket string response to a usable result
|
||||
*/
|
||||
export function wsJsonToRes<ResponseType>(
|
||||
msg: any,
|
||||
responseClass: ClassConstructor<ResponseType>
|
||||
): ResponseType {
|
||||
return deserialize(responseClass, msg.data);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
"lib": ["es2017", "es7", "es6", "dom"],
|
||||
"outDir": "./dist",
|
||||
"target": "ES5",
|
||||
"experimentalDecorators": true,
|
||||
"moduleResolution": "Node"
|
||||
},
|
||||
"include": [
|
||||
|
|
15
yarn.lock
15
yarn.lock
|
@ -251,6 +251,11 @@
|
|||
"@nodelib/fs.scandir" "2.1.4"
|
||||
fastq "^1.6.0"
|
||||
|
||||
"@sniptt/monads@^0.5.10":
|
||||
version "0.5.10"
|
||||
resolved "https://registry.yarnpkg.com/@sniptt/monads/-/monads-0.5.10.tgz#a80cd00738bbd682d36d36dd36bdc0bddc96eb76"
|
||||
integrity sha512-+agDOv9DpDV+9e2zN/Vmdk+XaqGx5Sykl0fqhqgiJ90r18nsBkxe44DmZ2sA1HYK+MSsBeZBiAr6pq4w+5uhfw==
|
||||
|
||||
"@types/glob@^7.1.1":
|
||||
version "7.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
|
||||
|
@ -539,6 +544,11 @@ chalk@^4.0.0:
|
|||
ansi-styles "^4.1.0"
|
||||
supports-color "^7.1.0"
|
||||
|
||||
class-transformer@^0.5.1:
|
||||
version "0.5.1"
|
||||
resolved "https://registry.yarnpkg.com/class-transformer/-/class-transformer-0.5.1.tgz#24147d5dffd2a6cea930a3250a677addf96ab336"
|
||||
integrity sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==
|
||||
|
||||
clean-stack@^2.0.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
|
||||
|
@ -1583,11 +1593,6 @@ onigasm@^2.2.5:
|
|||
dependencies:
|
||||
lru-cache "^5.1.1"
|
||||
|
||||
option-t@^32.2.0:
|
||||
version "32.2.0"
|
||||
resolved "https://registry.yarnpkg.com/option-t/-/option-t-32.2.0.tgz#9f24f5f36a1237a1302c37c7fef4489f4333eeb2"
|
||||
integrity sha512-dff/0MN6ckHoKVeGNNFYGyWunwFAvKI9FqKDIJlzh7gZ0EZD0hVflTWs7DzznsTPVhV6F+TSSaSIe3bzWi0Z7Q==
|
||||
|
||||
optionator@^0.9.1:
|
||||
version "0.9.1"
|
||||
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499"
|
||||
|
|
Loading…
Reference in a new issue