summaryrefslogtreecommitdiff
path: root/src/server/api/stream/channels/main.ts
blob: 5b0705f1d3cf193e426dab5aae15413a5242d66b (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
28
29
import autobind from 'autobind-decorator';
import Mute from '../../../../models/mute';
import Channel from '../channel';

export default class extends Channel {
	public readonly chName = 'main';
	public static shouldShare = true;
	public static requireCredential = true;

	@autobind
	public async init(params: any) {
		const mute = await Mute.find({ muterId: this.user._id });
		const mutedUserIds = mute.map(m => m.muteeId.toString());

		// Subscribe main stream channel
		this.subscriber.on(`mainStream:${this.user._id}`, async data => {
			const { type, body } = data;

			switch (type) {
				case 'notification': {
					if (mutedUserIds.includes(body.userId)) return;
					break;
				}
			}

			this.send(type, body);
		});
	}
}