Implement user online status

Resolve #7422
Fix #7424
This commit is contained in:
syuilo 2021-04-17 15:30:26 +09:00
parent 61461b7f59
commit 68571d8f57
10 changed files with 92 additions and 9 deletions

View file

@ -1,6 +1,7 @@
import { USER_ONLINE_THRESHOLD } from '@/const';
import { Users } from '@/models';
import { MoreThan } from 'typeorm';
import define from '../define';
import { redisClient } from '../../../db/redis';
import config from '@/config';
export const meta = {
tags: ['meta'],
@ -11,12 +12,12 @@ export const meta = {
}
};
export default define(meta, (ps, user) => {
return new Promise((res, rej) => {
redisClient.pubsub('numsub', config.host, (_, x) => {
res({
count: x[1]
});
});
export default define(meta, async () => {
const count = await Users.count({
lastActiveDate: MoreThan(new Date(Date.now() - USER_ONLINE_THRESHOLD))
});
return {
count
};
});