Merge pull request #805 from h3poteto/iss-804
refs #804 Hide switch streaming button when user are using Pleroma
This commit is contained in:
commit
ee84c12e26
|
@ -1,7 +1,5 @@
|
||||||
import Mastodon from 'megalodon'
|
|
||||||
import Streaming from './streaming'
|
import Streaming from './streaming'
|
||||||
import WebSocket from './websocket'
|
import WebSocket from './websocket'
|
||||||
import log from 'electron-log'
|
|
||||||
|
|
||||||
export default class StreamingManager {
|
export default class StreamingManager {
|
||||||
constructor (account, useWebsocket = false) {
|
constructor (account, useWebsocket = false) {
|
||||||
|
@ -11,40 +9,20 @@ export default class StreamingManager {
|
||||||
this.useWebsocket = useWebsocket
|
this.useWebsocket = useWebsocket
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Find Pleroma comment in the response
|
|
||||||
*/
|
|
||||||
async detectPleroma () {
|
|
||||||
const data = await Mastodon.get('/instance', {}, this.account.baseURL + '/api/v1')
|
|
||||||
if (data.version.includes('Pleroma')) {
|
|
||||||
log.info('detect Pleroma')
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
startUser (updateCallback, notificationCallback, errCallback) {
|
startUser (updateCallback, notificationCallback, errCallback) {
|
||||||
this.detectPleroma()
|
if (this.useWebsocket) {
|
||||||
.then((isPleroma) => {
|
this._startUserSocket(updateCallback, notificationCallback, errCallback)
|
||||||
if (isPleroma || this.useWebsocket) {
|
} else {
|
||||||
this._startUserSocket(updateCallback, notificationCallback, errCallback)
|
this._startUserStreaming(updateCallback, notificationCallback, errCallback)
|
||||||
} else {
|
}
|
||||||
this._startUserStreaming(updateCallback, notificationCallback, errCallback)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => errCallback(err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start (path, params, updateCallback, errCallback) {
|
start (path, params, updateCallback, errCallback) {
|
||||||
this.detectPleroma()
|
if (this.useWebsocket) {
|
||||||
.then((isPleroma) => {
|
this._startSocket(path, params, updateCallback, errCallback)
|
||||||
if (isPleroma || this.useWebsocket) {
|
} else {
|
||||||
this._startSocket(path, params, updateCallback, errCallback)
|
this._startStreaming(path, params, updateCallback, errCallback)
|
||||||
} else {
|
}
|
||||||
this._startStreaming(path, params, updateCallback, errCallback)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => errCallback(err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stop () {
|
stop () {
|
||||||
|
|
|
@ -106,6 +106,7 @@ export default {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await this.$store.dispatch('TimelineSpace/detectPleroma')
|
||||||
// Bind streamings
|
// Bind streamings
|
||||||
await this.$store.dispatch('TimelineSpace/bindStreamings', account)
|
await this.$store.dispatch('TimelineSpace/bindStreamings', account)
|
||||||
// Start streamings
|
// Start streamings
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="tools">
|
<div class="tools">
|
||||||
<el-button type="text" class="action" @click="switchStreaming" :title="$t('header_menu.switch_streaming')">
|
<el-button v-if="!pleroma" type="text" class="action" @click="switchStreaming" :title="$t('header_menu.switch_streaming')">
|
||||||
<svg :class="useWebsocket ? 'websocket' : 'not-websocket'" width="25" height="18" viewBox="0 0 256 193" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid"><path d="M192.44 144.645h31.78V68.339l-35.805-35.804-22.472 22.472 26.497 26.497v63.14zm31.864 15.931H113.452L86.954 134.08l11.237-11.236 21.885 21.885h45.028l-44.357-44.441 11.32-11.32 44.357 44.358V88.296l-21.801-21.801 11.152-11.153L110.685 0H0l31.696 31.696v.084H97.436l23.227 23.227-33.96 33.96L63.476 65.74V47.712h-31.78v31.193l55.007 55.007L64.314 156.3l35.805 35.805H256l-31.696-31.529z" /></svg>
|
<svg :class="useWebsocket ? 'websocket' : 'not-websocket'" width="25" height="18" viewBox="0 0 256 193" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid"><path d="M192.44 144.645h31.78V68.339l-35.805-35.804-22.472 22.472 26.497 26.497v63.14zm31.864 15.931H113.452L86.954 134.08l11.237-11.236 21.885 21.885h45.028l-44.357-44.441 11.32-11.32 44.357 44.358V88.296l-21.801-21.801 11.152-11.153L110.685 0H0l31.696 31.696v.084H97.436l23.227 23.227-33.96 33.96L63.476 65.74V47.712h-31.78v31.193l55.007 55.007L64.314 156.3l35.805 35.805H256l-31.696-31.529z" /></svg>
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button type="text" class="action" @click="openNewTootModal" :title="$t('header_menu.new_toot')">
|
<el-button type="text" class="action" @click="openNewTootModal" :title="$t('header_menu.new_toot')">
|
||||||
|
@ -74,7 +74,8 @@ export default {
|
||||||
title: state => state.title
|
title: state => state.title
|
||||||
}),
|
}),
|
||||||
...mapState('TimelineSpace', {
|
...mapState('TimelineSpace', {
|
||||||
useWebsocket: state => state.useWebsocket
|
useWebsocket: state => state.useWebsocket,
|
||||||
|
pleroma: state => state.pleroma
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
|
|
|
@ -30,7 +30,8 @@ const TimelineSpace = {
|
||||||
local: unreadSettings.Local.default,
|
local: unreadSettings.Local.default,
|
||||||
public: unreadSettings.Public.default
|
public: unreadSettings.Public.default
|
||||||
},
|
},
|
||||||
useWebsocket: false
|
useWebsocket: false,
|
||||||
|
pleroma: false
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
updateAccount (state, account) {
|
updateAccount (state, account) {
|
||||||
|
@ -57,6 +58,9 @@ const TimelineSpace = {
|
||||||
updateUnreadNotification (state, settings) {
|
updateUnreadNotification (state, settings) {
|
||||||
state.unreadNotification = settings
|
state.unreadNotification = settings
|
||||||
},
|
},
|
||||||
|
changePleroma (state, pleroma) {
|
||||||
|
state.pleroma = pleroma
|
||||||
|
},
|
||||||
changeUseWebsocket (state, use) {
|
changeUseWebsocket (state, use) {
|
||||||
state.useWebsocket = use
|
state.useWebsocket = use
|
||||||
}
|
}
|
||||||
|
@ -115,6 +119,16 @@ const TimelineSpace = {
|
||||||
)
|
)
|
||||||
return 'clearAccount'
|
return 'clearAccount'
|
||||||
},
|
},
|
||||||
|
async detectPleroma ({ commit, state }) {
|
||||||
|
const data = await Mastodon.get('/instance', {}, state.account.baseURL + '/api/v1')
|
||||||
|
if (data.version.includes('Pleroma')) {
|
||||||
|
commit('changePleroma', true)
|
||||||
|
commit('changeUseWebsocket', true)
|
||||||
|
} else {
|
||||||
|
commit('changePleroma', false)
|
||||||
|
commit('changeUseWebsocket', false)
|
||||||
|
}
|
||||||
|
},
|
||||||
// -----------------------------------------------
|
// -----------------------------------------------
|
||||||
// Shortcuts
|
// Shortcuts
|
||||||
// -----------------------------------------------
|
// -----------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue