1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-23 15:37:59 +01:00

refs #6 Get recent home timeline when timelie space is created

This commit is contained in:
AkiraFukushima 2018-03-12 17:17:41 +09:00
parent 9b0728b724
commit e1ede624f9
3 changed files with 25 additions and 6 deletions

View File

@ -16,6 +16,7 @@ export default {
created () {
this.$store.dispatch('TimelineSpace/fetchAccount', this.$route.params.id)
.then((account) => {
this.$store.dispatch('TimelineSpace/fetchHomeTimeline', account)
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/username', account)
})

View File

@ -1,6 +1,6 @@
<template>
<div id="home">
<div class="home-timeline" v-for="(message, index) in timeline" v-bind:key="index">
<div class="home-timeline" v-for="message in timeline" v-bind:key="message.id">
<toot :message="message"></toot>
</div>
</div>
@ -17,9 +17,6 @@ export default {
...mapState({
timeline: state => state.TimelineSpace.homeTimeline
})
},
created () {
// TODO: Get recent timeline and concat timeline before stream
}
}
</script>

View File

@ -24,10 +24,13 @@ const TimelineSpace = {
state.username = username
},
appendHomeTimeline (state, update) {
state.homeTimeline = state.homeTimeline.concat([update])
state.homeTimeline = [update].concat(state.homeTimeline)
},
appendNotification (state, notification) {
state.notification = state.notification.concat([notification])
state.notification = [notification].concat(state.notification)
},
insertHomeTimeline (state, messages) {
state.homeTimeline = state.homeTimeline.concat(messages)
}
},
actions: {
@ -75,6 +78,24 @@ const TimelineSpace = {
},
stopUserStreaming ({ commit }) {
ipcRenderer.send('stop-user-streaming')
},
fetchHomeTimeline ({ commit }, account) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: account.accessToken,
api_url: account.baseURL + '/api/v1'
}
)
client.get('/timelines/home', { limit: 40 })
.then((res) => {
commit('insertHomeTimeline', res.data)
resolve()
})
.catch((err) => {
reject(err)
})
})
}
}
}