mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Check if an emoji with the same shorcut is defined
This commit is contained in:
parent
96ab83af7b
commit
8cc8a83ab6
@ -270,6 +270,12 @@ export class SettingsController {
|
|||||||
*/
|
*/
|
||||||
public static async UploadCustomEmoji(h: RequestHandler) {
|
public static async UploadCustomEmoji(h: RequestHandler) {
|
||||||
const shorcut = h.postEmojiShorcut("shorcut");
|
const shorcut = h.postEmojiShorcut("shorcut");
|
||||||
|
|
||||||
|
// Check if the user has already a shorcut with the same name
|
||||||
|
if(await CustomEmojisHelper.HasUserSimilarShorcut(h.getUserId(), shorcut))
|
||||||
|
h.error(401, "A custom emoji with the same shorcut is already defined!")
|
||||||
|
|
||||||
|
|
||||||
const path = await h.savePostImage("image", "custom_emojies", 72, 72);
|
const path = await h.savePostImage("image", "custom_emojies", 72, 72);
|
||||||
|
|
||||||
// Create the emoji
|
// Create the emoji
|
||||||
|
@ -29,6 +29,24 @@ export class CustomEmojisHelper {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a given user has already a custom emoji with
|
||||||
|
* the same shorcut
|
||||||
|
*
|
||||||
|
* @param userID Target user ID
|
||||||
|
* @param shorcut The name of the shorcut to check
|
||||||
|
*/
|
||||||
|
public static async HasUserSimilarShorcut(userID: number, shorcut: string) : Promise<boolean> {
|
||||||
|
return await DatabaseHelper.Count({
|
||||||
|
table: EMOJIS_TABLE,
|
||||||
|
where: {
|
||||||
|
user_id: userID,
|
||||||
|
shorcut: shorcut
|
||||||
|
}
|
||||||
|
}) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of emojies of a given user
|
* Get the list of emojies of a given user
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user