summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/CustomEmojiService.ts
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-11-08 15:52:37 +0000
committerdakkar <dakkar@thenautilus.net>2024-11-08 15:52:37 +0000
commitf079edaf3ccc1fea9242f0f8522ebbfc7e8242e4 (patch)
treeead184cf29c147bc74ed92ce905b46e5e42209c1 /packages/backend/src/core/CustomEmojiService.ts
parentmerge: Bump version number (!735) (diff)
parentRelease: 2024.10.1 (diff)
downloadsharkey-f079edaf3ccc1fea9242f0f8522ebbfc7e8242e4.tar.gz
sharkey-f079edaf3ccc1fea9242f0f8522ebbfc7e8242e4.tar.bz2
sharkey-f079edaf3ccc1fea9242f0f8522ebbfc7e8242e4.zip
Merge tag '2024.10.1' into feature/2024.10
Diffstat (limited to 'packages/backend/src/core/CustomEmojiService.ts')
-rw-r--r--packages/backend/src/core/CustomEmojiService.ts29
1 files changed, 22 insertions, 7 deletions
diff --git a/packages/backend/src/core/CustomEmojiService.ts b/packages/backend/src/core/CustomEmojiService.ts
index cd906a72af..cc33fb5c0b 100644
--- a/packages/backend/src/core/CustomEmojiService.ts
+++ b/packages/backend/src/core/CustomEmojiService.ts
@@ -112,19 +112,33 @@ export class CustomEmojiService implements OnApplicationShutdown {
}
@bindThis
- public async update(id: MiEmoji['id'], data: {
+ public async update(data: (
+ { id: MiEmoji['id'], name?: string; } | { name: string; id?: MiEmoji['id'], }
+ ) & {
driveFile?: MiDriveFile;
- name?: string;
category?: string | null;
aliases?: string[];
license?: string | null;
isSensitive?: boolean;
localOnly?: boolean;
roleIdsThatCanBeUsedThisEmojiAsReaction?: MiRole['id'][];
- }, moderator?: MiUser): Promise<void> {
- const emoji = await this.emojisRepository.findOneByOrFail({ id: id });
- const sameNameEmoji = await this.emojisRepository.findOneBy({ name: data.name, host: IsNull() });
- if (sameNameEmoji != null && sameNameEmoji.id !== id) throw new Error('name already exists');
+ }, moderator?: MiUser): Promise<
+ null
+ | 'NO_SUCH_EMOJI'
+ | 'SAME_NAME_EMOJI_EXISTS'
+ > {
+ const emoji = data.id
+ ? await this.getEmojiById(data.id)
+ : await this.getEmojiByName(data.name!);
+ if (emoji === null) return 'NO_SUCH_EMOJI';
+ const id = emoji.id;
+
+ // IDと絵文字名が両方指定されている場合は絵文字名の変更を行うため重複チェックが必要
+ const doNameUpdate = data.id && data.name && (data.name !== emoji.name);
+ if (doNameUpdate) {
+ const isDuplicate = await this.checkDuplicate(data.name!);
+ if (isDuplicate) return 'SAME_NAME_EMOJI_EXISTS';
+ }
await this.emojisRepository.update(emoji.id, {
updatedAt: new Date(),
@@ -151,7 +165,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
const packed = await this.emojiEntityService.packDetailed(emoji.id);
- if (emoji.name === data.name) {
+ if (!doNameUpdate) {
this.globalEventService.publishBroadcastStream('emojiUpdated', {
emojis: [packed],
});
@@ -173,6 +187,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
after: updated,
});
}
+ return null;
}
@bindThis