Skip to content

Commit

Permalink
fix(notifications): check once if call notification is valid (not mis…
Browse files Browse the repository at this point in the history
…sed)

- if missed, don't show callbox, but native notification and default sound

Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Dec 5, 2024
1 parent e94a922 commit 6ca3616
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/callbox/renderer/callbox.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> - Resolved with boolean - true if the user should see the callbox, false otherwise
*/
export async function checkCurrentUserHasPendingCall(token: string): Promise<boolean> {
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
Expand Down
14 changes: 10 additions & 4 deletions src/talk/renderer/notifications/notifications.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -160,16 +161,21 @@ export function createNotificationStore() {
*
* @param notification
*/
function showNativeNotification(notification) {
async function showNativeNotification(notification) {
if (notification.app !== 'spreed') {
return
}
if (notification.shouldNotify === false) {
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,
Expand Down Expand Up @@ -201,7 +207,7 @@ export function createNotificationStore() {
emit('notifications:action:execute', event)
}, false)
}
playSound(notification.objectType === 'call')
playSound(isNotificationFromPendingCall)
}

/**
Expand All @@ -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 })
}
}
Expand Down

0 comments on commit 6ca3616

Please sign in to comment.