summaryrefslogtreecommitdiff
path: root/src/api/stream
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-12-22 07:26:23 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-12-22 07:26:23 +0900
commit6575a6de5bbcab9a88448e4366feb77f1845a580 (patch)
tree72a18a518f6e9f03ddf89098098c432ca0570100 /src/api/stream
parentwip (diff)
downloadsharkey-6575a6de5bbcab9a88448e4366feb77f1845a580.tar.gz
sharkey-6575a6de5bbcab9a88448e4366feb77f1845a580.tar.bz2
sharkey-6575a6de5bbcab9a88448e4366feb77f1845a580.zip
wip
Diffstat (limited to 'src/api/stream')
-rw-r--r--src/api/stream/home.ts33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/api/stream/home.ts b/src/api/stream/home.ts
index 7c8f3bfec8..7dcdb5ed73 100644
--- a/src/api/stream/home.ts
+++ b/src/api/stream/home.ts
@@ -3,19 +3,48 @@ import * as redis from 'redis';
import * as debug from 'debug';
import User from '../models/user';
+import Mute from '../models/mute';
import serializePost from '../serializers/post';
import readNotification from '../common/read-notification';
const log = debug('misskey');
-export default function homeStream(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user: any): void {
+export default async function(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user: any) {
// Subscribe Home stream channel
subscriber.subscribe(`misskey:user-stream:${user._id}`);
+ const mute = await Mute.find({
+ muter_id: user._id,
+ deleted_at: { $exists: false }
+ });
+ const mutedUserIds = mute.map(m => m.mutee_id.toString());
+
subscriber.on('message', async (channel, data) => {
switch (channel.split(':')[1]) {
case 'user-stream':
- connection.send(data);
+ try {
+ const x = JSON.parse(data);
+
+ if (x.type == 'post') {
+ if (mutedUserIds.indexOf(x.body.user_id) != -1) {
+ return;
+ }
+ if (x.body.reply != null && mutedUserIds.indexOf(x.body.reply.user_id) != -1) {
+ return;
+ }
+ if (x.body.repost != null && mutedUserIds.indexOf(x.body.repost.user_id) != -1) {
+ return;
+ }
+ } else if (x.type == 'notification') {
+ if (mutedUserIds.indexOf(x.body.user_id) != -1) {
+ return;
+ }
+ }
+
+ connection.send(data);
+ } catch (e) {
+ connection.send(data);
+ }
break;
case 'post-stream':
const postId = channel.split(':')[2];