diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2021-05-11 12:41:02 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-11 12:41:02 +0900 |
| commit | 917e57d47536aec70c33ea63cb2f3868f21f8242 (patch) | |
| tree | 474d55ffb1e473ce722b0057c26b0cd7dde71192 /src/services/note | |
| parent | change dom order: down elements cover upper ones (#7509) (diff) | |
| download | sharkey-917e57d47536aec70c33ea63cb2f3868f21f8242.tar.gz sharkey-917e57d47536aec70c33ea63cb2f3868f21f8242.tar.bz2 sharkey-917e57d47536aec70c33ea63cb2f3868f21f8242.zip | |
Fix #7431 (#7432)
* Fix #7431
* fix
Diffstat (limited to 'src/services/note')
| -rw-r--r-- | src/services/note/reaction/create.ts | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/services/note/reaction/create.ts b/src/services/note/reaction/create.ts index e2e7fc54ef..ce6ae08b30 100644 --- a/src/services/note/reaction/create.ts +++ b/src/services/note/reaction/create.ts @@ -13,12 +13,13 @@ import { createNotification } from '../../create-notification'; import deleteReaction from './delete'; import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error'; import { NoteReaction } from '../../../models/entities/note-reaction'; +import { IdentifiableError } from '@/misc/identifiable-error'; export default async (user: { id: User['id']; host: User['host']; }, note: Note, reaction?: string) => { // TODO: cache reaction = await toDbReaction(reaction, user.host); - let record: NoteReaction = { + const record: NoteReaction = { id: genId(), createdAt: new Date(), noteId: note.id, @@ -31,17 +32,18 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note, await NoteReactions.insert(record); } catch (e) { if (isDuplicateKeyValueError(e)) { - record = await NoteReactions.findOneOrFail({ + const exists = await NoteReactions.findOneOrFail({ noteId: note.id, userId: user.id, }); - if (record.reaction !== reaction) { + if (exists.reaction !== reaction) { // 別のリアクションがすでにされていたら置き換える await deleteReaction(user, note); + await NoteReactions.insert(record); } else { - // 同じリアクションがすでにされていたら何もしない - return; + // 同じリアクションがすでにされていたらエラー + throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298'); } } else { throw e; |