From fe158339da85c0dc9674509d416d132435cbbdcf Mon Sep 17 00:00:00 2001 From: CyberRex Date: Wed, 21 Dec 2022 10:23:03 +0900 Subject: improve(backend): Skip note score incrementing when bots reacted (#9367) fix Improved code quality fix small fix --- packages/backend/src/core/ReactionService.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/backend/src/core/ReactionService.ts') diff --git a/packages/backend/src/core/ReactionService.ts b/packages/backend/src/core/ReactionService.ts index 09022b57ab..1775d54228 100644 --- a/packages/backend/src/core/ReactionService.ts +++ b/packages/backend/src/core/ReactionService.ts @@ -83,7 +83,7 @@ export class ReactionService { } @bindThis - public async create(user: { id: User['id']; host: User['host']; }, note: Note, reaction?: string) { + public async create(user: { id: User['id']; host: User['host']; isBot: User['isBot'] }, note: Note, reaction?: string) { // Check blocking if (note.userId !== user.id) { const block = await this.blockingsRepository.findOneBy({ @@ -139,7 +139,7 @@ export class ReactionService { await this.notesRepository.createQueryBuilder().update() .set({ reactions: () => sql, - score: () => '"score" + 1', + ... (!user.isBot ? { score: () => '"score" + 1' } : {}), }) .where('id = :id', { id: note.id }) .execute(); @@ -199,7 +199,7 @@ export class ReactionService { } @bindThis - public async delete(user: { id: User['id']; host: User['host']; }, note: Note) { + public async delete(user: { id: User['id']; host: User['host']; isBot: User['isBot']; }, note: Note) { // if already unreacted const exist = await this.noteReactionsRepository.findOneBy({ noteId: note.id, @@ -226,7 +226,7 @@ export class ReactionService { .where('id = :id', { id: note.id }) .execute(); - this.notesRepository.decrement({ id: note.id }, 'score', 1); + if (!user.isBot) this.notesRepository.decrement({ id: note.id }, 'score', 1); this.globalEventServie.publishNoteStream(note.id, 'unreacted', { reaction: this.decodeReaction(exist.reaction).reaction, -- cgit v1.2.3-freya