From c69af3a503851de168ac5e03d0ee1f4c9df87f02 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Mon, 20 Oct 2025 19:18:04 +0200 Subject: [PATCH] fix(useGetMessages): always start message polling - fallback to last read message + long polling if context request was cancelled Signed-off-by: Maksim Sukharev --- src/composables/useGetMessages.ts | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/composables/useGetMessages.ts b/src/composables/useGetMessages.ts index 0d0dd649465..32447ab4906 100644 --- a/src/composables/useGetMessages.ts +++ b/src/composables/useGetMessages.ts @@ -318,23 +318,22 @@ export function useGetMessagesProvider() { } await getMessageContext(token, contextMessageId.value, contextThreadId.value) - - // If last message is not present in the initial context, - // add it as most recent chat block to start long polling from it - if (conversation.value?.lastMessage && 'id' in conversation.value.lastMessage - && !chatStore.hasMessage(token, { messageId: conversation.value.lastMessage.id })) { - await store.dispatch('processMessage', { token, message: conversation.value.lastMessage }) - chatStore.processChatBlocks(token, [conversation.value.lastMessage]) - } - - // Fallback for sensitive and federated conversations: if there is still no chat block created, - // ensure polling starts at least from the last read message by the user - if (!chatStore.chatBlocks[token]) { - chatStore.chatBlocks[token] = [new Set([conversation.value!.lastReadMessage])] - } } catch (exception) { console.debug(exception) - return + } + + // If last message is not present in the initial context, + // add it as most recent chat block to start long polling from it + if (conversation.value?.lastMessage && 'id' in conversation.value.lastMessage + && !chatStore.hasMessage(token, { messageId: conversation.value.lastMessage.id })) { + await store.dispatch('processMessage', { token, message: conversation.value.lastMessage }) + chatStore.processChatBlocks(token, [conversation.value.lastMessage]) + } + + // Fallback for sensitive and federated conversations: if there is still no chat block created, + // ensure polling starts at least from the last read message by the user + if (!chatStore.chatBlocks[token]) { + chatStore.chatBlocks[token] = [new Set([conversation.value!.lastReadMessage])] } } else { await checkContextAndFocusMessage(token, contextMessageId.value, contextThreadId.value, focusMessageId !== null)