From cd8e2cb6a4f37f31423dbbc9301f7474f60e09fe Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sun, 15 Jan 2023 20:26:59 +0000 Subject: [PATCH] fix: initialise stream promise before stream is available (#1191) --- composables/masto/notification.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/composables/masto/notification.ts b/composables/masto/notification.ts index 1a0e007d..8fa11827 100644 --- a/composables/masto/notification.ts +++ b/composables/masto/notification.ts @@ -12,20 +12,24 @@ export const useNotifications = () => { return const lastReadId = notifications[id]![1][0] notifications[id]![1] = [] - - await client.v1.markers.create({ - notifications: { lastReadId }, - }) + if (lastReadId) { + await client.v1.markers.create({ + notifications: { lastReadId }, + }) + } } async function connect(): Promise { if (!isHydrated.value || !id || notifications[id] || !currentUser.value?.token) return + let resolveStream + const stream = new Promise(resolve => resolveStream = resolve) + notifications[id] = [stream, []] + await until($$(canStreaming)).toBe(true) - const stream = client.v1.stream.streamUser() - notifications[id] = [stream, []] + client.v1.stream.streamUser().then(resolveStream) stream.then(s => s.on('notification', (n) => { if (notifications[id]) notifications[id]![1].unshift(n.id)