summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-04-17 15:30:26 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-04-17 15:30:26 +0900
commit68571d8f577e0a9eb8679e8dd30e11d8b1709340 (patch)
tree623ad0865b76cdb8a4551042530655ef7c22c754 /src/server/api/endpoints
parentImprove client (diff)
downloadsharkey-68571d8f577e0a9eb8679e8dd30e11d8b1709340.tar.gz
sharkey-68571d8f577e0a9eb8679e8dd30e11d8b1709340.tar.bz2
sharkey-68571d8f577e0a9eb8679e8dd30e11d8b1709340.zip
Implement user online status
Resolve #7422 Fix #7424
Diffstat (limited to 'src/server/api/endpoints')
-rw-r--r--src/server/api/endpoints/get-online-users-count.ts19
-rw-r--r--src/server/api/endpoints/i/update.ts5
2 files changed, 15 insertions, 9 deletions
diff --git a/src/server/api/endpoints/get-online-users-count.ts b/src/server/api/endpoints/get-online-users-count.ts
index 150ac9e365..a13363055f 100644
--- a/src/server/api/endpoints/get-online-users-count.ts
+++ b/src/server/api/endpoints/get-online-users-count.ts
@@ -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
+ };
});
diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts
index c0ffd75e23..032dccd91a 100644
--- a/src/server/api/endpoints/i/update.ts
+++ b/src/server/api/endpoints/i/update.ts
@@ -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;