2018-10-07 05:06:17 +03:00
|
|
|
import autobind from 'autobind-decorator';
|
2021-08-19 15:55:45 +03:00
|
|
|
import Channel from '../channel';
|
|
|
|
import { Notes } from '@/models/index';
|
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) {
|
|
|
|
// Subscribe main stream channel
|
2019-04-12 19:43:22 +03:00
|
|
|
this.subscriber.on(`mainStream:${this.user!.id}`, async data => {
|
2020-03-04 04:45:33 +02:00
|
|
|
const { type } = data;
|
|
|
|
let { body } = data;
|
2018-10-07 05:06:17 +03:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 'notification': {
|
2021-01-30 04:09:46 +02:00
|
|
|
if (this.muting.has(body.userId)) return;
|
2019-09-23 21:58:00 +03:00
|
|
|
if (body.note && body.note.isHidden) {
|
2021-03-21 10:38:09 +02:00
|
|
|
const note = await Notes.pack(body.note.id, this.user, {
|
2019-09-23 21:58:00 +03:00
|
|
|
detail: true
|
|
|
|
});
|
2021-03-21 10:38:09 +02:00
|
|
|
this.connection.cacheNote(note);
|
|
|
|
body.note = note;
|
2019-09-23 21:58:00 +03:00
|
|
|
}
|
2019-01-24 17:06:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'mention': {
|
2021-01-30 04:09:46 +02:00
|
|
|
if (this.muting.has(body.userId)) return;
|
2019-09-23 21:58:00 +03:00
|
|
|
if (body.isHidden) {
|
2021-03-21 10:38:09 +02:00
|
|
|
const note = await Notes.pack(body.id, this.user, {
|
2019-09-23 21:58:00 +03:00
|
|
|
detail: true
|
|
|
|
});
|
2021-03-21 10:38:09 +02:00
|
|
|
this.connection.cacheNote(note);
|
|
|
|
body = note;
|
2019-09-23 21:58:00 +03:00
|
|
|
}
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|