Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(callbox): check if there are no participants in call #964

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/callbox/renderer/callbox.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,38 @@ async function getCallParticipants(token: string) {
/**
* Check if the current user has joined the call
* @param token - Conversation token
* @return Promise<boolean|null> - whether participant is in the call (`null` if there is no current call)
*/
async function hasCurrentUserJoinedCall(token: string) {
const user = getCurrentUser()
if (!user) {
throw new Error('Cannot check whether current join the call - no current user found')
}
const participants = await getCallParticipants(token)
if (!participants.length) {
return null
}
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> {
Antreesy marked this conversation as resolved.
Show resolved Hide resolved
try {
const response = await hasCurrentUserJoinedCall(token)
if (response === null) {
return false
}
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 All @@ -72,7 +94,10 @@ export function waitCurrentUserHasJoinedCall(token: string, limit?: number): Pro

try {
// Check if the user has joined the call
if (await hasCurrentUserJoinedCall(token)) {
const result = await hasCurrentUserJoinedCall(token)
if (result === null) {
return resolve(false)
} else if (result === true) {
return resolve(true)
}
} catch (e) {
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