mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-22 02:23:32 +00:00
Debounce update-last-seen on tab switch, throttle idle detection goOnline
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { ref, onMounted, onBeforeUnmount, watch } from 'vue'
|
||||
import { useUserStore } from '@main/stores/user'
|
||||
import { useStorage, useDebounceFn } from '@vueuse/core'
|
||||
import { useStorage, useDebounceFn, useThrottleFn } from '@vueuse/core'
|
||||
|
||||
export function useIdleDetection () {
|
||||
const userStore = useUserStore()
|
||||
@@ -10,7 +10,7 @@ export function useIdleDetection () {
|
||||
const lastActivity = useStorage('last_active', Date.now())
|
||||
const timer = ref(null)
|
||||
|
||||
const goOnline = useDebounceFn(() => {
|
||||
const goOnline = useThrottleFn(() => {
|
||||
if (userStore.user.availability_status === 'away' || userStore.user.availability_status === 'offline') {
|
||||
userStore.updateUserAvailability('online', false)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
<template>
|
||||
<div class="flex flex-col relative flex-1 min-h-0">
|
||||
<!-- Loading conversation overlay -->
|
||||
<div
|
||||
v-if="isLoadingConversation"
|
||||
class="absolute inset-0 bg-background z-10"
|
||||
role="status"
|
||||
>
|
||||
<div v-if="isLoadingConversation" class="absolute inset-0 bg-background z-10" role="status">
|
||||
<Spinner size="md" :text="$t('globals.terms.loading')" absolute />
|
||||
</div>
|
||||
<div
|
||||
@@ -145,7 +141,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, nextTick, onMounted, watch } from 'vue'
|
||||
import { useDocumentVisibility } from '@vueuse/core'
|
||||
import { useDocumentVisibility, useDebounceFn } from '@vueuse/core'
|
||||
import { useWidgetStore } from '../store/widget.js'
|
||||
import { useChatStore } from '../store/chat.js'
|
||||
import { useRelativeTime } from '@widget/composables/useRelativeTime.js'
|
||||
@@ -248,10 +244,16 @@ const scrollToBottom = () => {
|
||||
})
|
||||
}
|
||||
|
||||
// Debounced version for tab-switch and widget-open triggers only.
|
||||
// New message and conversation switch call the store function directly.
|
||||
const debouncedUpdateLastSeen = useDebounceFn(() => {
|
||||
chatStore.updateCurrentConversationLastSeen()
|
||||
}, 2000)
|
||||
|
||||
const visibility = useDocumentVisibility()
|
||||
watch(visibility, (state) => {
|
||||
if (state === 'visible' && widgetStore.isOpen && chatStore.currentConversation?.uuid) {
|
||||
chatStore.updateCurrentConversationLastSeen()
|
||||
debouncedUpdateLastSeen()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user