Newer
Older
import autobind from 'autobind-decorator';
import { User } from '@/models/entities/user';
import { Notes } from '@/models/index';
import { Note } from '@/models/entities/note';
import { name, schema } from './entities/per-user-notes';
/**
* ユーザーごとのノートに関するチャート
*/
// eslint-disable-next-line import/no-default-export
export default class PerUserNotesChart extends Chart<typeof schema> {
constructor() {
super(name, schema, true);
}
@autobind
protected async queryCurrentState(group: string): Promise<Partial<KVs<typeof schema>>> {
const [count] = await Promise.all([
Notes.count({ userId: group }),
]);
return {
total: count,
};
}
@autobind
public async update(user: { id: User['id'] }, note: Note, isAdditional: boolean): Promise<void> {
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,