From fe158339da85c0dc9674509d416d132435cbbdcf Mon Sep 17 00:00:00 2001 From: CyberRex Date: Wed, 21 Dec 2022 10:23:03 +0900 Subject: [PATCH] improve(backend): Skip note score incrementing when bots reacted (#9367) fix Improved code quality fix small fix --- packages/backend/src/core/NoteCreateService.ts | 4 +++- packages/backend/src/core/NoteDeleteService.ts | 4 ++-- packages/backend/src/core/ReactionService.ts | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index b0a8f03af..e9c225231 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -198,6 +198,7 @@ export class NoteCreateService { host: User['host']; isSilenced: User['isSilenced']; createdAt: User['createdAt']; + isBot: User['isBot']; }, data: Option, silent = false): Promise { // チャンネル外にリプライしたら対象のスコープに合わせる // (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで) @@ -415,6 +416,7 @@ export class NoteCreateService { host: User['host']; isSilenced: User['isSilenced']; createdAt: User['createdAt']; + isBot: User['isBot']; }, data: Option, silent: boolean, tags: string[], mentionedUsers: MinimumUser[]) { // 統計を更新 this.notesChart.update(note, true); @@ -484,7 +486,7 @@ export class NoteCreateService { // この投稿を除く指定したユーザーによる指定したノートのリノートが存在しないとき if (data.renote && (await this.noteEntityService.countSameRenotes(user.id, data.renote.id, note.id) === 0)) { - this.incRenoteCount(data.renote); + if (!user.isBot) this.incRenoteCount(data.renote); } if (data.poll && data.poll.expiresAt) { diff --git a/packages/backend/src/core/NoteDeleteService.ts b/packages/backend/src/core/NoteDeleteService.ts index 7331d0355..1313fcbd3 100644 --- a/packages/backend/src/core/NoteDeleteService.ts +++ b/packages/backend/src/core/NoteDeleteService.ts @@ -49,13 +49,13 @@ export class NoteDeleteService { * @param user 投稿者 * @param note 投稿 */ - async delete(user: { id: User['id']; uri: User['uri']; host: User['host']; }, note: Note, quiet = false) { + async delete(user: { id: User['id']; uri: User['uri']; host: User['host']; isBot: User['isBot']; }, note: Note, quiet = false) { const deletedAt = new Date(); // この投稿を除く指定したユーザーによる指定したノートのリノートが存在しないとき if (note.renoteId && (await this.noteEntityService.countSameRenotes(user.id, note.renoteId, note.id)) === 0) { this.notesRepository.decrement({ id: note.renoteId }, 'renoteCount', 1); - this.notesRepository.decrement({ id: note.renoteId }, 'score', 1); + if (!user.isBot) this.notesRepository.decrement({ id: note.renoteId }, 'score', 1); } if (note.replyId) { diff --git a/packages/backend/src/core/ReactionService.ts b/packages/backend/src/core/ReactionService.ts index 09022b57a..1775d5422 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,