summaryrefslogtreecommitdiff
path: root/src/server/api/stream
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
parentキューのメモリ使用量を削減 (diff)
downloadsharkey-a0e640b1189a55c28aafe7d586d531731ad450a4.tar.gz
sharkey-a0e640b1189a55c28aafe7d586d531731ad450a4.tar.bz2
sharkey-a0e640b1189a55c28aafe7d586d531731ad450a4.zip
ローカルタイムラインとグローバルタイムラインを実装
Diffstat (limited to 'src/server/api/stream')
-rw-r--r--src/server/api/stream/global-timeline.ts39
-rw-r--r--src/server/api/stream/home.ts7
-rw-r--r--src/server/api/stream/local-timeline.ts39
3 files changed, 81 insertions, 4 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
+ }));
+ });
+}
diff --git a/src/server/api/stream/home.ts b/src/server/api/stream/home.ts
index e9c0924f31..a9d6ff241e 100644
--- a/src/server/api/stream/home.ts
+++ b/src/server/api/stream/home.ts
@@ -21,10 +21,7 @@ export default async function(
// Subscribe Home stream channel
subscriber.subscribe(`misskey:user-stream:${user._id}`);
- const mute = await Mute.find({
- muterId: user._id,
- deletedAt: { $exists: false }
- });
+ const mute = await Mute.find({ muterId: user._id });
const mutedUserIds = mute.map(m => m.muteeId.toString());
subscriber.on('message', async (channel, data) => {
@@ -33,6 +30,7 @@ export default async function(
try {
const x = JSON.parse(data);
+ //#region 流れてきたメッセージがミュートしているユーザーが関わるものだったら無視する
if (x.type == 'note') {
if (mutedUserIds.indexOf(x.body.userId) != -1) {
return;
@@ -48,6 +46,7 @@ export default async function(
return;
}
}
+ //#endregion
connection.send(data);
} catch (e) {
diff --git a/src/server/api/stream/local-timeline.ts b/src/server/api/stream/local-timeline.ts
new file mode 100644
index 0000000000..a790ba878b
--- /dev/null
+++ b/src/server/api/stream/local-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:local-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
+ }));
+ });
+}