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