2018-10-22 15:36:35 -05:00
|
|
|
import autobind from 'autobind-decorator';
|
2018-10-22 19:59:43 -05:00
|
|
|
import Chart, { Obj } from './';
|
|
|
|
import { IUser, isLocalUser } from '../models/user';
|
|
|
|
import db from '../db/mongodb';
|
2018-10-22 15:36:35 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ハッシュタグに関するチャート
|
|
|
|
*/
|
|
|
|
type HashtagLog = {
|
2018-10-22 19:59:43 -05:00
|
|
|
local: {
|
|
|
|
/**
|
|
|
|
* 投稿された数
|
|
|
|
*/
|
|
|
|
count: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
remote: HashtagLog['local'];
|
2018-10-22 15:36:35 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class HashtagChart extends Chart<HashtagLog> {
|
|
|
|
constructor() {
|
|
|
|
super('hashtag', true);
|
2018-10-22 19:59:43 -05:00
|
|
|
|
|
|
|
// 後方互換性のため
|
|
|
|
db.get('chart.hashtag').findOne().then(doc => {
|
|
|
|
if (doc != null && doc.data.local == null) {
|
|
|
|
db.get('chart.hashtag').drop();
|
|
|
|
}
|
|
|
|
});
|
2018-10-22 15:36:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
protected async getTemplate(init: boolean, latest?: HashtagLog): Promise<HashtagLog> {
|
|
|
|
return {
|
2018-10-22 19:59:43 -05:00
|
|
|
local: {
|
|
|
|
count: 0
|
|
|
|
},
|
|
|
|
remote: {
|
|
|
|
count: 0
|
|
|
|
}
|
2018-10-22 15:36:35 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
2018-10-22 19:59:43 -05:00
|
|
|
public async update(hashtag: string, user: IUser) {
|
|
|
|
const update: Obj = {
|
2018-10-22 15:36:35 -05:00
|
|
|
count: 1
|
|
|
|
};
|
|
|
|
|
2018-10-22 19:59:43 -05:00
|
|
|
await this.incIfUnique({
|
|
|
|
[isLocalUser(user) ? 'local' : 'remote']: update
|
|
|
|
}, 'users', user._id.toHexString(), hashtag);
|
2018-10-22 15:36:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new HashtagChart();
|