diff --git a/src/http.ts b/src/http.ts index b0ab650..487d931 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1097,10 +1097,8 @@ export class LemmyHttp { } function encodeGetParams(p: BodyType): string { - console.log(p); // Necessary to remove the Options let serialized = JSON.parse(serialize(p)); - console.log(serialized); return ( Object.entries(serialized) // TODO test this, it might serialize the undefineds diff --git a/src/interfaces/api/comment.ts b/src/interfaces/api/comment.ts index b6d707d..5d29cf8 100644 --- a/src/interfaces/api/comment.ts +++ b/src/interfaces/api/comment.ts @@ -20,18 +20,8 @@ export class CreateComment { form_id: Option; auth: string; - constructor( - content: string, - parent_id: Option, - post_id: number, - form_id: Option, - auth: string - ) { - this.content = content; - this.parent_id = parent_id; - this.post_id = post_id; - this.form_id = form_id; - this.auth = auth; + constructor(init: CreateComment) { + Object.assign(this, init); } } @@ -47,16 +37,8 @@ export class EditComment { form_id: Option; auth: string; - constructor( - content: string, - comment_id: number, - form_id: Option, - auth: string - ) { - this.content = content; - this.comment_id = comment_id; - this.form_id = form_id; - this.auth = auth; + constructor(init: EditComment) { + Object.assign(this, init); } } @@ -68,10 +50,8 @@ export class DeleteComment { deleted: boolean; auth: string; - constructor(comment_id: number, deleted: boolean, auth: string) { - this.comment_id = comment_id; - this.deleted = deleted; - this.auth = auth; + constructor(init: DeleteComment) { + Object.assign(this, init); } } @@ -87,16 +67,8 @@ export class RemoveComment { reason: Option; auth: string; - constructor( - comment_id: number, - removed: boolean, - reason: Option, - auth: string - ) { - this.comment_id = comment_id; - this.removed = removed; - this.reason = reason; - this.auth = auth; + constructor(init: RemoveComment) { + Object.assign(this, init); } } @@ -108,10 +80,8 @@ export class MarkCommentAsRead { read: boolean; auth: string; - constructor(comment_id: number, read: boolean, auth: string) { - this.comment_id = comment_id; - this.read = read; - this.auth = auth; + constructor(init: MarkCommentAsRead) { + Object.assign(this, init); } } @@ -120,10 +90,8 @@ export class SaveComment { save: boolean; auth: string; - constructor(comment_id: number, save: boolean, auth: string) { - this.comment_id = comment_id; - this.save = save; - this.auth = auth; + constructor(init: SaveComment) { + Object.assign(this, init); } } @@ -144,10 +112,8 @@ export class CreateCommentLike { score: number; auth: string; - constructor(comment_id: number, score: number, auth: string) { - this.comment_id = comment_id; - this.score = score; - this.auth = auth; + constructor(init: CreateCommentLike) { + Object.assign(this, init); } } @@ -191,24 +157,8 @@ export class GetComments { @Expose() auth: Option; - constructor( - type_: Option, - sort: Option, - page: Option, - limit: Option, - community_id: Option, - community_name: Option, - saved_only: Option, - auth: Option - ) { - 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; + constructor(init: GetComments) { + Object.assign(this, init); } } @@ -221,10 +171,8 @@ export class CreateCommentReport { reason: string; auth: string; - constructor(comment_id: number, reason: string, auth: string) { - this.comment_id = comment_id; - this.reason = reason; - this.auth = auth; + constructor(init: CreateCommentReport) { + Object.assign(this, init); } } @@ -240,10 +188,8 @@ export class ResolveCommentReport { resolved: boolean; auth: string; - constructor(report_id: number, resolved: boolean, auth: string) { - this.report_id = report_id; - this.resolved = resolved; - this.auth = auth; + constructor(init: ResolveCommentReport) { + Object.assign(this, init); } } @@ -273,18 +219,8 @@ export class ListCommentReports { unresolved_only: Option; auth: string; - constructor( - page: Option, - limit: Option, - community_id: Option, - unresolved_only: Option, - auth: string - ) { - this.page = page; - this.limit = limit; - this.community_id = community_id; - this.unresolved_only = unresolved_only; - this.auth = auth; + constructor(init: ListCommentReports) { + Object.assign(this, init); } } diff --git a/src/interfaces/api/community.ts b/src/interfaces/api/community.ts index 2c971e4..ccf0086 100644 --- a/src/interfaces/api/community.ts +++ b/src/interfaces/api/community.ts @@ -28,10 +28,8 @@ export class GetCommunity { @Expose() auth: Option; - constructor(id: Option, name: Option, auth: Option) { - this.id = id; - this.name = name; - this.auth = auth; + constructor(init: GetCommunity) { + Object.assign(this, init); } } @@ -70,24 +68,8 @@ export class CreateCommunity { posting_restricted_to_mods: Option; auth: string; - constructor( - name: string, - title: string, - description: Option, - icon: Option, - banner: Option, - nsfw: Option, - posting_restricted_to_mods: Option, - 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; + constructor(init: CreateCommunity) { + Object.assign(this, init); } } @@ -117,18 +99,8 @@ export class ListCommunities { @Expose() auth: Option; - constructor( - type_: Option, - sort: Option, - page: Option, - limit: Option, - auth: Option - ) { - this.type_ = type_; - this.sort = sort; - this.page = page; - this.limit = limit; - this.auth = auth; + constructor(init: ListCommunities) { + Object.assign(this, init); } } @@ -161,22 +133,8 @@ export class BanFromCommunity { expires: Option; auth: string; - constructor( - community_id: number, - person_id: number, - ban: boolean, - remove_data: Option, - reason: Option, - expires: Option, - 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; + constructor(init: BanFromCommunity) { + Object.assign(this, init); } } @@ -191,16 +149,8 @@ export class AddModToCommunity { 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; + constructor(init: AddModToCommunity) { + Object.assign(this, init); } } @@ -239,24 +189,8 @@ export class EditCommunity { posting_restricted_to_mods: Option; auth: string; - constructor( - community_id: number, - title: Option, - description: Option, - icon: Option, - banner: Option, - nsfw: Option, - posting_restricted_to_mods: Option, - 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; + constructor(init: EditCommunity) { + Object.assign(this, init); } } @@ -265,10 +199,8 @@ export class DeleteCommunity { deleted: boolean; auth: string; - constructor(community_id: number, deleted: boolean, auth: string) { - this.community_id = community_id; - this.deleted = deleted; - this.auth = auth; + constructor(init: DeleteCommunity) { + Object.assign(this, init); } } @@ -291,18 +223,8 @@ export class RemoveCommunity { expires: Option; auth: string; - constructor( - community_id: number, - removed: boolean, - reason: Option, - expires: Option, - auth: string - ) { - this.community_id = community_id; - this.removed = removed; - this.reason = reason; - this.expires = expires; - this.auth = auth; + constructor(init: RemoveCommunity) { + Object.assign(this, init); } } @@ -311,10 +233,8 @@ export class FollowCommunity { follow: boolean; auth: string; - constructor(community_id: number, follow: boolean, auth: string) { - this.community_id = community_id; - this.follow = follow; - this.auth = auth; + constructor(init: FollowCommunity) { + Object.assign(this, init); } } @@ -323,10 +243,8 @@ export class TransferCommunity { 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; + constructor(init: TransferCommunity) { + Object.assign(this, init); } } @@ -335,10 +253,8 @@ export class BlockCommunity { block: boolean; auth: string; - constructor(community_id: number, block: boolean, auth: string) { - this.community_id = community_id; - this.block = block; - this.auth = auth; + constructor(init: BlockCommunity) { + Object.assign(this, init); } } diff --git a/src/interfaces/api/person.ts b/src/interfaces/api/person.ts index 0bb7efd..83a63f8 100644 --- a/src/interfaces/api/person.ts +++ b/src/interfaces/api/person.ts @@ -15,9 +15,8 @@ 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; + constructor(init: Login) { + Object.assign(this, init); } } @@ -61,26 +60,8 @@ export class Register { @Expose() answer: Option; - constructor( - username: string, - email: Option, - password: string, - password_verify: string, - show_nsfw: boolean, - captcha_uuid: Option, - captcha_answer: Option, - honeypot: Option, - answer: Option - ) { - 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; + constructor(init: Register) { + Object.assign(this, init); } } @@ -207,46 +188,8 @@ export class SaveUserSettings { show_new_post_notifs: Option; auth: string; - constructor( - show_nsfw: Option, - theme: Option, - default_sort_type: Option, - default_listing_type: Option, - lang: Option, - avatar: Option, - banner: Option, - display_name: Option, - email: Option, - bio: Option, - matrix_user_id: Option, - show_avatars: Option, - show_scores: Option, - send_notifications_to_email: Option, - bot_account: Option, - show_bot_accounts: Option, - show_read_posts: Option, - show_new_post_notifs: Option, - 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; + constructor(init: SaveUserSettings) { + Object.assign(this, init); } } @@ -256,16 +199,8 @@ export class ChangePassword { 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; + constructor(init: ChangePassword) { + Object.assign(this, init); } } @@ -321,24 +256,8 @@ export class GetPersonDetails { @Expose() auth: Option; - constructor( - person_id: Option, - username: Option, - sort: Option, - page: Option, - limit: Option, - community_id: Option, - saved_only: Option, - auth: Option - ) { - 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; + constructor(init: GetPersonDetails) { + Object.assign(this, init); } } @@ -370,10 +289,8 @@ export class AddAdmin { added: boolean; auth: string; - constructor(person_id: number, added: boolean, auth: string) { - this.person_id = person_id; - this.added = added; - this.auth = auth; + constructor(init: AddAdmin) { + Object.assign(this, init); } } @@ -405,20 +322,8 @@ export class BanPerson { expires: Option; auth: string; - constructor( - person_id: number, - ban: boolean, - remove_data: Option, - reason: Option, - expires: Option, - auth: string - ) { - this.person_id = person_id; - this.ban = ban; - this.remove_data = remove_data; - this.reason = reason; - this.expires = expires; - this.auth = auth; + constructor(init: BanPerson) { + Object.assign(this, init); } } @@ -446,18 +351,8 @@ export class GetReplies { unread_only: Option; auth: string; - constructor( - sort: Option, - page: Option, - limit: Option, - unread_only: Option, - auth: string - ) { - this.sort = sort; - this.page = page; - this.limit = limit; - this.unread_only = unread_only; - this.auth = auth; + constructor(init: GetReplies) { + Object.assign(this, init); } } @@ -480,18 +375,8 @@ export class GetPersonMentions { unread_only: Option; auth: string; - constructor( - sort: Option, - page: Option, - limit: Option, - unread_only: Option, - auth: string - ) { - this.sort = sort; - this.page = page; - this.limit = limit; - this.unread_only = unread_only; - this.auth = auth; + constructor(init: GetPersonMentions) { + Object.assign(this, init); } } @@ -500,10 +385,8 @@ export class MarkPersonMentionAsRead { 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; + constructor(init: MarkPersonMentionAsRead) { + Object.assign(this, init); } } @@ -518,9 +401,8 @@ export class DeleteAccount { password: string; auth: string; - constructor(password: string, auth: string) { - this.password = password; - this.auth = auth; + constructor(init: DeleteAccount) { + Object.assign(this, init); } } @@ -529,8 +411,8 @@ export class DeleteAccountResponse {} export class PasswordReset { email: string; - constructor(email: string) { - this.email = email; + constructor(init: PasswordReset) { + Object.assign(this, init); } } @@ -541,10 +423,8 @@ export class PasswordChange { password: string; password_verify: string; - constructor(token: string, password: string, password_verify: string) { - this.token = token; - this.password = password; - this.password_verify = password_verify; + constructor(init: PasswordChange) { + Object.assign(this, init); } } @@ -553,10 +433,8 @@ export class CreatePrivateMessage { recipient_id: number; auth: string; - constructor(content: string, recipient_id: number, auth: string) { - this.content = content; - this.recipient_id = recipient_id; - this.auth = auth; + constructor(init: CreatePrivateMessage) { + Object.assign(this, init); } } @@ -565,10 +443,8 @@ export class EditPrivateMessage { 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; + constructor(init: EditPrivateMessage) { + Object.assign(this, init); } } @@ -577,10 +453,8 @@ export class DeletePrivateMessage { 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; + constructor(init: DeletePrivateMessage) { + Object.assign(this, init); } } @@ -589,10 +463,8 @@ export class MarkPrivateMessageAsRead { 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; + constructor(init: MarkPrivateMessageAsRead) { + Object.assign(this, init); } } @@ -610,6 +482,10 @@ export class GetPrivateMessages { @Expose() limit: Option; auth: string; + + constructor(init: GetPrivateMessages) { + Object.assign(this, init); + } } export class PrivateMessagesResponse { @@ -630,9 +506,8 @@ export class GetReportCount { community_id: Option; auth: string; - constructor(community_id: Option, auth: string) { - this.community_id = community_id; - this.auth = auth; + constructor(init: GetReportCount) { + Object.assign(this, init); } } @@ -648,8 +523,8 @@ export class GetReportCountResponse { export class GetUnreadCount { auth: string; - constructor(auth: string) { - this.auth = auth; + constructor(init: GetUnreadCount) { + Object.assign(this, init); } } @@ -662,8 +537,8 @@ export class GetUnreadCountResponse { export class VerifyEmail { token: string; - constructor(token: string) { - this.token = token; + constructor(init: VerifyEmail) { + Object.assign(this, init); } } @@ -674,10 +549,8 @@ export class BlockPerson { block: boolean; auth: string; - constructor(person_id: number, block: boolean, auth: string) { - this.person_id = person_id; - this.block = block; - this.auth = auth; + constructor(init: BlockPerson) { + Object.assign(this, init); } } @@ -689,8 +562,8 @@ export class BlockPersonResponse { export class GetBannedPersons { auth: string; - constructor(auth: string) { - this.auth = auth; + constructor(init: GetBannedPersons) { + Object.assign(this, init); } } diff --git a/src/interfaces/api/post.ts b/src/interfaces/api/post.ts index 8fa5d97..87d8cbf 100644 --- a/src/interfaces/api/post.ts +++ b/src/interfaces/api/post.ts @@ -31,22 +31,8 @@ export class CreatePost { honeypot: Option; auth: string; - constructor( - name: string, - url: Option, - body: Option, - nsfw: Option, - community_id: number, - honeypot: Option, - 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; + constructor(init: CreatePost) { + Object.assign(this, init); } } @@ -61,9 +47,8 @@ export class GetPost { @Expose() auth: Option; - constructor(id: number, auth: Option) { - this.id = id; - this.auth = auth; + constructor(init: GetPost) { + Object.assign(this, init); } } @@ -112,24 +97,8 @@ export class GetPosts { @Expose() auth: Option; - constructor( - type_: Option, - sort: Option, - page: Option, - limit: Option, - community_id: Option, - community_name: Option, - saved_only: Option, - auth: Option - ) { - 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; + constructor(init: GetPosts) { + Object.assign(this, init); } } @@ -146,10 +115,8 @@ export class CreatePostLike { score: number; auth: string; - constructor(post_id: number, score: number, auth: string) { - this.post_id = post_id; - this.score = score; - this.auth = auth; + constructor(init: CreatePostLike) { + Object.assign(this, init); } } @@ -173,20 +140,8 @@ export class EditPost { nsfw: Option; auth: string; - constructor( - post_id: number, - name: Option, - url: Option, - body: Option, - nsfw: Option, - auth: string - ) { - this.post_id = post_id; - this.name = name; - this.url = url; - this.body = body; - this.nsfw = nsfw; - this.auth = auth; + constructor(init: EditPost) { + Object.assign(this, init); } } @@ -195,10 +150,8 @@ export class DeletePost { deleted: boolean; auth: string; - constructor(post_id: number, deleted: boolean, auth: string) { - this.post_id = post_id; - this.deleted = deleted; - this.auth = auth; + constructor(init: DeletePost) { + Object.assign(this, init); } } @@ -214,16 +167,8 @@ export class RemovePost { reason: Option; auth: string; - constructor( - post_id: number, - removed: boolean, - reason: Option, - auth: string - ) { - this.post_id = post_id; - this.removed = removed; - this.reason = reason; - this.auth = auth; + constructor(init: RemovePost) { + Object.assign(this, init); } } @@ -235,10 +180,8 @@ export class MarkPostAsRead { read: boolean; auth: string; - constructor(post_id: number, read: boolean, auth: string) { - this.post_id = post_id; - this.read = read; - this.auth = auth; + constructor(init: MarkPostAsRead) { + Object.assign(this, init); } } @@ -250,10 +193,8 @@ export class LockPost { locked: boolean; auth: string; - constructor(post_id: number, locked: boolean, auth: string) { - this.post_id = post_id; - this.locked = locked; - this.auth = auth; + constructor(init: LockPost) { + Object.assign(this, init); } } @@ -265,10 +206,8 @@ export class StickyPost { stickied: boolean; auth: string; - constructor(post_id: number, stickied: boolean, auth: string) { - this.post_id = post_id; - this.stickied = stickied; - this.auth = auth; + constructor(init: StickyPost) { + Object.assign(this, init); } } @@ -277,10 +216,8 @@ export class SavePost { save: boolean; auth: string; - constructor(post_id: number, save: boolean, auth: string) { - this.post_id = post_id; - this.save = save; - this.auth = auth; + constructor(init: SavePost) { + Object.assign(this, init); } } @@ -289,10 +226,8 @@ export class CreatePostReport { reason: string; auth: string; - constructor(post_id: number, reason: string, auth: string) { - this.post_id = post_id; - this.reason = reason; - this.auth = auth; + constructor(init: CreatePostReport) { + Object.assign(this, init); } } @@ -308,10 +243,8 @@ export class ResolvePostReport { resolved: boolean; auth: string; - constructor(report_id: number, resolved: boolean, auth: string) { - this.report_id = report_id; - this.resolved = resolved; - this.auth = auth; + constructor(init: ResolvePostReport) { + Object.assign(this, init); } } @@ -340,18 +273,8 @@ export class ListPostReports { unresolved_only: Option; auth: string; - constructor( - page: Option, - limit: Option, - community_id: Option, - unresolved_only: Option, - auth: string - ) { - this.page = page; - this.limit = limit; - this.community_id = community_id; - this.unresolved_only = unresolved_only; - this.auth = auth; + constructor(init: ListPostReports) { + Object.assign(this, init); } } @@ -362,8 +285,8 @@ export class ListPostReportsResponse { export class GetSiteMetadata { url: string; - constructor(url: string) { - this.url = url; + constructor(init: GetSiteMetadata) { + Object.assign(this, init); } } diff --git a/src/interfaces/api/site.ts b/src/interfaces/api/site.ts index 130e7ee..c929519 100644 --- a/src/interfaces/api/site.ts +++ b/src/interfaces/api/site.ts @@ -71,28 +71,8 @@ export class Search { @Expose() auth: Option; - constructor( - q: string, - type_: Option, - community_id: Option, - community_name: Option, - creator_id: Option, - sort: Option, - listing_type: Option, - page: Option, - limit: Option, - auth: Option - ) { - 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; + constructor(init: Search) { + Object.assign(this, init); } } @@ -129,18 +109,8 @@ export class GetModlog { @Expose() auth: Option; - constructor( - mod_person_id: Option, - community_id: Option, - page: Option, - limit: Option, - auth: Option - ) { - this.mod_person_id = mod_person_id; - this.community_id = community_id; - this.page = page; - this.limit = limit; - this.auth = auth; + constructor(init: GetModlog) { + Object.assign(this, init); } } @@ -217,40 +187,8 @@ export class CreateSite { default_post_listing_type: Option; auth: string; - constructor( - name: string, - sidebar: Option, - description: Option, - icon: Option, - banner: Option, - enable_downvotes: Option, - open_registration: Option, - enable_nsfw: Option, - community_creation_admin_only: Option, - require_email_verification: Option, - require_application: Option, - application_question: Option, - private_instance: Option, - default_theme: Option, - default_post_listing_type: Option, - 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; + constructor(init: CreateSite) { + Object.assign(this, init); } } @@ -321,42 +259,8 @@ export class EditSite { default_post_listing_type: Option; auth: string; - constructor( - name: Option, - sidebar: Option, - description: Option, - icon: Option, - banner: Option, - enable_downvotes: Option, - open_registration: Option, - enable_nsfw: Option, - community_creation_admin_only: Option, - require_email_verification: Option, - require_application: Option, - application_question: Option, - private_instance: Option, - default_theme: Option, - legal_information: Option, - default_post_listing_type: Option, - 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; + constructor(init: EditSite) { + Object.assign(this, init); } } @@ -366,8 +270,8 @@ export class GetSite { @Expose() auth: Option; - constructor(auth: Option) { - this.auth = auth; + constructor(init: GetSite) { + Object.assign(this, init); } } @@ -402,27 +306,31 @@ export class GetSiteResponse { /** * Your user info, such as blocks, follows, etc. */ -export interface MyUserInfo { +export class MyUserInfo { local_user_view: LocalUserSettingsView; follows: CommunityFollowerView[]; moderates: CommunityModeratorView[]; community_blocks: CommunityBlockView[]; person_blocks: PersonBlockView[]; + + constructor(init: MyUserInfo) { + Object.assign(this, init); + } } export class LeaveAdmin { auth: string; - constructor(auth: string) { - this.auth = auth; + constructor(init: LeaveAdmin) { + Object.assign(this, init); } } export class GetSiteConfig { auth: string; - constructor(auth: string) { - this.auth = auth; + constructor(init: GetSiteConfig) { + Object.assign(this, init); } } @@ -434,9 +342,8 @@ export class SaveSiteConfig { config_hjson: string; auth: string; - constructor(config_hjson: string, auth: string) { - this.config_hjson = config_hjson; - this.auth = auth; + constructor(init: SaveSiteConfig) { + Object.assign(this, init); } } @@ -450,6 +357,10 @@ export class FederatedInstances { @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() blocked: Option; + + constructor(init: FederatedInstances) { + Object.assign(this, init); + } } export class ResolveObject { @@ -459,9 +370,8 @@ export class ResolveObject { @Expose() auth: Option; - constructor(q: string, auth: Option) { - this.q = q; - this.auth = auth; + constructor(init: ResolveObject) { + Object.assign(this, init); } } @@ -502,16 +412,8 @@ export class ListRegistrationApplications { limit: Option; auth: string; - constructor( - unread_only: Option, - page: Option, - limit: Option, - auth: string - ) { - this.unread_only = unread_only; - this.page = page; - this.limit = limit; - this.auth = auth; + constructor(init: ListRegistrationApplications) { + Object.assign(this, init); } } @@ -528,16 +430,8 @@ export class ApproveRegistrationApplication { deny_reason: Option; auth: string; - constructor( - id: number, - approve: boolean, - deny_reason: Option, - auth: string - ) { - this.id = id; - this.approve = approve; - this.deny_reason = deny_reason; - this.auth = auth; + constructor(init: ApproveRegistrationApplication) { + Object.assign(this, init); } } @@ -548,8 +442,8 @@ export class RegistrationApplicationResponse { export class GetUnreadRegistrationApplicationCount { auth: string; - constructor(auth: string) { - this.auth = auth; + constructor(init: GetUnreadRegistrationApplicationCount) { + Object.assign(this, init); } } diff --git a/src/interfaces/others.ts b/src/interfaces/others.ts index 477d1cb..abb3228 100644 --- a/src/interfaces/others.ts +++ b/src/interfaces/others.ts @@ -171,4 +171,8 @@ export class SiteMetadata { @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() html: Option; + + constructor(init: SiteMetadata) { + Object.assign(this, init); + } }