misskey/src/server/api/stream/global-timeline.ts

28 lines
778 B
TypeScript
Raw Normal View History

import * as websocket from 'websocket';
2018-07-30 00:20:27 +02:00
import Xev from 'xev';
import { IUser } from '../../../models/user';
import Mute from '../../../models/mute';
import shouldMuteThisNote from '../../../misc/should-mute-this-note';
export default async function(
request: websocket.request,
connection: websocket.connection,
2018-07-30 00:20:27 +02:00
subscriber: Xev,
user: IUser
) {
const mute = await Mute.find({ muterId: user._id });
const mutedUserIds = mute.map(m => m.muteeId.toString());
2018-07-30 00:20:27 +02:00
// Subscribe stream
subscriber.on('global-timeline', async note => {
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
if (shouldMuteThisNote(note, mutedUserIds)) return;
connection.send(JSON.stringify({
type: 'note',
body: note
}));
});
}