summaryrefslogtreecommitdiff
path: root/src/server/api/stream/channels/main.ts
blob: 780bc0b89feb30d60b4f88d783da5ff775432a4c (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import autobind from 'autobind-decorator';
import Channel from '../channel';
import { Notes } from '../../../../models';

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

	@autobind
	public async init(params: any) {
		// Subscribe main stream channel
		this.subscriber.on(`mainStream:${this.user!.id}`, async data => {
			const { type } = data;
			let { body } = data;

			switch (type) {
				case 'notification': {
					if (this.muting.has(body.userId)) return;
					if (body.note && body.note.isHidden) {
						const note = await Notes.pack(body.note.id, this.user, {
							detail: true
						});
						this.connection.cacheNote(note);
						body.note = note;
					}
					break;
				}
				case 'mention': {
					if (this.muting.has(body.userId)) return;
					if (body.isHidden) {
						const note = await Notes.pack(body.id, this.user, {
							detail: true
						});
						this.connection.cacheNote(note);
						body = note;
					}
					break;
				}
			}

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