Sharkey/src/server/api/stream/channels/main.ts

41 lines
960 B
TypeScript
Raw Normal View History

import autobind from 'autobind-decorator';
import Channel from '../channel';
import { Notes } from '../../../../models';
export default class extends Channel {
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;
@autobind
public async init(params: any) {
// Subscribe main stream channel
this.subscriber.on(`mainStream:${this.user!.id}`, async data => {
2019-09-23 21:58:00 +03:00
let { type, body } = data;
switch (type) {
case 'notification': {
if (this.muting.includes(body.userId)) return;
2019-09-23 21:58:00 +03:00
if (body.note && body.note.isHidden) {
body.note = await Notes.pack(body.note.id, this.user, {
detail: true
});
}
break;
}
case 'mention': {
if (this.muting.includes(body.userId)) return;
2019-09-23 21:58:00 +03:00
if (body.isHidden) {
body = await Notes.pack(body.id, this.user, {
detail: true
});
}
break;
}
}
2018-10-07 19:56:36 +03:00
this.send(type, body);
});
}
}