From 88bb199da259ec60cb2cf953a8ddc3a594f073a1 Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Sun, 5 Apr 2026 00:54:29 +0530 Subject: [PATCH] Clear typing indicators after 5 sec --- frontend/apps/main/src/stores/conversation.js | 15 +++++++++++++++ frontend/apps/widget/src/store/chat.js | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/frontend/apps/main/src/stores/conversation.js b/frontend/apps/main/src/stores/conversation.js index 19616cc9..f7e0b180 100644 --- a/frontend/apps/main/src/stores/conversation.js +++ b/frontend/apps/main/src/stores/conversation.js @@ -87,6 +87,8 @@ export const useConversationStore = defineStore('conversation', () => { priority_first: 'conversation.sort.priorityFirst' } + let typingTimeout = null + const conversations = reactive({ data: [], listType: null, @@ -798,7 +800,20 @@ export const useConversationStore = defineStore('conversation', () => { // Only update typing status for the current conversation if (conversation.data?.uuid !== conversation_uuid) return + if (typingTimeout) { + clearTimeout(typingTimeout) + typingTimeout = null + } + conversation.isTyping = is_typing + + // Auto-clear after 5s if no new typing event arrives. + if (is_typing) { + typingTimeout = setTimeout(() => { + conversation.isTyping = false + typingTimeout = null + }, 5000) + } } function sendTyping (isTyping, otherAttributes = {}) { diff --git a/frontend/apps/widget/src/store/chat.js b/frontend/apps/widget/src/store/chat.js index 27a8bac3..0947bb4b 100644 --- a/frontend/apps/widget/src/store/chat.js +++ b/frontend/apps/widget/src/store/chat.js @@ -8,6 +8,7 @@ import { useUserStore } from './user.js' export const useChatStore = defineStore('chat', () => { const userStore = useUserStore() // State + let typingTimeout = null const isTyping = ref(false) const currentConversation = ref({}) const conversations = ref(null) @@ -167,10 +168,22 @@ export const useChatStore = defineStore('chat', () => { const setTypingStatus = (conversationUUID, status) => { if (!conversationUUID) return - if (currentConversation.value?.uuid !== conversationUUID) { - return + if (currentConversation.value?.uuid !== conversationUUID) return + + if (typingTimeout) { + clearTimeout(typingTimeout) + typingTimeout = null } + isTyping.value = status + + // Auto-clear after 5s if no new typing event arrives. + if (status) { + typingTimeout = setTimeout(() => { + isTyping.value = false + typingTimeout = null + }, 5000) + } } const setCurrentConversation = (conversation) => {