1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-02-07 15:28:42 +01:00

refs #167 Streaming update in list timeline

This commit is contained in:
AkiraFukushima 2018-04-09 23:43:36 +09:00
parent abcef61a71
commit 32b8ab9190
3 changed files with 89 additions and 13 deletions

View File

@ -452,6 +452,36 @@ ipcMain.on('stop-public-streaming', (event, _) => {
publicStreaming = null publicStreaming = null
}) })
let listStreaming = null
ipcMain.on('start-list-streaming', (event, obj) => {
const account = new Account(accountDB)
account.getAccount(obj.account._id)
.catch((err) => {
log.error(err)
event.sender.send('error-start-list-streaming', err)
})
.then((account) => {
// Stop old list streaming
if (listStreaming !== null) {
listStreaming.stop()
listStreaming = null
}
listStreaming = new Streaming(account)
listStreaming.start(
`/streaming/list?list=${obj.list_id}`,
(update) => {
event.sender.send('update-start-list-streaming', update)
},
(err) => {
log.error(err)
event.sendeer.send('error-start-list-streaming', err)
}
)
})
})
// sounds // sounds
ipcMain.on('fav-rt-action-sound', (event, _) => { ipcMain.on('fav-rt-action-sound', (event, _) => {
const preferences = new Preferences(preferencesDBPath) const preferences = new Preferences(preferencesDBPath)

View File

@ -22,44 +22,64 @@ export default {
}) })
}, },
created () { created () {
const loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
this.load() this.load()
.then(() => {
loading.close()
})
document.getElementById('scrollable').addEventListener('scroll', this.onScroll) document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
}, },
watch: { watch: {
list_id: function () { list_id: function () {
const loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
this.load() this.load()
.then(() => {
loading.close()
})
} }
}, },
beforeDestroy () {
this.$store.dispatch('TimelineSpace/Contents/Lists/stopStreaming')
},
destroyed () { destroyed () {
if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) { if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) {
document.getElementById('scrollable').removeEventListener('scroll', this.onScroll) document.getElementById('scrollable').removeEventListener('scroll', this.onScroll)
} }
}, },
methods: { methods: {
load () { async load () {
const loading = this.$loading({ await this.$store.dispatch('TimelineSpace/Contents/Lists/stopStreaming')
lock: true, try {
text: 'Loading', await this.$store.dispatch('TimelineSpace/Contents/Lists/fetchTimeline', this.list_id)
spinner: 'el-icon-loading', } catch (err) {
background: 'rgba(0, 0, 0, 0.7)' this.$message({
}) message: 'Failed to get timeline',
this.$store.dispatch('TimelineSpace/Contents/Lists/fetchTimeline', this.list_id) type: 'error'
.then(() => {
loading.close()
}) })
}
this.$store.dispatch('TimelineSpace/Contents/Lists/startStreaming', this.list_id)
.catch(() => { .catch(() => {
loading.close()
this.$message({ this.$message({
message: 'Failed to get timeline', message: 'Failed to start streaming',
type: 'error' type: 'error'
}) })
}) })
return 'started'
}, },
updateToot (message) { updateToot (message) {
this.$store.commit('TimelineSpace/Contents/Lists/updateToot', message) this.$store.commit('TimelineSpace/Contents/Lists/updateToot', message)
}, },
onScroll (event) { onScroll (event) {
console.log(document.getElementsByName('lists'))
if (((event.target.clientHeight + event.target.scrollTop) >= document.getElementsByName('lists')[0].clientHeight - 10) && !this.lazyloading) { if (((event.target.clientHeight + event.target.scrollTop) >= document.getElementsByName('lists')[0].clientHeight - 10) && !this.lazyloading) {
this.$store.dispatch('TimelineSpace/Contents/Lists/lazyFetchTimeline', { this.$store.dispatch('TimelineSpace/Contents/Lists/lazyFetchTimeline', {
list_id: this.list_id, list_id: this.list_id,

View File

@ -1,3 +1,4 @@
import { ipcRenderer } from 'electron'
import Mastodon from 'mastodon-api' import Mastodon from 'mastodon-api'
const Lists = { const Lists = {
@ -7,6 +8,9 @@ const Lists = {
lazyLoading: false lazyLoading: false
}, },
mutations: { mutations: {
appendTimeline (state, update) {
state.timeline = [update].concat(state.timeline)
},
updateTimeline (state, timeline) { updateTimeline (state, timeline) {
state.timeline = timeline state.timeline = timeline
}, },
@ -48,6 +52,28 @@ const Lists = {
}) })
}) })
}, },
startStreaming ({ state, commit, rootState }, listID) {
ipcRenderer.on('update-start-list-streaming', (event, update) => {
commit('appendTimeline', update)
})
return new Promise((resolve, reject) => {
ipcRenderer.send('start-list-streaming', {
list_id: listID,
account: rootState.TimelineSpace.account
})
ipcRenderer.once('error-start-list-streaming', (event, err) => {
reject(err)
})
})
},
stopStreaming ({ commit }) {
return new Promise((resolve, reject) => {
ipcRenderer.removeAllListeners('error-start-list-streaming')
ipcRenderer.removeAllListeners('update-start-list-streaming')
ipcRenderer.send('stop-list-streaming')
resolve()
})
},
lazyFetchTimeline ({ state, commit, rootState }, obj) { lazyFetchTimeline ({ state, commit, rootState }, obj) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (state.lazyLoading) { if (state.lazyLoading) {