diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-04-18 23:25:55 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-04-18 23:25:55 +0900 |
| commit | 631091940ba13f23dd705596a243c8c585f0d64e (patch) | |
| tree | 571966ad2bf8dde14026b4d253c0bb2d597c580f /src/server/api | |
| parent | Merge branch 'develop' (diff) | |
| parent | 12.77.1 (diff) | |
| download | misskey-631091940ba13f23dd705596a243c8c585f0d64e.tar.gz misskey-631091940ba13f23dd705596a243c8c585f0d64e.tar.bz2 misskey-631091940ba13f23dd705596a243c8c585f0d64e.zip | |
Merge branch 'develop'
Diffstat (limited to 'src/server/api')
| -rw-r--r-- | src/server/api/endpoints/notifications/read.ts | 42 | ||||
| -rw-r--r-- | src/server/api/streaming.ts | 18 |
2 files changed, 54 insertions, 6 deletions
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]); +}); 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(), - }); - } }); }; |