1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 05:19:22 +00:00

Get the list of custom emojies

This commit is contained in:
Pierre HUBERT 2020-04-03 16:43:38 +02:00
parent 131735a5f0
commit 6559c3b910
5 changed files with 54 additions and 1 deletions

View File

@ -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
}
}
} }

View File

@ -5,6 +5,8 @@ import { AccountImage, AccountImageVisibilityLevel } from "../entities/AccountIm
import { BackgroundImageHelper } from "../helpers/BackgroundImageHelper"; import { BackgroundImageHelper } from "../helpers/BackgroundImageHelper";
import { LikesHelper, LikesType } from "../helpers/LikesHelper"; import { LikesHelper, LikesType } from "../helpers/LikesHelper";
import { FriendsHelper } from "../helpers/FriendsHelper"; import { FriendsHelper } from "../helpers/FriendsHelper";
import { CustomEmojisHelper } from "../helpers/CustomEmojisHelper";
import { SettingsController } from "./SettingsController";
/** /**
* User information controller * User information controller
@ -76,7 +78,8 @@ export class UserController {
"publicPage": user.pageStatus == UserPageStatus.PUBLIC, "publicPage": user.pageStatus == UserPageStatus.PUBLIC,
"openPage": user.pageStatus == UserPageStatus.OPEN, "openPage": user.pageStatus == UserPageStatus.OPEN,
"virtualDirectory": user.hasVirtualDirectory ? user.virtualDirectory : "", "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) { if(advanced) {

View File

@ -4,6 +4,8 @@
* @author Pierre Hubert * @author Pierre Hubert
*/ */
import { pathUserData } from "../utils/UserDataUtils";
export interface CustomEmojiBuilder { export interface CustomEmojiBuilder {
id: number, id: number,
userID: number, userID: number,
@ -23,4 +25,8 @@ export class CustomEmoji implements CustomEmojiBuilder {
this[key] = info[key]; this[key] = info[key];
} }
} }
get url() : string {
return pathUserData(this.path, false);
}
} }

View File

@ -522,6 +522,8 @@ export class AccountHelper {
// Delete user background image // Delete user background image
await BackgroundImageHelper.Delete(userID); await BackgroundImageHelper.Delete(userID);
// TODO : Delete custom user emojies
// Delete connections to all services // Delete connections to all services
await this.DeleteAllUserLoginTokens(userID); await this.DeleteAllUserLoginTokens(userID);

View File

@ -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<CustomEmoji[]> {
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
})
}
} }