@ -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
|
||||
};
|
||||
});
|
||||
|
@ -96,6 +96,10 @@ export const meta = {
|
||||
validator: $.optional.bool,
|
||||
},
|
||||
|
||||
hideOnlineStatus: {
|
||||
validator: $.optional.bool,
|
||||
},
|
||||
|
||||
carefulBot: {
|
||||
validator: $.optional.bool,
|
||||
desc: {
|
||||
@ -228,6 +232,7 @@ export default define(meta, async (ps, _user, token) => {
|
||||
if (ps.mutingNotificationTypes !== undefined) profileUpdates.mutingNotificationTypes = ps.mutingNotificationTypes as typeof notificationTypes[number][];
|
||||
if (typeof ps.isLocked === 'boolean') updates.isLocked = ps.isLocked;
|
||||
if (typeof ps.isExplorable === 'boolean') updates.isExplorable = ps.isExplorable;
|
||||
if (typeof ps.hideOnlineStatus === 'boolean') updates.hideOnlineStatus = ps.hideOnlineStatus;
|
||||
if (typeof ps.isBot === 'boolean') updates.isBot = ps.isBot;
|
||||
if (typeof ps.carefulBot === 'boolean') profileUpdates.carefulBot = ps.carefulBot;
|
||||
if (typeof ps.autoAcceptFollowed === 'boolean') profileUpdates.autoAcceptFollowed = ps.autoAcceptFollowed;
|
||||
|
@ -6,6 +6,7 @@ import { ParsedUrlQuery } from 'querystring';
|
||||
import authenticate from './authenticate';
|
||||
import { EventEmitter } from 'events';
|
||||
import { subsdcriber as redisClient } from '../../db/redis';
|
||||
import { Users } from '@/models';
|
||||
|
||||
module.exports = (server: http.Server) => {
|
||||
// Init websocket server
|
||||
@ -45,5 +46,11 @@ module.exports = (server: http.Server) => {
|
||||
connection.send('pong');
|
||||
}
|
||||
});
|
||||
|
||||
if (user) {
|
||||
Users.update(user.id, {
|
||||
lastActiveDate: new Date(),
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user