From d0fe2ffa57e4877438e909e2e9a49533906371d5 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Mon, 14 May 2018 21:37:34 +0900
Subject: [PATCH] refs #299 Start local streaming when initialize timeline
space
---
src/renderer/components/TimelineSpace.vue | 11 ++++++
.../TimelineSpace/Contents/Local.vue | 36 +------------------
src/renderer/store/TimelineSpace.js | 20 +++++++++++
.../store/TimelineSpace/Contents/Local.js | 26 ++------------
4 files changed, 35 insertions(+), 58 deletions(-)
diff --git a/src/renderer/components/TimelineSpace.vue b/src/renderer/components/TimelineSpace.vue
index c6d549b6..40f7ad7a 100644
--- a/src/renderer/components/TimelineSpace.vue
+++ b/src/renderer/components/TimelineSpace.vue
@@ -39,11 +39,13 @@ export default {
},
beforeDestroy () {
this.$store.dispatch('TimelineSpace/stopUserStreaming')
+ this.$store.dispatch('TimelineSpace/stopLocalStreaming')
},
methods: {
async clear () {
await this.$store.dispatch('TimelineSpace/clearAccount')
await this.$store.commit('TimelineSpace/Contents/Home/clearTimeline')
+ await this.$store.commit('TimelineSpace/Contents/Local/clearTimeline')
await this.$store.commit('TimelineSpace/Contents/Notifications/clearNotifications')
await this.$store.dispatch('TimelineSpace/removeShortcutEvents')
return 'clear'
@@ -74,6 +76,14 @@ export default {
type: 'error'
})
}
+ try {
+ await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
+ } catch (err) {
+ this.$message({
+ message: 'Could not fetch local timeline',
+ type: 'error'
+ })
+ }
this.$store.dispatch('TimelineSpace/SideMenu/fetchLists', account)
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
.catch(() => {
@@ -82,6 +92,7 @@ export default {
type: 'error'
})
})
+ this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
}
}
}
diff --git a/src/renderer/components/TimelineSpace/Contents/Local.vue b/src/renderer/components/TimelineSpace/Contents/Local.vue
index b06bcefd..a16945b2 100644
--- a/src/renderer/components/TimelineSpace/Contents/Local.vue
+++ b/src/renderer/components/TimelineSpace/Contents/Local.vue
@@ -27,53 +27,19 @@ export default {
unread: state => state.TimelineSpace.Contents.Local.unreadTimeline
})
},
- created () {
- 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()
- })
+ mounted () {
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
},
- beforeDestroy () {
- this.$store.dispatch('TimelineSpace/Contents/Local/stopLocalStreaming')
- },
destroyed () {
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/Local/mergeTimeline')
this.$store.commit('TimelineSpace/Contents/Local/archiveTimeline')
- this.$store.commit('TimelineSpace/Contents/Local/clearTimeline')
if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) {
document.getElementById('scrollable').removeEventListener('scroll', this.onScroll)
document.getElementById('scrollable').scrollTop = 0
}
},
methods: {
- async initialize () {
- try {
- await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline')
- } catch (err) {
- this.$message({
- message: 'Could not fetch timeline',
- type: 'error'
- })
- }
- this.$store.dispatch('TimelineSpace/Contents/Local/startLocalStreaming')
- .catch(() => {
- this.$message({
- message: 'Failed to start streaming',
- type: 'error'
- })
- })
- },
updateToot (message) {
this.$store.commit('TimelineSpace/Contents/Local/updateToot', message)
},
diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js
index 0526152e..f72641a3 100644
--- a/src/renderer/store/TimelineSpace.js
+++ b/src/renderer/store/TimelineSpace.js
@@ -93,6 +93,20 @@ const TimelineSpace = {
})
})
},
+ startLocalStreaming ({ state, commit, rootState }, account) {
+ ipcRenderer.on('update-start-local-streaming', (event, update) => {
+ commit('TimelineSpace/Contents/Local/appendTimeline', update, { root: true })
+ if (rootState.TimelineSpace.Contents.Local.heading && Math.random() > 0.8) {
+ commit('TimelineSpace/Contents/Local/archiveTimeline', {}, { root: true })
+ }
+ })
+ return new Promise((resolve, reject) => {
+ ipcRenderer.send('start-local-streaming', account)
+ ipcRenderer.once('error-start-local-streaming', (event, err) => {
+ reject(err)
+ })
+ })
+ },
async stopUserStreaming ({ commit }) {
ipcRenderer.removeAllListeners('update-start-user-streaming')
ipcRenderer.removeAllListeners('notification-start-user-streaming')
@@ -100,6 +114,12 @@ const TimelineSpace = {
ipcRenderer.send('stop-user-streaming')
return 'stopUserStreaming'
},
+ async stopLocalStreaming ({ commit }) {
+ ipcRenderer.removeAllListeners('error-start-local-streaming')
+ ipcRenderer.removeAllListeners('update-start-local-streaming')
+ ipcRenderer.send('stop-local-streaming')
+ return 'stopLocalStreaming'
+ },
watchShortcutEvents ({ commit }) {
ipcRenderer.on('CmdOrCtrl+N', () => {
commit('TimelineSpace/Modals/NewToot/changeModal', true, { root: true })
diff --git a/src/renderer/store/TimelineSpace/Contents/Local.js b/src/renderer/store/TimelineSpace/Contents/Local.js
index 84e7c94b..e7cf7267 100644
--- a/src/renderer/store/TimelineSpace/Contents/Local.js
+++ b/src/renderer/store/TimelineSpace/Contents/Local.js
@@ -1,4 +1,3 @@
-import { ipcRenderer } from 'electron'
import Mastodon from 'mastodon-api'
const Local = {
@@ -67,12 +66,12 @@ const Local = {
}
},
actions: {
- fetchLocalTimeline ({ state, commit, rootState }) {
+ fetchLocalTimeline ({ commit }, account) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
- access_token: rootState.TimelineSpace.account.accessToken,
- api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
+ access_token: account.accessToken,
+ api_url: account.baseURL + '/api/v1'
}
)
client.get('/timelines/public', { limit: 40, local: true }, (err, data, res) => {
@@ -82,25 +81,6 @@ const Local = {
})
})
},
- startLocalStreaming ({ state, commit, rootState }) {
- ipcRenderer.on('update-start-local-streaming', (event, update) => {
- commit('appendTimeline', update)
- if (state.heading && Math.random() > 0.8) {
- commit('archiveTimeline')
- }
- })
- return new Promise((resolve, reject) => {
- ipcRenderer.send('start-local-streaming', rootState.TimelineSpace.account)
- ipcRenderer.once('error-start-local-streaming', (event, err) => {
- reject(err)
- })
- })
- },
- stopLocalStreaming ({ commit }) {
- ipcRenderer.removeAllListeners('error-start-local-streaming')
- ipcRenderer.removeAllListeners('update-start-local-streaming')
- ipcRenderer.send('stop-local-streaming')
- },
lazyFetchTimeline ({ state, commit, rootState }, last) {
if (last === undefined || last === null) {
return null