fix
This commit is contained in:
parent
b648e1921b
commit
be65fd66a3
|
@ -160,33 +160,56 @@ export class ReactionService {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
reaction,
|
reaction,
|
||||||
};
|
};
|
||||||
|
if (user.host == null) {
|
||||||
|
const exists = await this.noteReactionsRepository.findOneBy({
|
||||||
|
noteId: note.id,
|
||||||
|
userId: user.id,
|
||||||
|
reaction: record.reaction,
|
||||||
|
});
|
||||||
|
|
||||||
// Create reaction
|
const count = await this.noteReactionsRepository.countBy({
|
||||||
const exists = await this.noteReactionsRepository.findOneBy({
|
noteId: note.id,
|
||||||
noteId: note.id,
|
userId: user.id,
|
||||||
userId: user.id,
|
});
|
||||||
reaction: record.reaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
const count = await this.noteReactionsRepository.countBy({
|
if (count > 3) {
|
||||||
noteId: note.id,
|
throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298');
|
||||||
userId: user.id,
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (count > 3) {
|
if (exists == null) {
|
||||||
throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298');
|
if (user.host == null) {
|
||||||
}
|
await this.noteReactionsRepository.insert(record);
|
||||||
|
} else {
|
||||||
if (exists == null) {
|
throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298');
|
||||||
if (user.host == null) {
|
}
|
||||||
await this.noteReactionsRepository.insert(record);
|
|
||||||
} else {
|
} else {
|
||||||
|
// 同じリアクションがすでにされていたらエラー
|
||||||
throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298');
|
throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 同じリアクションがすでにされていたらエラー
|
try {
|
||||||
throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298');
|
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');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Create reaction
|
||||||
|
|
||||||
// Increment reactions count
|
// Increment reactions count
|
||||||
const sql = `jsonb_set("reactions", '{${reaction}}', (COALESCE("reactions"->>'${reaction}', '0')::int + 1)::text::jsonb)`;
|
const sql = `jsonb_set("reactions", '{${reaction}}', (COALESCE("reactions"->>'${reaction}', '0')::int + 1)::text::jsonb)`;
|
||||||
|
|
|
@ -129,7 +129,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<i class="ti ti-ban"></i>
|
<i class="ti ti-ban"></i>
|
||||||
</button>
|
</button>
|
||||||
<button ref="reactButton" :class="$style.noteFooterButton" class="_button" @click="toggleReact()">
|
<button ref="reactButton" :class="$style.noteFooterButton" class="_button" @click="toggleReact()">
|
||||||
<i v-if="appearNote.reactionAcceptance === 'likeOnly' && appearNote.myReactions?.length >= 3 " class="ti ti-heart-filled" style="color: var(--eventReactionHeart);"></i>
|
<i v-if="appearNote.reactionAcceptance === 'likeOnly' && appearNote.myReactions?.length >= 4 " class="ti ti-heart-filled" style="color: var(--eventReactionHeart);"></i>
|
||||||
<i v-else-if="appearNote.myReactions?.length >= 4 || appearNote.myReaction && appearNote.user.host " class="ti ti-minus" style="color: var(--accent);"></i>
|
<i v-else-if="appearNote.myReactions?.length >= 4 || appearNote.myReaction && appearNote.user.host " class="ti ti-minus" style="color: var(--accent);"></i>
|
||||||
<i v-else-if="appearNote.reactionAcceptance === 'likeOnly'" class="ti ti-heart"></i>
|
<i v-else-if="appearNote.reactionAcceptance === 'likeOnly'" class="ti ti-heart"></i>
|
||||||
<i v-else class="ti ti-plus"></i>
|
<i v-else class="ti ti-plus"></i>
|
||||||
|
|
Loading…
Reference in a new issue