mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-29 05:26:43 -06:00
8d42e94e57
Resolve #3904
48 lines
875 B
TypeScript
48 lines
875 B
TypeScript
import autobind from 'autobind-decorator';
|
|
import Chart, { Obj } from '.';
|
|
import { IUser, isLocalUser } from '../models/user';
|
|
|
|
/**
|
|
* アクティブユーザーに関するチャート
|
|
*/
|
|
type ActiveUsersLog = {
|
|
local: {
|
|
/**
|
|
* アクティブユーザー数
|
|
*/
|
|
count: number;
|
|
};
|
|
|
|
remote: ActiveUsersLog['local'];
|
|
};
|
|
|
|
class ActiveUsersChart extends Chart<ActiveUsersLog> {
|
|
constructor() {
|
|
super('activeUsers');
|
|
}
|
|
|
|
@autobind
|
|
protected async getTemplate(init: boolean, latest?: ActiveUsersLog): Promise<ActiveUsersLog> {
|
|
return {
|
|
local: {
|
|
count: 0
|
|
},
|
|
remote: {
|
|
count: 0
|
|
}
|
|
};
|
|
}
|
|
|
|
@autobind
|
|
public async update(user: IUser) {
|
|
const update: Obj = {
|
|
count: 1
|
|
};
|
|
|
|
await this.incIfUnique({
|
|
[isLocalUser(user) ? 'local' : 'remote']: update
|
|
}, 'users', user._id.toHexString());
|
|
}
|
|
}
|
|
|
|
export default new ActiveUsersChart();
|