summaryrefslogtreecommitdiff
path: root/src/server/api/stream
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-07-11 09:36:30 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-07-11 09:36:30 +0900
commiteb392b125105f9949f84a6fd654694238457a18f (patch)
tree4978826789dd054ba1538b46087d9d438beec3c0 /src/server/api/stream
parentUpdate call.ts (diff)
downloadsharkey-eb392b125105f9949f84a6fd654694238457a18f.tar.gz
sharkey-eb392b125105f9949f84a6fd654694238457a18f.tar.bz2
sharkey-eb392b125105f9949f84a6fd654694238457a18f.zip
wip
Diffstat (limited to 'src/server/api/stream')
-rw-r--r--src/server/api/stream/hybrid-timeline.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/server/api/stream/hybrid-timeline.ts b/src/server/api/stream/hybrid-timeline.ts
new file mode 100644
index 0000000000..55f9fbb788
--- /dev/null
+++ b/src/server/api/stream/hybrid-timeline.ts
@@ -0,0 +1,47 @@
+import * as websocket from 'websocket';
+import * as redis from 'redis';
+
+import { IUser } from '../../../models/user';
+import Mute from '../../../models/mute';
+import { pack } from '../../../models/note';
+
+export default async function(
+ request: websocket.request,
+ connection: websocket.connection,
+ subscriber: redis.RedisClient,
+ user: IUser
+) {
+ // Subscribe stream
+ subscriber.subscribe(`misskey:hybrid-timeline:${user._id}`);
+
+ 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
+
+ // Renoteなら再pack
+ if (note.renoteId != null) {
+ note.renote = await pack(note.renoteId, user, {
+ detail: true
+ });
+ }
+
+ connection.send(JSON.stringify({
+ type: 'note',
+ body: note
+ }));
+ });
+}