fedilove-ui/routes/_store/observers/instanceObservers.js

42 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-03-03 22:15:50 +00:00
import { updateInstanceInfo, updateVerifyCredentialsForInstance } from '../../_actions/instances'
import { updateLists } from '../../_actions/lists'
import { createStream } from '../../_actions/streaming'
2018-02-11 21:46:57 +00:00
export function instanceObservers (store) {
2018-02-15 17:02:46 +00:00
// stream to watch for home timeline updates and notifications
let currentInstanceStream
store.observe('currentInstance', async (currentInstance) => {
if (!process.browser) {
return
}
if (currentInstanceStream) {
currentInstanceStream.close()
currentInstanceStream = null
if (process.env.NODE_ENV !== 'production') {
window.currentInstanceStream = null
}
}
2018-02-11 21:46:57 +00:00
if (!currentInstance) {
return
}
updateVerifyCredentialsForInstance(currentInstance)
updateInstanceInfo(currentInstance)
updateLists()
2018-02-15 17:02:46 +00:00
await updateInstanceInfo(currentInstance)
let instanceInfo = store.get('currentInstanceInfo')
if (!(instanceInfo && store.get('currentInstance') === currentInstance)) {
return
}
let accessToken = store.get('accessToken')
currentInstanceStream = createStream(instanceInfo.urls.streaming_api,
currentInstance, accessToken, 'home')
if (process.env.NODE_ENV !== 'production') {
window.currentInstanceStream = currentInstanceStream
}
2018-02-11 21:46:57 +00:00
})
2018-02-11 22:11:03 +00:00
}