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

46 lines
1.1 KiB
TypeScript
Raw Normal View History

import autobind from 'autobind-decorator';
import Channel from '../channel';
import { Notes } from '@/models/index';
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 => {
const { type } = data;
let { body } = data;
switch (type) {
case 'notification': {
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
}
break;
}
case 'mention': {
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
}
break;
}
}
2018-10-07 19:56:36 +03:00
this.send(type, body);
});
}
}