2018-04-17 08:52:28 +03:00
|
|
|
import * as websocket from 'websocket';
|
2018-07-30 01:20:27 +03:00
|
|
|
import Xev from 'xev';
|
2018-04-17 08:52:28 +03:00
|
|
|
|
|
|
|
import { IUser } from '../../../models/user';
|
|
|
|
import Mute from '../../../models/mute';
|
2018-06-12 12:54:36 +03:00
|
|
|
import { pack } from '../../../models/note';
|
2018-04-17 08:52:28 +03:00
|
|
|
|
|
|
|
export default async function(
|
|
|
|
request: websocket.request,
|
|
|
|
connection: websocket.connection,
|
2018-07-30 01:20:27 +03:00
|
|
|
subscriber: Xev,
|
2018-04-17 08:52:28 +03:00
|
|
|
user: IUser
|
|
|
|
) {
|
|
|
|
const mute = await Mute.find({ muterId: user._id });
|
|
|
|
const mutedUserIds = mute.map(m => m.muteeId.toString());
|
|
|
|
|
2018-07-30 01:20:27 +03:00
|
|
|
// Subscribe stream
|
|
|
|
subscriber.on('local-timeline', async note => {
|
2018-04-17 08:52:28 +03:00
|
|
|
//#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
|
|
|
|
if (mutedUserIds.indexOf(note.userId) != -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
|
2018-06-12 12:54:36 +03:00
|
|
|
// Renoteなら再pack
|
|
|
|
if (note.renoteId != null) {
|
|
|
|
note.renote = await pack(note.renoteId, user, {
|
|
|
|
detail: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:52:28 +03:00
|
|
|
connection.send(JSON.stringify({
|
|
|
|
type: 'note',
|
|
|
|
body: note
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|