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';
|
|
|
|
import { PackedUser } from '../../../../models/repositories/user';
|
2018-10-07 11:06:17 +09:00
|
|
|
|
|
|
|
export default class extends Channel {
|
2018-10-11 23:01:57 +09:00
|
|
|
public readonly chName = 'localTimeline';
|
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();
|
|
|
|
if (meta.disableLocalTimeline) {
|
|
|
|
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) {
|
|
|
|
if ((note.user as PackedUser).host !== null) return;
|
2019-04-07 21:50:36 +09:00
|
|
|
if (note.visibility === 'home') return;
|
|
|
|
|
|
|
|
if (['followers', 'specified'].includes(note.visibility)) {
|
|
|
|
note = await Notes.pack(note.id, this.user, {
|
2018-10-07 11:06:17 +09:00
|
|
|
detail: true
|
|
|
|
});
|
2019-04-07 21:50:36 +09:00
|
|
|
|
|
|
|
if (note.isHidden) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// リプライなら再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, {
|
|
|
|
detail: true
|
|
|
|
});
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|