mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-02-05 03:38:55 +01:00
refs #105 Get recent timeline in local
This commit is contained in:
parent
9c7225d493
commit
c70251e9a9
@ -20,12 +20,35 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
created () {
|
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 () {
|
beforeDestroy () {
|
||||||
this.$store.dispatch('TimelineSpace/Local/stopLocalStreaming')
|
this.$store.dispatch('TimelineSpace/Local/stopLocalStreaming')
|
||||||
},
|
},
|
||||||
methods: {
|
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) {
|
updateToot (message) {
|
||||||
this.$store.commit('TimelineSpace/Local/updateToot', message)
|
this.$store.commit('TimelineSpace/Local/updateToot', message)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { ipcRenderer } from 'electron'
|
import { ipcRenderer } from 'electron'
|
||||||
|
import Mastodon from 'mastodon-api'
|
||||||
|
|
||||||
const Local = {
|
const Local = {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
@ -9,6 +10,9 @@ const Local = {
|
|||||||
appendTimeline (state, update) {
|
appendTimeline (state, update) {
|
||||||
state.timeline = [update].concat(state.timeline)
|
state.timeline = [update].concat(state.timeline)
|
||||||
},
|
},
|
||||||
|
updateTimeline (state, messages) {
|
||||||
|
state.timeline = messages
|
||||||
|
},
|
||||||
updateToot (state, message) {
|
updateToot (state, message) {
|
||||||
state.timeline = state.timeline.map((toot) => {
|
state.timeline = state.timeline.map((toot) => {
|
||||||
if (toot.id === message.id) {
|
if (toot.id === message.id) {
|
||||||
@ -27,6 +31,21 @@ const Local = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
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) {
|
startLocalStreaming ({ commit }, account) {
|
||||||
ipcRenderer.on('update-start-local-streaming', (event, update) => {
|
ipcRenderer.on('update-start-local-streaming', (event, update) => {
|
||||||
commit('appendTimeline', update)
|
commit('appendTimeline', update)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user