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';
|
|
|
|
import { PackedUser } from '../../../../models/repositories/user';
|
2018-10-07 04:06:17 +02:00
|
|
|
|
|
|
|
export default class extends Channel {
|
2018-10-11 16:01:57 +02:00
|
|
|
public readonly chName = 'localTimeline';
|
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();
|
|
|
|
if (meta.disableLocalTimeline) {
|
|
|
|
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) {
|
|
|
|
if ((note.user as PackedUser).host !== null) return;
|
2019-11-24 00:31:57 +01:00
|
|
|
if (note.visibility !== 'public') return;
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2019-11-24 00:31:57 +01:00
|
|
|
// リプライなら再pack
|
|
|
|
if (note.replyId != null) {
|
|
|
|
note.reply = await Notes.pack(note.replyId, this.user, {
|
|
|
|
detail: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Renoteなら再pack
|
|
|
|
if (note.renoteId != null) {
|
|
|
|
note.renote = await Notes.pack(note.renoteId, this.user, {
|
2018-10-07 04:06:17 +02:00
|
|
|
detail: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// 流れてきた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
|
|
|
}
|
|
|
|
}
|