diff options
Diffstat (limited to 'src/api/stream')
| -rw-r--r-- | src/api/stream/channel.ts | 12 | ||||
| -rw-r--r-- | src/api/stream/home.ts | 16 | ||||
| -rw-r--r-- | src/api/stream/server.ts | 1 |
3 files changed, 28 insertions, 1 deletions
diff --git a/src/api/stream/channel.ts b/src/api/stream/channel.ts new file mode 100644 index 0000000000..d67d77cbf4 --- /dev/null +++ b/src/api/stream/channel.ts @@ -0,0 +1,12 @@ +import * as websocket from 'websocket'; +import * as redis from 'redis'; + +export default function(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient): void { + const channel = request.resourceURL.query.channel; + + // Subscribe channel stream + subscriber.subscribe(`misskey:channel-stream:${channel}`); + subscriber.on('message', (_, data) => { + connection.send(data); + }); +} diff --git a/src/api/stream/home.ts b/src/api/stream/home.ts index 2ab8d3025b..7c8f3bfec8 100644 --- a/src/api/stream/home.ts +++ b/src/api/stream/home.ts @@ -2,7 +2,9 @@ import * as websocket from 'websocket'; import * as redis from 'redis'; import * as debug from 'debug'; +import User from '../models/user'; import serializePost from '../serializers/post'; +import readNotification from '../common/read-notification'; const log = debug('misskey'); @@ -35,6 +37,20 @@ export default function homeStream(request: websocket.request, connection: webso const msg = JSON.parse(data.utf8Data); switch (msg.type) { + case 'alive': + // Update lastUsedAt + User.update({ _id: user._id }, { + $set: { + last_used_at: new Date() + } + }); + break; + + case 'read_notification': + if (!msg.id) return; + readNotification(user._id, msg.id); + break; + case 'capture': if (!msg.id) return; const postId = msg.id; diff --git a/src/api/stream/server.ts b/src/api/stream/server.ts index 6de5337499..0db6643d40 100644 --- a/src/api/stream/server.ts +++ b/src/api/stream/server.ts @@ -14,7 +14,6 @@ export default function homeStream(request: websocket.request, connection: webso ev.addListener('stats', onStats); connection.on('close', () => { - console.log('yooo'); ev.removeListener('stats', onStats); }); } |