* wip * wip * wip * wip * wip * Update define.ts * Update update.ts * Update user.ts * wip * wip * Update request.ts * URL * wip * wip * wip * wip * Update invite.ts * Update create.ts
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import autobind from 'autobind-decorator';
|
|
import Chart, { DeepPartial } from '../../core';
|
|
import { User } from '../../../../models/entities/user';
|
|
import { Note } from '../../../../models/entities/note';
|
|
import { SchemaType } from '@/misc/schema';
|
|
import { Users } from '../../../../models';
|
|
import { name, schema } from '../schemas/per-user-reactions';
|
|
|
|
type PerUserReactionsLog = SchemaType<typeof schema>;
|
|
|
|
export default class PerUserReactionsChart extends Chart<PerUserReactionsLog> {
|
|
constructor() {
|
|
super(name, schema, true);
|
|
}
|
|
|
|
@autobind
|
|
protected genNewLog(latest: PerUserReactionsLog): DeepPartial<PerUserReactionsLog> {
|
|
return {};
|
|
}
|
|
|
|
@autobind
|
|
protected aggregate(logs: PerUserReactionsLog[]): PerUserReactionsLog {
|
|
return {
|
|
local: {
|
|
count: logs.reduce((a, b) => a + b.local.count, 0),
|
|
},
|
|
remote: {
|
|
count: logs.reduce((a, b) => a + b.remote.count, 0),
|
|
},
|
|
};
|
|
}
|
|
|
|
@autobind
|
|
protected async fetchActual(group: string): Promise<DeepPartial<PerUserReactionsLog>> {
|
|
return {};
|
|
}
|
|
|
|
@autobind
|
|
public async update(user: { id: User['id'], host: User['host'] }, note: Note) {
|
|
this.inc({
|
|
[Users.isLocalUser(user) ? 'local' : 'remote']: { count: 1 }
|
|
}, note.userId);
|
|
}
|
|
}
|