mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-25 10:46:17 +03:00
fix: initialise stream promise before stream is available (#1191)
This commit is contained in:
parent
a594f6f167
commit
cd8e2cb6a4
1 changed files with 10 additions and 6 deletions
|
@ -12,20 +12,24 @@ export const useNotifications = () => {
|
||||||
return
|
return
|
||||||
const lastReadId = notifications[id]![1][0]
|
const lastReadId = notifications[id]![1][0]
|
||||||
notifications[id]![1] = []
|
notifications[id]![1] = []
|
||||||
|
if (lastReadId) {
|
||||||
await client.v1.markers.create({
|
await client.v1.markers.create({
|
||||||
notifications: { lastReadId },
|
notifications: { lastReadId },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function connect(): Promise<void> {
|
async function connect(): Promise<void> {
|
||||||
if (!isHydrated.value || !id || notifications[id] || !currentUser.value?.token)
|
if (!isHydrated.value || !id || notifications[id] || !currentUser.value?.token)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
let resolveStream
|
||||||
|
const stream = new Promise<WsEvents>(resolve => resolveStream = resolve)
|
||||||
|
notifications[id] = [stream, []]
|
||||||
|
|
||||||
await until($$(canStreaming)).toBe(true)
|
await until($$(canStreaming)).toBe(true)
|
||||||
|
|
||||||
const stream = client.v1.stream.streamUser()
|
client.v1.stream.streamUser().then(resolveStream)
|
||||||
notifications[id] = [stream, []]
|
|
||||||
stream.then(s => s.on('notification', (n) => {
|
stream.then(s => s.on('notification', (n) => {
|
||||||
if (notifications[id])
|
if (notifications[id])
|
||||||
notifications[id]![1].unshift(n.id)
|
notifications[id]![1].unshift(n.id)
|
||||||
|
|
Loading…
Reference in a new issue