2018-10-07 11:06:17 +09:00
|
|
|
import autobind from 'autobind-decorator';
|
|
|
|
import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
|
|
|
|
import Channel from '../channel';
|
2019-04-24 08:11:19 +09:00
|
|
|
import { fetchMeta } from '../../../../misc/fetch-meta';
|
2019-04-07 21:50:36 +09:00
|
|
|
import { Notes } from '../../../../models';
|
2019-04-23 22:35:26 +09:00
|
|
|
import { PackedNote } from '../../../../models/repositories/note';
|
2018-10-07 11:06:17 +09:00
|
|
|
|
|
|
|
export default class extends Channel {
|
2018-10-11 23:01:57 +09:00
|
|
|
public readonly chName = 'globalTimeline';
|
2018-10-11 23:07:20 +09:00
|
|
|
public static shouldShare = true;
|
2018-11-11 02:22:34 +09:00
|
|
|
public static requireCredential = false;
|
2018-10-11 23:01:57 +09:00
|
|
|
|
2018-10-07 11:06:17 +09:00
|
|
|
@autobind
|
|
|
|
public async init(params: any) {
|
2019-01-16 02:30:55 +09:00
|
|
|
const meta = await fetchMeta();
|
2019-01-16 14:54:14 +09:00
|
|
|
if (meta.disableGlobalTimeline) {
|
2019-01-16 02:30:55 +09:00
|
|
|
if (this.user == null || (!this.user.isAdmin && !this.user.isModerator)) return;
|
|
|
|
}
|
|
|
|
|
2018-10-07 11:06:17 +09:00
|
|
|
// Subscribe events
|
2019-04-07 21:50:36 +09:00
|
|
|
this.subscriber.on('notesStream', this.onNote);
|
2018-10-07 11:06:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
2019-04-23 22:35:26 +09:00
|
|
|
private async onNote(note: PackedNote) {
|
2019-04-23 02:50:59 +09:00
|
|
|
if (note.visibility !== 'public') return;
|
|
|
|
|
2019-01-20 19:22:13 +09:00
|
|
|
// リプライなら再pack
|
|
|
|
if (note.replyId != null) {
|
2019-04-07 21:50:36 +09:00
|
|
|
note.reply = await Notes.pack(note.replyId, this.user, {
|
2019-01-20 19:22:13 +09:00
|
|
|
detail: true
|
|
|
|
});
|
|
|
|
}
|
2018-10-07 11:06:17 +09:00
|
|
|
// Renoteなら再pack
|
|
|
|
if (note.renoteId != null) {
|
2019-04-07 21:50:36 +09:00
|
|
|
note.renote = await Notes.pack(note.renoteId, this.user, {
|
2018-10-07 11:06:17 +09:00
|
|
|
detail: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-13 22:13:24 +09:00
|
|
|
// 関係ない返信は除外
|
|
|
|
if (note.reply) {
|
|
|
|
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
|
|
|
|
if (note.reply.userId !== this.user!.id && note.userId !== this.user!.id && note.reply.userId !== note.userId) return;
|
|
|
|
}
|
|
|
|
|
2018-10-07 11:06:17 +09:00
|
|
|
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
|
2019-04-07 21:50:36 +09:00
|
|
|
if (shouldMuteThisNote(note, this.muting)) return;
|
2018-10-07 11:06:17 +09:00
|
|
|
|
|
|
|
this.send('note', note);
|
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
public dispose() {
|
|
|
|
// Unsubscribe events
|
2019-04-07 21:50:36 +09:00
|
|
|
this.subscriber.off('notesStream', this.onNote);
|
2018-10-07 11:06:17 +09:00
|
|
|
}
|
|
|
|
}
|