From 49e9fb9001c25378aa396d2a1ccdac1e18456e14 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Wed, 3 May 2023 15:50:43 -0400 Subject: [PATCH] don't update if renoted by bot --- packages/backend/src/remote/activitypub/models/person.ts | 4 ++-- packages/backend/src/services/chart/charts/notes.ts | 8 ++++++-- .../backend/src/services/chart/charts/per-user-notes.ts | 4 +++- packages/backend/src/services/note/create.ts | 6 ++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/remote/activitypub/models/person.ts b/packages/backend/src/remote/activitypub/models/person.ts index 877f5f3323..9e21fa9ff5 100644 --- a/packages/backend/src/remote/activitypub/models/person.ts +++ b/packages/backend/src/remote/activitypub/models/person.ts @@ -191,7 +191,7 @@ export async function createPerson( .map((tag) => normalizeForSearch(tag)) .splice(0, 32); - const isBot = getApType(object) === "Service"; + const isBot = getApType(object) !== "Person"; const bday = person["vcard:bday"]?.match(/^\d{4}-\d{2}-\d{2}/); @@ -502,7 +502,7 @@ export async function updatePerson( emojis: emojiNames, name: truncate(person.name, nameLength), tags, - isBot: getApType(object) === "Service", + isBot: getApType(object) !== "Person", isCat: (person as any).isCat === true, isLocked: !!person.manuallyApprovesFollowers, movedToUri: person.movedTo || null, diff --git a/packages/backend/src/services/chart/charts/notes.ts b/packages/backend/src/services/chart/charts/notes.ts index 9ec347b470..42db60d0cf 100644 --- a/packages/backend/src/services/chart/charts/notes.ts +++ b/packages/backend/src/services/chart/charts/notes.ts @@ -30,7 +30,11 @@ export default class NotesChart extends Chart { return {}; } - public async update(note: Note, isAdditional: boolean): Promise { + public async update( + note: Note, + isAdditional: boolean, + byBot = false, + ): Promise { const prefix = note.userHost === null ? "local" : "remote"; await this.commit({ @@ -44,7 +48,7 @@ export default class NotesChart extends Chart { : -1 : 0, [`${prefix}.diffs.renote`]: - note.renoteId != null ? (isAdditional ? 1 : -1) : 0, + note.renoteId != null && !byBot ? (isAdditional ? 1 : -1) : 0, [`${prefix}.diffs.reply`]: note.replyId != null ? (isAdditional ? 1 : -1) : 0, [`${prefix}.diffs.withFile`]: diff --git a/packages/backend/src/services/chart/charts/per-user-notes.ts b/packages/backend/src/services/chart/charts/per-user-notes.ts index d0190cefd0..22f3fddb77 100644 --- a/packages/backend/src/services/chart/charts/per-user-notes.ts +++ b/packages/backend/src/services/chart/charts/per-user-notes.ts @@ -32,6 +32,7 @@ export default class PerUserNotesChart extends Chart { user: { id: User["id"] }, note: Note, isAdditional: boolean, + byBot = false, ): Promise { await this.commit( { @@ -44,7 +45,8 @@ export default class PerUserNotesChart extends Chart { ? 1 : -1 : 0, - "diffs.renote": note.renoteId != null ? (isAdditional ? 1 : -1) : 0, + "diffs.renote": + note.renoteId != null && !byBot ? (isAdditional ? 1 : -1) : 0, "diffs.reply": note.replyId != null ? (isAdditional ? 1 : -1) : 0, "diffs.withFile": note.fileIds.length > 0 ? (isAdditional ? 1 : -1) : 0, }, diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index f4697b0193..0c06b55cec 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -163,6 +163,7 @@ export default async ( host: User["host"]; isSilenced: User["isSilenced"]; createdAt: User["createdAt"]; + isBot: User["isBot"]; }, data: Option, silent = false, @@ -323,8 +324,8 @@ export default async ( res(note); // 統計を更新 - notesChart.update(note, true); - perUserNotesChart.update(user, note, true); + notesChart.update(note, true, user.isBot); + perUserNotesChart.update(user, note, true, user.isBot); // Register host if (Users.isRemoteUser(user)) { @@ -399,6 +400,7 @@ export default async ( // この投稿を除く指定したユーザーによる指定したノートのリノートが存在しないとき if ( data.renote && + !user.isBot && (await countSameRenotes(user.id, data.renote.id, note.id)) === 0 ) { incRenoteCount(data.renote);