1
0
mirror of https://github.com/nolanlawson/pinafore synced 2025-01-25 13:09:19 +01:00

42 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-03-03 14:15:50 -08:00
import { updateInstanceInfo, updateVerifyCredentialsForInstance } from '../../_actions/instances'
import { updateLists } from '../../_actions/lists'
import { createStream } from '../../_actions/streaming'
2018-02-11 13:46:57 -08:00
export function instanceObservers (store) {
2018-02-15 09:02:46 -08: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 13:46:57 -08:00
if (!currentInstance) {
return
}
updateVerifyCredentialsForInstance(currentInstance)
updateInstanceInfo(currentInstance)
updateLists()
2018-02-15 09:02:46 -08: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 13:46:57 -08:00
})
2018-02-11 14:11:03 -08:00
}