refs #299 Start local streaming when initialize timeline space
This commit is contained in:
parent
c9f8d85926
commit
d0fe2ffa57
|
@ -39,11 +39,13 @@ export default {
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
this.$store.dispatch('TimelineSpace/stopUserStreaming')
|
this.$store.dispatch('TimelineSpace/stopUserStreaming')
|
||||||
|
this.$store.dispatch('TimelineSpace/stopLocalStreaming')
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async clear () {
|
async clear () {
|
||||||
await this.$store.dispatch('TimelineSpace/clearAccount')
|
await this.$store.dispatch('TimelineSpace/clearAccount')
|
||||||
await this.$store.commit('TimelineSpace/Contents/Home/clearTimeline')
|
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.commit('TimelineSpace/Contents/Notifications/clearNotifications')
|
||||||
await this.$store.dispatch('TimelineSpace/removeShortcutEvents')
|
await this.$store.dispatch('TimelineSpace/removeShortcutEvents')
|
||||||
return 'clear'
|
return 'clear'
|
||||||
|
@ -74,6 +76,14 @@ export default {
|
||||||
type: 'error'
|
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/SideMenu/fetchLists', account)
|
||||||
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
|
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
@ -82,6 +92,7 @@ export default {
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,53 +27,19 @@ export default {
|
||||||
unread: state => state.TimelineSpace.Contents.Local.unreadTimeline
|
unread: state => state.TimelineSpace.Contents.Local.unreadTimeline
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
created () {
|
mounted () {
|
||||||
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()
|
|
||||||
})
|
|
||||||
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
|
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
|
||||||
this.$store.dispatch('TimelineSpace/Contents/Local/stopLocalStreaming')
|
|
||||||
},
|
|
||||||
destroyed () {
|
destroyed () {
|
||||||
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true)
|
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true)
|
||||||
this.$store.commit('TimelineSpace/Contents/Local/mergeTimeline')
|
this.$store.commit('TimelineSpace/Contents/Local/mergeTimeline')
|
||||||
this.$store.commit('TimelineSpace/Contents/Local/archiveTimeline')
|
this.$store.commit('TimelineSpace/Contents/Local/archiveTimeline')
|
||||||
this.$store.commit('TimelineSpace/Contents/Local/clearTimeline')
|
|
||||||
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)
|
||||||
document.getElementById('scrollable').scrollTop = 0
|
document.getElementById('scrollable').scrollTop = 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
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) {
|
updateToot (message) {
|
||||||
this.$store.commit('TimelineSpace/Contents/Local/updateToot', message)
|
this.$store.commit('TimelineSpace/Contents/Local/updateToot', message)
|
||||||
},
|
},
|
||||||
|
|
|
@ -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 }) {
|
async stopUserStreaming ({ commit }) {
|
||||||
ipcRenderer.removeAllListeners('update-start-user-streaming')
|
ipcRenderer.removeAllListeners('update-start-user-streaming')
|
||||||
ipcRenderer.removeAllListeners('notification-start-user-streaming')
|
ipcRenderer.removeAllListeners('notification-start-user-streaming')
|
||||||
|
@ -100,6 +114,12 @@ const TimelineSpace = {
|
||||||
ipcRenderer.send('stop-user-streaming')
|
ipcRenderer.send('stop-user-streaming')
|
||||||
return 'stopUserStreaming'
|
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 }) {
|
watchShortcutEvents ({ commit }) {
|
||||||
ipcRenderer.on('CmdOrCtrl+N', () => {
|
ipcRenderer.on('CmdOrCtrl+N', () => {
|
||||||
commit('TimelineSpace/Modals/NewToot/changeModal', true, { root: true })
|
commit('TimelineSpace/Modals/NewToot/changeModal', true, { root: true })
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { ipcRenderer } from 'electron'
|
|
||||||
import Mastodon from 'mastodon-api'
|
import Mastodon from 'mastodon-api'
|
||||||
|
|
||||||
const Local = {
|
const Local = {
|
||||||
|
@ -67,12 +66,12 @@ const Local = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
fetchLocalTimeline ({ state, commit, rootState }) {
|
fetchLocalTimeline ({ commit }, account) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const client = new Mastodon(
|
const client = new Mastodon(
|
||||||
{
|
{
|
||||||
access_token: rootState.TimelineSpace.account.accessToken,
|
access_token: account.accessToken,
|
||||||
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
|
api_url: account.baseURL + '/api/v1'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
client.get('/timelines/public', { limit: 40, local: true }, (err, data, res) => {
|
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) {
|
lazyFetchTimeline ({ state, commit, rootState }, last) {
|
||||||
if (last === undefined || last === null) {
|
if (last === undefined || last === null) {
|
||||||
return null
|
return null
|
||||||
|
|
Loading…
Reference in New Issue