improve(backend): Skip note score incrementing when bots reacted (#9367)

fix

Improved code quality

fix

small fix
This commit is contained in:
CyberRex 2022-12-21 10:23:03 +09:00 committed by GitHub
parent bebcaad23b
commit fe158339da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 7 deletions

View File

@ -198,6 +198,7 @@ export class NoteCreateService {
host: User['host'];
isSilenced: User['isSilenced'];
createdAt: User['createdAt'];
isBot: User['isBot'];
}, data: Option, silent = false): Promise<Note> {
// チャンネル外にリプライしたら対象のスコープに合わせる
// (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
@ -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) {

View File

@ -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) {

View File

@ -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,