From 6559c3b910eb938a8e13d8d47528638d66247124 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 3 Apr 2020 16:43:38 +0200 Subject: [PATCH] Get the list of custom emojies --- src/controllers/SettingsController.ts | 14 ++++++++++++++ src/controllers/UserController.ts | 5 ++++- src/entities/CustomEmoji.ts | 6 ++++++ src/helpers/AccountHelper.ts | 2 ++ src/helpers/CustomEmojisHelper.ts | 28 +++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/controllers/SettingsController.ts b/src/controllers/SettingsController.ts index 61dc803..299f4ed 100644 --- a/src/controllers/SettingsController.ts +++ b/src/controllers/SettingsController.ts @@ -285,4 +285,18 @@ export class SettingsController { }) } + + /** + * Convert an emoji into an API entry + * + * @param c The emoji to convert + */ + public static CustomEmojiToAPI(c: CustomEmoji) : any { + return { + id: c.id, + userID: c.userID, + shorcut: c.shorcut, + url: c.url + } + } } \ No newline at end of file diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 020c792..2be7eef 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -5,6 +5,8 @@ import { AccountImage, AccountImageVisibilityLevel } from "../entities/AccountIm import { BackgroundImageHelper } from "../helpers/BackgroundImageHelper"; import { LikesHelper, LikesType } from "../helpers/LikesHelper"; import { FriendsHelper } from "../helpers/FriendsHelper"; +import { CustomEmojisHelper } from "../helpers/CustomEmojisHelper"; +import { SettingsController } from "./SettingsController"; /** * User information controller @@ -76,7 +78,8 @@ export class UserController { "publicPage": user.pageStatus == UserPageStatus.PUBLIC, "openPage": user.pageStatus == UserPageStatus.OPEN, "virtualDirectory": user.hasVirtualDirectory ? user.virtualDirectory : "", - "accountImage": await this.GetAccountImageURL(user.accountImage, h) + "accountImage": await this.GetAccountImageURL(user.accountImage, h), + "customEmojis": (await CustomEmojisHelper.GetListUser(user.id)).map(SettingsController.CustomEmojiToAPI) }; if(advanced) { diff --git a/src/entities/CustomEmoji.ts b/src/entities/CustomEmoji.ts index 76864b9..d5964a5 100644 --- a/src/entities/CustomEmoji.ts +++ b/src/entities/CustomEmoji.ts @@ -4,6 +4,8 @@ * @author Pierre Hubert */ +import { pathUserData } from "../utils/UserDataUtils"; + export interface CustomEmojiBuilder { id: number, userID: number, @@ -23,4 +25,8 @@ export class CustomEmoji implements CustomEmojiBuilder { this[key] = info[key]; } } + + get url() : string { + return pathUserData(this.path, false); + } } \ No newline at end of file diff --git a/src/helpers/AccountHelper.ts b/src/helpers/AccountHelper.ts index 06cd159..43aad75 100644 --- a/src/helpers/AccountHelper.ts +++ b/src/helpers/AccountHelper.ts @@ -522,6 +522,8 @@ export class AccountHelper { // Delete user background image await BackgroundImageHelper.Delete(userID); + + // TODO : Delete custom user emojies // Delete connections to all services await this.DeleteAllUserLoginTokens(userID); diff --git a/src/helpers/CustomEmojisHelper.ts b/src/helpers/CustomEmojisHelper.ts index 2d10a35..0a95b4b 100644 --- a/src/helpers/CustomEmojisHelper.ts +++ b/src/helpers/CustomEmojisHelper.ts @@ -28,4 +28,32 @@ export class CustomEmojisHelper { ) } + /** + * Get the list of emojies of a given user + * + * @param userID Target user ID + */ + public static async GetListUser(userID: number) : Promise { + return (await DatabaseHelper.Query({ + table: EMOJIS_TABLE, + where: { + user_id: userID + } + })).map((e) => this.DbToCustomEmoji(e)); + } + + + /** + * Turn a database entry into a custom emoji + * + * @param row Database entry + */ + private static DbToCustomEmoji(row: any) : CustomEmoji { + return new CustomEmoji({ + id: row.id, + userID: row.user_id, + shorcut: row.shorcut, + path: row.path + }) + } } \ No newline at end of file