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