トップページのタイムラインをリアルタイム更新するように

This commit is contained in:
syuilo 2018-09-04 12:59:34 +09:00
parent ba64de334a
commit 6abff253ea
3 changed files with 31 additions and 9 deletions

View file

@ -7,9 +7,9 @@ import MiOS from '../../../mios';
*/ */
export class LocalTimelineStream extends Stream { export class LocalTimelineStream extends Stream {
constructor(os: MiOS, me) { constructor(os: MiOS, me) {
super(os, 'local-timeline', { super(os, 'local-timeline', me ? {
i: me.token i: me.token
}); } : {});
} }
} }

View file

@ -31,15 +31,30 @@ export default Vue.extend({
default: undefined default: undefined
} }
}, },
data() { data() {
return { return {
fetching: true, fetching: true,
notes: [] notes: [],
connection: null,
connectionId: null
}; };
}, },
mounted() { mounted() {
this.fetch(); this.fetch();
this.connection = (this as any).os.streams.localTimelineStream.getConnection();
this.connectionId = (this as any).os.streams.localTimelineStream.use();
this.connection.on('note', this.onNote);
}, },
beforeDestroy() {
this.connection.off('note', this.onNote);
(this as any).os.streams.localTimelineStream.dispose(this.connectionId);
},
methods: { methods: {
fetch(cb?) { fetch(cb?) {
this.fetching = true; this.fetching = true;
@ -49,13 +64,20 @@ export default Vue.extend({
reply: false, reply: false,
renote: false, renote: false,
media: false, media: false,
poll: false, poll: false
bot: false
}).then(notes => { }).then(notes => {
this.notes = notes; this.notes = notes;
this.fetching = false; this.fetching = false;
}); });
} },
onNote(note) {
if (note.replyId != null) return;
if (note.renoteId != null) return;
if (note.poll != null) return;
this.notes.unshift(note);
},
} }
}); });
</script> </script>

View file

@ -3,7 +3,7 @@ import { EventEmitter } from 'eventemitter3';
import * as uuid from 'uuid'; import * as uuid from 'uuid';
import initStore from './store'; import initStore from './store';
import { apiUrl, swPublickey, version, lang, googleMapsApiKey } from './config'; import { apiUrl, version, lang } from './config';
import Progress from './common/scripts/loading'; import Progress from './common/scripts/loading';
import Connection from './common/scripts/streaming/stream'; import Connection from './common/scripts/streaming/stream';
import { HomeStreamManager } from './common/scripts/streaming/home'; import { HomeStreamManager } from './common/scripts/streaming/home';
@ -230,13 +230,13 @@ export default class MiOS extends EventEmitter {
//#region Init stream managers //#region Init stream managers
this.streams.serverStatsStream = new ServerStatsStreamManager(this); this.streams.serverStatsStream = new ServerStatsStreamManager(this);
this.streams.notesStatsStream = new NotesStatsStreamManager(this); this.streams.notesStatsStream = new NotesStatsStreamManager(this);
this.streams.localTimelineStream = new LocalTimelineStreamManager(this, this.store.state.i);
this.once('signedin', () => { this.once('signedin', () => {
// Init home stream manager // Init home stream manager
this.stream = new HomeStreamManager(this, this.store.state.i); this.stream = new HomeStreamManager(this, this.store.state.i);
// Init other stream manager // Init other stream manager
this.streams.localTimelineStream = new LocalTimelineStreamManager(this, this.store.state.i);
this.streams.hybridTimelineStream = new HybridTimelineStreamManager(this, this.store.state.i); this.streams.hybridTimelineStream = new HybridTimelineStreamManager(this, this.store.state.i);
this.streams.globalTimelineStream = new GlobalTimelineStreamManager(this, this.store.state.i); this.streams.globalTimelineStream = new GlobalTimelineStreamManager(this, this.store.state.i);
this.streams.driveStream = new DriveStreamManager(this, this.store.state.i); this.streams.driveStream = new DriveStreamManager(this, this.store.state.i);
@ -361,7 +361,7 @@ export default class MiOS extends EventEmitter {
// A public key your push server will use to send // A public key your push server will use to send
// messages to client apps via a push server. // messages to client apps via a push server.
applicationServerKey: urlBase64ToUint8Array(swPublickey) applicationServerKey: urlBase64ToUint8Array(this.meta.data.swPublickey)
}; };
// Subscribe push notification // Subscribe push notification