summaryrefslogtreecommitdiff
path: root/src/api/stream
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-03-20 13:54:59 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-03-20 13:55:04 +0900
commit0610acbf6eef11a9a85cc35851150cb3cc072785 (patch)
tree8d53c24c38ba7de3c64c4ff780c7f35d828ef554 /src/api/stream
parentMerge pull request #301 from syuilo/greenkeeper/gulp-uglify-2.1.1 (diff)
downloadsharkey-0610acbf6eef11a9a85cc35851150cb3cc072785.tar.gz
sharkey-0610acbf6eef11a9a85cc35851150cb3cc072785.tar.bz2
sharkey-0610acbf6eef11a9a85cc35851150cb3cc072785.zip
#302
Diffstat (limited to 'src/api/stream')
-rw-r--r--src/api/stream/home.ts40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/api/stream/home.ts b/src/api/stream/home.ts
index 975bea4c60..80bced8ac8 100644
--- a/src/api/stream/home.ts
+++ b/src/api/stream/home.ts
@@ -1,10 +1,46 @@
import * as websocket from 'websocket';
import * as redis from 'redis';
+import * as debug from 'debug';
+
+import serializePost from '../serializers/post';
+
+const log = debug('misskey');
export default function homeStream(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user: any): void {
// Subscribe Home stream channel
subscriber.subscribe(`misskey:user-stream:${user._id}`);
- subscriber.on('message', (_, data) => {
- connection.send(data);
+
+ subscriber.on('message', async (channel, data) => {
+ switch (channel.split(':')[1]) {
+ case 'user-stream':
+ connection.send(data);
+ break;
+ case 'post-stream':
+ const postId = channel.split(':')[2];
+ log(`RECEIVED: ${postId} ${data} by @${user.username}`);
+ const post = await serializePost(postId, user, {
+ detail: true
+ });
+ connection.send(JSON.stringify({
+ type: 'post-updated',
+ body: {
+ post: post
+ }
+ }));
+ break;
+ }
+ });
+
+ connection.on('message', data => {
+ const msg = JSON.parse(data.utf8Data);
+
+ switch (msg.type) {
+ case 'capture':
+ if (!msg.id) return;
+ const postId = msg.id;
+ log(`CAPTURE: ${postId} by @${user.username}`);
+ subscriber.subscribe(`misskey:post-stream:${postId}`);
+ break;
+ }
});
}