From 6ca3616e2ef2d255c4e88ce7a435601ae6d5d7a6 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Thu, 5 Dec 2024 12:15:37 +0100 Subject: [PATCH] fix(notifications): check once if call notification is valid (not missed) - if missed, don't show callbox, but native notification and default sound Signed-off-by: Maksim Sukharev --- src/callbox/renderer/callbox.service.ts | 15 +++++++++++++++ .../renderer/notifications/notifications.store.js | 14 ++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/callbox/renderer/callbox.service.ts b/src/callbox/renderer/callbox.service.ts index 314527d8..6b2039a0 100644 --- a/src/callbox/renderer/callbox.service.ts +++ b/src/callbox/renderer/callbox.service.ts @@ -57,6 +57,21 @@ async function hasCurrentUserJoinedCall(token: string) { return participants.some((participant) => user.uid === participant.actorId) } +/** + * Check if callbox should be rendered + * @param token - Conversation token + * @return Promise - Resolved with boolean - true if the user should see the callbox, false otherwise + */ +export async function checkCurrentUserHasPendingCall(token: string): Promise { + try { + const response = await hasCurrentUserJoinedCall(token) + return !response + } catch (e) { + console.warn('Error while checking if the user has pending call', e) + return false + } +} + /** * Wait until the current user has joined the call * @param token - Conversation token diff --git a/src/talk/renderer/notifications/notifications.store.js b/src/talk/renderer/notifications/notifications.store.js index 04583f03..e5947fca 100644 --- a/src/talk/renderer/notifications/notifications.store.js +++ b/src/talk/renderer/notifications/notifications.store.js @@ -20,6 +20,7 @@ import { t } from '@nextcloud/l10n' import { getNotificationsData } from './notifications.service.js' import { appData } from '../../../app/AppData.js' import { useUserStatusStore } from '../UserStatus/userStatus.store.js' +import { checkCurrentUserHasPendingCall } from '../../../callbox/renderer/callbox.service.ts' import { getAppConfigValue } from '../../../shared/appConfig.service.ts' import { subscribeBroadcast } from '../../../shared/broadcast.service.ts' import { openConversation } from '../utils/talk.service.ts' @@ -160,7 +161,7 @@ export function createNotificationStore() { * * @param notification */ - function showNativeNotification(notification) { + async function showNativeNotification(notification) { if (notification.app !== 'spreed') { return } @@ -168,8 +169,13 @@ export function createNotificationStore() { return } + const isNotificationFromPendingCall = notification.objectType === 'call' + && await checkCurrentUserHasPendingCall(notification.objectId) + const enableCallboxConfig = getAppConfigValue('enableCallbox') - const shouldShowCallPopup = notification.objectType === 'call' && (enableCallboxConfig === 'always' || (enableCallboxConfig === 'respect-dnd' && !userStatusStore.isDnd)) + const shouldShowCallPopup = isNotificationFromPendingCall + && (enableCallboxConfig === 'always' || (enableCallboxConfig === 'respect-dnd' && !userStatusStore.isDnd)) + if (shouldShowCallPopup) { const params = { token: notification.objectId, @@ -201,7 +207,7 @@ export function createNotificationStore() { emit('notifications:action:execute', event) }, false) } - playSound(notification.objectType === 'call') + playSound(isNotificationFromPendingCall) } /** @@ -222,7 +228,7 @@ export function createNotificationStore() { notificationsSet = new Set(state.notifications.map((notification) => notification.notificationId)) if (state.backgroundFetching) { for (const notification of newNotifications) { - showNativeNotification(notification) + await showNativeNotification(notification) emit('notifications:notification:received', { notification }) } }