* Fix #7431

* fix
This commit is contained in:
MeiMei 2021-05-11 12:41:02 +09:00 committed by GitHub
parent b9cad899c6
commit 9e97826c79
2 changed files with 14 additions and 7 deletions

View file

@ -11,6 +11,11 @@ export default async (actor: IRemoteUser, activity: ILike) => {
await extractEmojis(activity.tag || [], actor.host).catch(() => null); await extractEmojis(activity.tag || [], actor.host).catch(() => null);
await create(actor, note, activity._misskey_reaction || activity.content || activity.name); return await create(actor, note, activity._misskey_reaction || activity.content || activity.name).catch(e => {
return `ok`; if (e.id === '51c42bb4-931a-456b-bff7-e5a8a70dd298') {
return 'skip: already reacted';
} else {
throw e;
}
}).then(() => 'ok');
}; };

View file

@ -13,12 +13,13 @@ import { createNotification } from '../../create-notification';
import deleteReaction from './delete'; import deleteReaction from './delete';
import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error'; import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error';
import { NoteReaction } from '../../../models/entities/note-reaction'; 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) => { export default async (user: { id: User['id']; host: User['host']; }, note: Note, reaction?: string) => {
// TODO: cache // TODO: cache
reaction = await toDbReaction(reaction, user.host); reaction = await toDbReaction(reaction, user.host);
let record: NoteReaction = { const record: NoteReaction = {
id: genId(), id: genId(),
createdAt: new Date(), createdAt: new Date(),
noteId: note.id, noteId: note.id,
@ -31,17 +32,18 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note,
await NoteReactions.insert(record); await NoteReactions.insert(record);
} catch (e) { } catch (e) {
if (isDuplicateKeyValueError(e)) { if (isDuplicateKeyValueError(e)) {
record = await NoteReactions.findOneOrFail({ const exists = await NoteReactions.findOneOrFail({
noteId: note.id, noteId: note.id,
userId: user.id, userId: user.id,
}); });
if (record.reaction !== reaction) { if (exists.reaction !== reaction) {
// 別のリアクションがすでにされていたら置き換える // 別のリアクションがすでにされていたら置き換える
await deleteReaction(user, note); await deleteReaction(user, note);
await NoteReactions.insert(record);
} else { } else {
// 同じリアクションがすでにされていたら何もしない // 同じリアクションがすでにされていたらエラー
return; throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298');
} }
} else { } else {
throw e; throw e;