import Chart from "../core.js"; import { Notes } from "../../../models/index.js"; import { name, schema } from "./entities/per-user-notes.js"; /** * ユーザーごとのノートに関するチャート */ export default class PerUserNotesChart extends Chart { constructor(){ super(name, schema, true); } async tickMajor(group) { const [count] = await Promise.all([ Notes.countBy({ userId: group }) ]); return { total: count }; } async tickMinor() { return {}; } async update(user, note, isAdditional) { await this.commit({ total: isAdditional ? 1 : -1, inc: isAdditional ? 1 : 0, dec: isAdditional ? 0 : 1, "diffs.normal": note.replyId == null && note.renoteId == null ? isAdditional ? 1 : -1 : 0, "diffs.renote": note.renoteId != null ? isAdditional ? 1 : -1 : 0, "diffs.reply": note.replyId != null ? isAdditional ? 1 : -1 : 0, "diffs.withFile": note.fileIds.length > 0 ? isAdditional ? 1 : -1 : 0 }, user.id); } }