forked from mirror/misskey
wip
This commit is contained in:
parent
a6edd50a5d
commit
fd0e840138
@ -167,24 +167,12 @@ export class ReactionService {
|
||||
reaction,
|
||||
};
|
||||
|
||||
// Create reaction
|
||||
try {
|
||||
await this.noteReactionsRepository.insert(record);
|
||||
} catch (e) {
|
||||
if (isDuplicateKeyValueError(e)) {
|
||||
const exists = await this.noteReactionsRepository.findOneByOrFail({
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (exists.reaction !== reaction) {
|
||||
// 別のリアクションがすでにされていたら置き換える
|
||||
await this.delete(user, note);
|
||||
await this.noteReactionsRepository.insert(record);
|
||||
} else {
|
||||
// 同じリアクションがすでにされていたらエラー
|
||||
throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298');
|
||||
}
|
||||
// 同じリアクションがすでにされていたらエラー
|
||||
throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298');
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
@ -281,11 +269,12 @@ export class ReactionService {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async delete(user: { id: MiUser['id']; host: MiUser['host']; isBot: MiUser['isBot']; }, note: MiNote) {
|
||||
public async delete(user: { id: MiUser['id']; host: MiUser['host']; isBot: MiUser['isBot']; }, note: MiNote, _reaction?: string | null) {
|
||||
// if already unreacted
|
||||
const exist = await this.noteReactionsRepository.findOneBy({
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
reaction: _reaction ?? FALLBACK,
|
||||
});
|
||||
|
||||
if (exist == null) {
|
||||
|
@ -9,7 +9,8 @@ import { MiUser } from './User.js';
|
||||
import { MiNote } from './Note.js';
|
||||
|
||||
@Entity('note_reaction')
|
||||
@Index(['userId', 'noteId'], { unique: true })
|
||||
@Index(['userId', 'noteId'])
|
||||
@Index(['userId', 'noteId', 'reaction'], { unique: true })
|
||||
export class MiNoteReaction {
|
||||
@PrimaryColumn(id())
|
||||
public id: string;
|
||||
|
Loading…
Reference in New Issue
Block a user