From 50285bd049a8169a3bbcf74627d3d713af3ff385 Mon Sep 17 00:00:00 2001 From: Anon Date: Sun, 27 Nov 2022 21:25:00 -0600 Subject: [PATCH] Add custom emojis --- src/http.ts | 49 +++++++++++++++++++++++++++ src/interfaces/api/custom_emoji.ts | 54 ++++++++++++++++++++++++++++++ src/interfaces/api/index.ts | 1 + src/interfaces/api/site.ts | 2 ++ src/interfaces/others.ts | 3 ++ src/interfaces/source.ts | 20 +++++++++++ src/interfaces/views.ts | 9 +++++ src/websocket.ts | 26 ++++++++++++++ 8 files changed, 164 insertions(+) create mode 100644 src/interfaces/api/custom_emoji.ts diff --git a/src/http.ts b/src/http.ts index f93231f..1e1d870 100644 --- a/src/http.ts +++ b/src/http.ts @@ -34,6 +34,13 @@ import { RemoveCommunity, TransferCommunity, } from "./interfaces/api/community"; +import { + CreateCustomEmoji, + CustomEmojiResponse, + DeleteCustomEmoji, + DeleteCustomEmojiResponse, + EditCustomEmoji, +} from "./interfaces/api/custom_emoji"; import { AddAdmin, AddAdminResponse, @@ -1154,6 +1161,48 @@ export class LemmyHttp { ); } + /** + * Create a new custom emoji + * + * `HTTP.POST /custom_emoji` + */ + async createCustomEmoji(form: CreateCustomEmoji) { + return this.wrapper( + HttpType.Post, + "/custom_emoji", + form, + CustomEmojiResponse + ); + } + + /** + * Edit an existing custom emoji + * + * `HTTP.PUT /custom_emoji` + */ + async editCustomEmoji(form: EditCustomEmoji) { + return this.wrapper( + HttpType.Put, + "/custom_emoji", + form, + CustomEmojiResponse + ); + } + + /** + * Delete a custom emoji + * + * `HTTP.Post /custom_emoji/delete` + */ + async deleteCustomEmoji(form: DeleteCustomEmoji) { + return this.wrapper( + HttpType.Post, + "/custom_emoji/delete", + form, + DeleteCustomEmojiResponse + ); + } + private buildFullUrl(endpoint: string): string { return `${this.apiUrl}${endpoint}`; } diff --git a/src/interfaces/api/custom_emoji.ts b/src/interfaces/api/custom_emoji.ts new file mode 100644 index 0000000..47386b0 --- /dev/null +++ b/src/interfaces/api/custom_emoji.ts @@ -0,0 +1,54 @@ +import "reflect-metadata"; +import { CustomEmojiView } from "../views"; + +export class CreateCustomEmoji { + category: string; + shortcode: string; + image_url: string; + alt_text: string; + keywords: string[]; + auth: string; + + constructor(init: CreateCustomEmoji) { + Object.assign(this, init); + } +} + +export class EditCustomEmoji { + id: number; + category: string; + image_url: string; + alt_text: string; + keywords: string[]; + auth: string; + + constructor(init: EditCustomEmoji) { + Object.assign(this, init); + } +} + +export class DeleteCustomEmoji { + id: number; + auth: string; + + constructor(init: DeleteCustomEmoji) { + Object.assign(this, init); + } +} + +export class DeleteCustomEmojiResponse { + id: number; + success: boolean; + + constructor(init: DeleteCustomEmojiResponse) { + Object.assign(this, init); + } +} + +export class CustomEmojiResponse { + custom_emoji: CustomEmojiView; + + constructor(init: CustomEmojiResponse) { + Object.assign(this, init); + } +} diff --git a/src/interfaces/api/index.ts b/src/interfaces/api/index.ts index 81cff4d..e28cc3d 100644 --- a/src/interfaces/api/index.ts +++ b/src/interfaces/api/index.ts @@ -1,5 +1,6 @@ export * from "./comment"; export * from "./community"; +export * from "./custom_emoji"; export * from "./person"; export * from "./post"; export * from "./site"; diff --git a/src/interfaces/api/site.ts b/src/interfaces/api/site.ts index d8fd8bb..e5c59a9 100644 --- a/src/interfaces/api/site.ts +++ b/src/interfaces/api/site.ts @@ -10,6 +10,7 @@ import { CommunityFollowerView, CommunityModeratorView, CommunityView, + CustomEmojiView, LocalUserSettingsView, ModAddCommunityView, ModAddView, @@ -194,6 +195,7 @@ export interface GetSiteResponse { all_languages: Language[]; discussion_languages: number[]; taglines?: Tagline[]; + custom_emojis: CustomEmojiView[]; } /** diff --git a/src/interfaces/others.ts b/src/interfaces/others.ts index ea79e06..f1a306c 100644 --- a/src/interfaces/others.ts +++ b/src/interfaces/others.ts @@ -86,6 +86,9 @@ export enum UserOperation { GetReportCount, GetUnreadCount, VerifyEmail, + CreateCustomEmoji, + EditCustomEmoji, + DeleteCustomEmoji, } /** diff --git a/src/interfaces/source.ts b/src/interfaces/source.ts index eb278c2..110d8e6 100644 --- a/src/interfaces/source.ts +++ b/src/interfaces/source.ts @@ -386,3 +386,23 @@ export interface Tagline { published: string; updated?: string; } + +export class CustomEmoji { + id: number; + local_site_id: number; + shortcode: string; + image_url: string; + alt_text: string; + category: string; + published: string; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + updated: Option; +} + +export class CustomEmojiKeyword { + id: number; + custom_emoji_id: number; + keyword: string; +} diff --git a/src/interfaces/views.ts b/src/interfaces/views.ts index 40a95c9..18bce41 100644 --- a/src/interfaces/views.ts +++ b/src/interfaces/views.ts @@ -15,6 +15,8 @@ import { CommentReply, CommentReport, CommunitySafe, + CustomEmoji, + CustomEmojiKeyword, LocalSite, LocalSiteRateLimit, LocalUserSettings, @@ -289,3 +291,10 @@ export interface PrivateMessageReportView { creator: PersonSafe; resolver?: PersonSafe; } + +export class CustomEmojiView { + @Type(() => CustomEmoji) + custom_emoji: CustomEmoji; + @Type(() => CustomEmojiKeyword) + keywords: CustomEmojiKeyword[]; +} diff --git a/src/websocket.ts b/src/websocket.ts index 2afce29..2a6b933 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -23,6 +23,11 @@ import { RemoveCommunity, TransferCommunity, } from "./interfaces/api/community"; +import { + CreateCustomEmoji, + DeleteCustomEmoji, + EditCustomEmoji, +} from "./interfaces/api/custom_emoji"; import { AddAdmin, BanPerson, @@ -682,6 +687,27 @@ export class LemmyWebsocket { purgeComment(form: PurgeComment) { return wrapper(UserOperation.PurgeComment, form); } + + /** + * Create a custom emoji + */ + createCustomEmoji(form: CreateCustomEmoji) { + return wrapper(UserOperation.CreateCustomEmoji, form); + } + + /** + * Edit a custom emoji + */ + editCustomEmoji(form: EditCustomEmoji) { + return wrapper(UserOperation.EditCustomEmoji, form); + } + + /** + * Delete a custom emoji + */ + deleteCustomEmoji(form: DeleteCustomEmoji) { + return wrapper(UserOperation.DeleteCustomEmoji, form); + } } function wrapper(op: UserOperation, data: MessageType) {