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

42 lines
980 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 16:07:20 +02:00
public static shouldShare = true;
2018-11-10 18:22:34 +01:00
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.includes(body.userId)) return;
2019-09-23 20:58:00 +02: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 20:58:00 +02:00
if (body.isHidden) {
body = await Notes.pack(body.id, this.user, {
detail: true
});
}
break;
}
}
2018-10-07 18:56:36 +02:00
this.send(type, body);
});
}
}