2018-10-07 05:06:17 +03:00
|
|
|
import autobind from 'autobind-decorator';
|
|
|
|
import Channel from '../channel';
|
2019-04-07 15:50:36 +03:00
|
|
|
import { Mutings } from '../../../../models';
|
2018-10-07 05:06:17 +03:00
|
|
|
|
|
|
|
export default class extends Channel {
|
2018-10-11 17:01:57 +03:00
|
|
|
public readonly chName = 'main';
|
2018-10-11 17:07:20 +03:00
|
|
|
public static shouldShare = true;
|
2018-11-10 19:22:34 +02:00
|
|
|
public static requireCredential = true;
|
2018-10-11 17:01:57 +03:00
|
|
|
|
2018-10-07 05:06:17 +03:00
|
|
|
@autobind
|
|
|
|
public async init(params: any) {
|
2019-04-12 19:43:22 +03:00
|
|
|
const mute = await Mutings.find({ muterId: this.user!.id });
|
2018-10-07 05:06:17 +03:00
|
|
|
|
|
|
|
// Subscribe main stream channel
|
2019-04-12 19:43:22 +03:00
|
|
|
this.subscriber.on(`mainStream:${this.user!.id}`, async data => {
|
2018-10-07 05:06:17 +03:00
|
|
|
const { type, body } = data;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 'notification': {
|
2019-04-07 15:50:36 +03:00
|
|
|
if (mute.map(m => m.muteeId).includes(body.userId)) return;
|
2019-01-24 17:06:20 +02:00
|
|
|
if (body.note && body.note.isHidden) return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'mention': {
|
2019-04-30 09:53:13 +03:00
|
|
|
if (mute.map(m => m.muteeId).includes(body.userId)) return;
|
2019-01-24 17:06:20 +02:00
|
|
|
if (body.isHidden) return;
|
2018-10-07 05:06:17 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-07 19:56:36 +03:00
|
|
|
|
|
|
|
this.send(type, body);
|
2018-10-07 05:06:17 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|