1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-01-26 15:34:56 +01:00

refs #105 Get recent timeline in local

This commit is contained in:
AkiraFukushima 2018-03-24 01:48:05 +09:00
parent 9c7225d493
commit c70251e9a9
2 changed files with 43 additions and 1 deletions

View File

@ -20,12 +20,35 @@ export default {
})
},
created () {
this.$store.dispatch('TimelineSpace/Local/startLocalStreaming', this.account)
const loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
this.initialize()
.then(() => {
loading.close()
})
.catch(() => {
loading.close()
})
},
beforeDestroy () {
this.$store.dispatch('TimelineSpace/Local/stopLocalStreaming')
},
methods: {
async initialize () {
try {
await this.$store.dispatch('TimelineSpace/Local/fetchLocalTimeline', this.account)
} catch (err) {
this.$message({
message: 'Could not fetch timeline',
type: 'error'
})
}
this.$store.dispatch('TimelineSpace/Local/startLocalStreaming', this.account)
},
updateToot (message) {
this.$store.commit('TimelineSpace/Local/updateToot', message)
}

View File

@ -1,4 +1,5 @@
import { ipcRenderer } from 'electron'
import Mastodon from 'mastodon-api'
const Local = {
namespaced: true,
@ -9,6 +10,9 @@ const Local = {
appendTimeline (state, update) {
state.timeline = [update].concat(state.timeline)
},
updateTimeline (state, messages) {
state.timeline = messages
},
updateToot (state, message) {
state.timeline = state.timeline.map((toot) => {
if (toot.id === message.id) {
@ -27,6 +31,21 @@ const Local = {
}
},
actions: {
fetchLocalTimeline ({ commit }, account) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: account.accessToken,
api_url: account.baseURL + '/api/v1'
}
)
client.get('/timelines/public', { limit: 40, local: true }, (err, data, res) => {
if (err) return reject(err)
commit('updateTimeline', data)
resolve(res)
})
})
},
startLocalStreaming ({ commit }, account) {
ipcRenderer.on('update-start-local-streaming', (event, update) => {
commit('appendTimeline', update)