From f984f56459182375421c4af0a31393a8f411a296 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 18 Apr 2021 22:35:47 +0900 Subject: 精度を高めるためストリーミング接続中に定期的にlastActiveDateを更新するように MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/api/streaming.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/server/api') diff --git a/src/server/api/streaming.ts b/src/server/api/streaming.ts index 7224c23570..57e8c90860 100644 --- a/src/server/api/streaming.ts +++ b/src/server/api/streaming.ts @@ -35,10 +35,22 @@ module.exports = (server: http.Server) => { const main = new MainStreamConnection(connection, ev, user, app); + const intervalId = user ? setInterval(() => { + Users.update(user.id, { + lastActiveDate: new Date(), + }); + }, 1000 * 60 * 5) : null; + if (user) { + Users.update(user.id, { + lastActiveDate: new Date(), + }); + } + connection.once('close', () => { ev.removeAllListeners(); main.dispose(); redisClient.off('message', onRedisMessage); + if (intervalId) clearInterval(intervalId); }); connection.on('message', async (data) => { @@ -46,11 +58,5 @@ module.exports = (server: http.Server) => { connection.send('pong'); } }); - - if (user) { - Users.update(user.id, { - lastActiveDate: new Date(), - }); - } }); }; -- cgit v1.2.3-freya From 7da5eead8a52c842a93047bb4bb180cfca183ec1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 18 Apr 2021 22:51:35 +0900 Subject: Resolve #7457 --- src/server/api/endpoints/notifications/read.ts | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/server/api/endpoints/notifications/read.ts (limited to 'src/server/api') diff --git a/src/server/api/endpoints/notifications/read.ts b/src/server/api/endpoints/notifications/read.ts new file mode 100644 index 0000000000..fe8e5ba44f --- /dev/null +++ b/src/server/api/endpoints/notifications/read.ts @@ -0,0 +1,42 @@ +import $ from 'cafy'; +import { ID } from '@/misc/cafy-id'; +import { publishMainStream } from '../../../../services/stream'; +import define from '../../define'; +import { Notifications } from '../../../../models'; +import { readNotification } from '../../common/read-notification'; +import { ApiError } from '../../error'; + +export const meta = { + tags: ['notifications', 'account'], + + requireCredential: true as const, + + kind: 'write:notifications', + + params: { + notificationId: { + validator: $.type(ID), + }, + }, + + errors: { + noSuchNotification: { + message: 'No such notification.', + code: 'NO_SUCH_NOTIFICATION', + id: 'efa929d5-05b5-47d1-beec-e6a4dbed011e' + }, + }, +}; + +export default define(meta, async (ps, user) => { + const notification = await Notifications.findOne({ + notifieeId: user.id, + id: ps.notificationId, + }); + + if (notification == null) { + throw new ApiError(meta.errors.noSuchNotification); + } + + readNotification(user.id, [notification.id]); +}); -- cgit v1.2.3-freya