From 60cb14e0b69fbd340b03b47da01027239df2c0a3 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Sat, 14 Sep 2024 15:04:09 +0200 Subject: [PATCH] fix: move page visibility check to composable Signed-off-by: Maksim Sukharev --- src/App.vue | 44 +++++++++----------- src/components/MessagesList/MessagesList.vue | 15 +++---- src/components/TopBar/CallTime.vue | 9 +++- src/composables/useActiveSession.js | 5 ++- src/composables/useGetParticipants.js | 4 +- src/composables/useWindowVisibility.ts | 36 ++++++++++++++++ src/store/windowVisibilityStore.js | 24 ----------- 7 files changed, 78 insertions(+), 59 deletions(-) create mode 100644 src/composables/useWindowVisibility.ts diff --git a/src/App.vue b/src/App.vue index 858f33a1a6a..2f010d83d69 100644 --- a/src/App.vue +++ b/src/App.vue @@ -41,6 +41,7 @@ import { useActiveSession } from './composables/useActiveSession.js' import { useHashCheck } from './composables/useHashCheck.js' import { useIsInCall } from './composables/useIsInCall.js' import { useSessionIssueHandler } from './composables/useSessionIssueHandler.js' +import { useWindowVisibility } from './composables/useWindowVisibility.ts' import { CONVERSATION, PARTICIPANT } from './constants.js' import Router from './router/router.js' import BrowserStorage from './services/BrowserStorage.js' @@ -71,6 +72,7 @@ export default { isLeavingAfterSessionIssue: useSessionIssueHandler(), isMobile: useIsMobile(), isNextcloudTalkHashDirty: useHashCheck(), + isWindowVisible: useWindowVisibility(), supportSessionState: useActiveSession(), federationStore: useFederationStore(), } @@ -88,9 +90,6 @@ export default { }, computed: { - windowIsVisible() { - return this.$store.getters.windowIsVisible() - }, isFullscreen() { return this.$store.getters.isFullscreen() }, @@ -189,7 +188,7 @@ export default { watch: { atLeastOneLastMessageIdChanged() { - if (this.windowIsVisible) { + if (this.isWindowVisible) { return } @@ -220,7 +219,23 @@ export default { toggle?.removeAttribute('data-theme-dark') } } - } + }, + + isWindowVisible(value) { + if (value) { + // Remove the potential "*" marker for unread chat messages + let title = this.getConversationName(this.token) + if (window.document.title.indexOf(t('spreed', 'Duplicate session')) === 0) { + title = t('spreed', 'Duplicate session') + } + this.setPageTitle(title, false) + } else { + // Copy the last message map to the saved version, + // this will be our reference to check if any chat got a new + // message since the last visit + this.savedLastMessageMap = this.lastMessageMap + } + }, }, beforeCreate() { @@ -249,7 +264,6 @@ export default { if (!getCurrentUser()) { EventBus.off('should-refresh-conversations', this.debounceRefreshCurrentConversation) } - document.removeEventListener('visibilitychange', this.changeWindowVisibility) unsubscribe('notifications:action:execute', this.interceptNotificationActions) @@ -272,7 +286,6 @@ export default { } window.addEventListener('resize', this.onResize) - document.addEventListener('visibilitychange', this.changeWindowVisibility) this.onResize() @@ -625,23 +638,6 @@ export default { this.fetchSingleConversation(this.token) }, - changeWindowVisibility() { - this.$store.dispatch('setWindowVisibility', !document.hidden) - if (this.windowIsVisible) { - // Remove the potential "*" marker for unread chat messages - let title = this.getConversationName(this.token) - if (window.document.title.indexOf(t('spreed', 'Duplicate session')) === 0) { - title = t('spreed', 'Duplicate session') - } - this.setPageTitle(title, false) - } else { - // Copy the last message map to the saved version, - // this will be our reference to check if any chat got a new - // message since the last visit - this.savedLastMessageMap = this.lastMessageMap - } - }, - /** * Set the page title to the conversation name * diff --git a/src/components/MessagesList/MessagesList.vue b/src/components/MessagesList/MessagesList.vue index 09237eab2b6..00388517223 100644 --- a/src/components/MessagesList/MessagesList.vue +++ b/src/components/MessagesList/MessagesList.vue @@ -59,6 +59,7 @@