summaryrefslogtreecommitdiff
path: root/src/server/api/stream/global-timeline.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-17 14:52:28 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-17 14:52:28 +0900
commita0e640b1189a55c28aafe7d586d531731ad450a4 (patch)
treec8d0ed34511646f1b5a1e68ff24d7510b1c64e7b /src/server/api/stream/global-timeline.ts
parentキューのメモリ使用量を削減 (diff)
downloadmisskey-a0e640b1189a55c28aafe7d586d531731ad450a4.tar.gz
misskey-a0e640b1189a55c28aafe7d586d531731ad450a4.tar.bz2
misskey-a0e640b1189a55c28aafe7d586d531731ad450a4.zip
ローカルタイムラインとグローバルタイムラインを実装
Diffstat (limited to 'src/server/api/stream/global-timeline.ts')
-rw-r--r--src/server/api/stream/global-timeline.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/server/api/stream/global-timeline.ts b/src/server/api/stream/global-timeline.ts
new file mode 100644
index 0000000000..f31ce17752
--- /dev/null
+++ b/src/server/api/stream/global-timeline.ts
@@ -0,0 +1,39 @@
+import * as websocket from 'websocket';
+import * as redis from 'redis';
+
+import { IUser } from '../../../models/user';
+import Mute from '../../../models/mute';
+
+export default async function(
+ request: websocket.request,
+ connection: websocket.connection,
+ subscriber: redis.RedisClient,
+ user: IUser
+) {
+ // Subscribe stream
+ subscriber.subscribe(`misskey:global-timeline`);
+
+ const mute = await Mute.find({ muterId: user._id });
+ const mutedUserIds = mute.map(m => m.muteeId.toString());
+
+ subscriber.on('message', async (_, data) => {
+ const note = JSON.parse(data);
+
+ //#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
+ if (mutedUserIds.indexOf(note.userId) != -1) {
+ return;
+ }
+ if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
+ return;
+ }
+ if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
+ return;
+ }
+ //#endregion
+
+ connection.send(JSON.stringify({
+ type: 'note',
+ body: note
+ }));
+ });
+}