refs #769 Switch user streaming method
This commit is contained in:
parent
8c1cdd4ddb
commit
c210bea4d9
|
@ -390,20 +390,21 @@ ipcMain.on('reset-badge', () => {
|
||||||
// streaming
|
// streaming
|
||||||
let userStreaming = null
|
let userStreaming = null
|
||||||
|
|
||||||
ipcMain.on('start-user-streaming', (event, ac) => {
|
ipcMain.on('start-user-streaming', (event, obj) => {
|
||||||
accountManager.getAccount(ac._id)
|
const { account, useWebsocket } = obj
|
||||||
|
accountManager.getAccount(account._id)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
log.error(err)
|
log.error(err)
|
||||||
event.sender.send('error-start-user-streaming', err)
|
event.sender.send('error-start-user-streaming', err)
|
||||||
})
|
})
|
||||||
.then((account) => {
|
.then((acct) => {
|
||||||
// Stop old user streaming
|
// Stop old user streaming
|
||||||
if (userStreaming !== null) {
|
if (userStreaming !== null) {
|
||||||
userStreaming.stop()
|
userStreaming.stop()
|
||||||
userStreaming = null
|
userStreaming = null
|
||||||
}
|
}
|
||||||
|
|
||||||
userStreaming = new StreamingManager(account)
|
userStreaming = new StreamingManager(acct, useWebsocket)
|
||||||
userStreaming.startUser(
|
userStreaming.startUser(
|
||||||
(update) => {
|
(update) => {
|
||||||
event.sender.send('update-start-user-streaming', update)
|
event.sender.send('update-start-user-streaming', update)
|
||||||
|
|
|
@ -4,11 +4,11 @@ import WebSocket from './websocket'
|
||||||
import log from 'electron-log'
|
import log from 'electron-log'
|
||||||
|
|
||||||
export default class StreamingManager {
|
export default class StreamingManager {
|
||||||
constructor (account) {
|
constructor (account, useWebsocket = false) {
|
||||||
this.account = account
|
this.account = account
|
||||||
this.streaming = new Streaming(account)
|
this.streaming = new Streaming(account)
|
||||||
this.websocket = new WebSocket(account)
|
this.websocket = new WebSocket(account)
|
||||||
this.mastodon = true
|
this.useWebsocket = useWebsocket
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,18 +17,19 @@ export default class StreamingManager {
|
||||||
async detectPleroma () {
|
async detectPleroma () {
|
||||||
const data = await Mastodon.get('/instance', {}, this.account.baseURL + '/api/v1')
|
const data = await Mastodon.get('/instance', {}, this.account.baseURL + '/api/v1')
|
||||||
if (data.version.includes('Pleroma')) {
|
if (data.version.includes('Pleroma')) {
|
||||||
this.mastodon = false
|
|
||||||
log.info('detect Pleroma')
|
log.info('detect Pleroma')
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
startUser (updateCallback, notificationCallback, errCallback) {
|
startUser (updateCallback, notificationCallback, errCallback) {
|
||||||
this.detectPleroma()
|
this.detectPleroma()
|
||||||
.then(() => {
|
.then((isPleroma) => {
|
||||||
if (this.mastodon) {
|
if (isPleroma || this.useWebsocket) {
|
||||||
this._startUserStreaming(updateCallback, notificationCallback, errCallback)
|
|
||||||
} else {
|
|
||||||
this._startUserSocket(updateCallback, notificationCallback, errCallback)
|
this._startUserSocket(updateCallback, notificationCallback, errCallback)
|
||||||
|
} else {
|
||||||
|
this._startUserStreaming(updateCallback, notificationCallback, errCallback)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => errCallback(err))
|
.catch(err => errCallback(err))
|
||||||
|
@ -36,11 +37,11 @@ export default class StreamingManager {
|
||||||
|
|
||||||
start (path, params, updateCallback, errCallback) {
|
start (path, params, updateCallback, errCallback) {
|
||||||
this.detectPleroma()
|
this.detectPleroma()
|
||||||
.then(() => {
|
.then((isPleroma) => {
|
||||||
if (this.mastodon) {
|
if (isPleroma || this.useWebsocket) {
|
||||||
this._startStreaming(path, params, updateCallback, errCallback)
|
|
||||||
} else {
|
|
||||||
this._startSocket(path, params, updateCallback, errCallback)
|
this._startSocket(path, params, updateCallback, errCallback)
|
||||||
|
} else {
|
||||||
|
this._startStreaming(path, params, updateCallback, errCallback)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => errCallback(err))
|
.catch(err => errCallback(err))
|
||||||
|
|
|
@ -66,13 +66,15 @@ export default {
|
||||||
filter: '',
|
filter: '',
|
||||||
filterVisible: false,
|
filterVisible: false,
|
||||||
showReblogs: true,
|
showReblogs: true,
|
||||||
showReplies: true,
|
showReplies: true
|
||||||
useWebsocket: false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState('TimelineSpace/HeaderMenu', {
|
||||||
title: state => state.TimelineSpace.HeaderMenu.title
|
title: state => state.title
|
||||||
|
}),
|
||||||
|
...mapState('TimelineSpace', {
|
||||||
|
useWebsocket: state => state.useWebsocket
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
|
@ -134,7 +136,9 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
switchStreaming () {
|
switchStreaming () {
|
||||||
this.useWebsocket = !this.useWebsocket
|
this.$store.dispatch('TimelineSpace/stopStreamings')
|
||||||
|
this.$store.commit('TimelineSpace/changeUseWebsocket', !this.useWebsocket)
|
||||||
|
this.$store.dispatch('TimelineSpace/startStreamings')
|
||||||
},
|
},
|
||||||
openNewTootModal () {
|
openNewTootModal () {
|
||||||
this.$store.dispatch('TimelineSpace/Modals/NewToot/openModal')
|
this.$store.dispatch('TimelineSpace/Modals/NewToot/openModal')
|
||||||
|
|
|
@ -29,7 +29,8 @@ const TimelineSpace = {
|
||||||
direct: unreadSettings.Direct.default,
|
direct: unreadSettings.Direct.default,
|
||||||
local: unreadSettings.Local.default,
|
local: unreadSettings.Local.default,
|
||||||
public: unreadSettings.Public.default
|
public: unreadSettings.Public.default
|
||||||
}
|
},
|
||||||
|
useWebsocket: false
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
updateAccount (state, account) {
|
updateAccount (state, account) {
|
||||||
|
@ -55,6 +56,9 @@ const TimelineSpace = {
|
||||||
},
|
},
|
||||||
updateUnreadNotification (state, settings) {
|
updateUnreadNotification (state, settings) {
|
||||||
state.unreadNotification = settings
|
state.unreadNotification = settings
|
||||||
|
},
|
||||||
|
changeUseWebsocket (state, use) {
|
||||||
|
state.useWebsocket = use
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -200,8 +204,8 @@ const TimelineSpace = {
|
||||||
dispatch('bindPublicStreaming')
|
dispatch('bindPublicStreaming')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
startStreamings ({ dispatch, state }, account) {
|
startStreamings ({ dispatch, state }) {
|
||||||
dispatch('startUserStreaming', account)
|
dispatch('startUserStreaming')
|
||||||
if (state.unreadNotification.direct) {
|
if (state.unreadNotification.direct) {
|
||||||
dispatch('startDirectMessagesStreaming')
|
dispatch('startDirectMessagesStreaming')
|
||||||
}
|
}
|
||||||
|
@ -250,9 +254,12 @@ const TimelineSpace = {
|
||||||
commit('TimelineSpace/SideMenu/changeUnreadNotifications', true, { root: true })
|
commit('TimelineSpace/SideMenu/changeUnreadNotifications', true, { root: true })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
startUserStreaming (_, account) {
|
startUserStreaming ({ state }) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ipcRenderer.send('start-user-streaming', account)
|
ipcRenderer.send('start-user-streaming', {
|
||||||
|
account: state.account,
|
||||||
|
useWebsocket: state.useWebsocket
|
||||||
|
})
|
||||||
ipcRenderer.once('error-start-user-streaming', (event, err) => {
|
ipcRenderer.once('error-start-user-streaming', (event, err) => {
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue