summaryrefslogtreecommitdiff
path: root/src/server/api/stream/global-timeline.ts
blob: 03852fb1813364abd152bd3c983f15e760a2ff0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import * as websocket from 'websocket';
import Xev from 'xev';

import { IUser } from '../../../models/user';
import Mute from '../../../models/mute';
import shouldMuteThisNote from '../../../misc/should-mute-this-note';

export default async function(
	request: websocket.request,
	connection: websocket.connection,
	subscriber: Xev,
	user: IUser
) {
	const mute = await Mute.find({ muterId: user._id });
	const mutedUserIds = mute.map(m => m.muteeId.toString());

	// Subscribe stream
	subscriber.on('global-timeline', async note => {
		// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
		if (shouldMuteThisNote(note, mutedUserIds)) return;

		connection.send(JSON.stringify({
			type: 'note',
			body: note
		}));
	});
}