2018-10-07 04:06:17 +02:00
|
|
|
import autobind from 'autobind-decorator';
|
|
|
|
import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
|
|
|
|
import Channel from '../channel';
|
2019-04-24 01:11:19 +02:00
|
|
|
import { fetchMeta } from '../../../../misc/fetch-meta';
|
2019-04-07 14:50:36 +02:00
|
|
|
import { Notes } from '../../../../models';
|
2019-04-23 15:35:26 +02:00
|
|
|
import { PackedNote } from '../../../../models/repositories/note';
|
2018-10-07 04:06:17 +02:00
|
|
|
|
|
|
|
export default class extends Channel {
|
2018-10-11 16:01:57 +02:00
|
|
|
public readonly chName = 'globalTimeline';
|
2018-10-11 16:07:20 +02:00
|
|
|
public static shouldShare = true;
|
2018-11-10 18:22:34 +01:00
|
|
|
public static requireCredential = false;
|
2018-10-11 16:01:57 +02:00
|
|
|
|
2018-10-07 04:06:17 +02:00
|
|
|
@autobind
|
|
|
|
public async init(params: any) {
|
2019-01-15 18:30:55 +01:00
|
|
|
const meta = await fetchMeta();
|
2019-01-16 06:54:14 +01:00
|
|
|
if (meta.disableGlobalTimeline) {
|
2019-01-15 18:30:55 +01:00
|
|
|
if (this.user == null || (!this.user.isAdmin && !this.user.isModerator)) return;
|
|
|
|
}
|
|
|
|
|
2018-10-07 04:06:17 +02:00
|
|
|
// Subscribe events
|
2019-04-07 14:50:36 +02:00
|
|
|
this.subscriber.on('notesStream', this.onNote);
|
2018-10-07 04:06:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
2019-04-23 15:35:26 +02:00
|
|
|
private async onNote(note: PackedNote) {
|
2019-04-22 19:50:59 +02:00
|
|
|
if (note.visibility !== 'public') return;
|
|
|
|
|
2019-01-20 11:22:13 +01:00
|
|
|
// リプライなら再pack
|
|
|
|
if (note.replyId != null) {
|
2019-04-07 14:50:36 +02:00
|
|
|
note.reply = await Notes.pack(note.replyId, this.user, {
|
2019-01-20 11:22:13 +01:00
|
|
|
detail: true
|
|
|
|
});
|
|
|
|
}
|
2018-10-07 04:06:17 +02:00
|
|
|
// Renoteなら再pack
|
|
|
|
if (note.renoteId != null) {
|
2019-04-07 14:50:36 +02:00
|
|
|
note.renote = await Notes.pack(note.renoteId, this.user, {
|
2018-10-07 04:06:17 +02:00
|
|
|
detail: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-13 14:13:24 +01: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 04:06:17 +02:00
|
|
|
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
|
2019-04-07 14:50:36 +02:00
|
|
|
if (shouldMuteThisNote(note, this.muting)) return;
|
2018-10-07 04:06:17 +02:00
|
|
|
|
|
|
|
this.send('note', note);
|
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
public dispose() {
|
|
|
|
// Unsubscribe events
|
2019-04-07 14:50:36 +02:00
|
|
|
this.subscriber.off('notesStream', this.onNote);
|
2018-10-07 04:06:17 +02:00
|
|
|
}
|
|
|
|
}
|