diff --git a/src/global/actions/apiUpdaters/calls.async.ts b/src/global/actions/apiUpdaters/calls.async.ts index 0613dde4e..83ee9db63 100644 --- a/src/global/actions/apiUpdaters/calls.async.ts +++ b/src/global/actions/apiUpdaters/calls.async.ts @@ -102,6 +102,14 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { if (!ARE_CALLS_SUPPORTED) return undefined; const { phoneCall, currentUserId } = global; + // Another call (P2P or group) is already active - ignore here so we don't show the popup; + // the non-async handler discards the new call as busy. + const isInOtherPhoneCall = Boolean(phoneCall?.id) && update.call.id !== phoneCall?.id; + const isInGroupCall = Boolean(global.groupCalls.activeGroupCallId) && !phoneCall; + if (isInOtherPhoneCall || isInGroupCall) { + return undefined; + } + const call: ApiPhoneCall = { ...phoneCall, ...update.call, @@ -116,16 +124,6 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { setGlobal(global); global = getGlobal(); - if (phoneCall && phoneCall.id && call.id !== phoneCall.id) { - if (call.state !== 'discarded') { - callApi('discardCall', { - call, - isBusy: true, - }); - } - return undefined; - } - const { accessHash, state, connections, gB, } = call; diff --git a/src/global/actions/apiUpdaters/calls.ts b/src/global/actions/apiUpdaters/calls.ts index 54a6b1f15..c79f00969 100644 --- a/src/global/actions/apiUpdaters/calls.ts +++ b/src/global/actions/apiUpdaters/calls.ts @@ -5,6 +5,7 @@ import { getCurrentTabId } from '../../../util/establishMultitabRole'; import { omit } from '../../../util/iteratees'; import { notifyAboutCall } from '../../../util/notifications'; import { onTickEnd } from '../../../util/schedulers'; +import { callApi } from '../../../api/gramjs'; import { addActionHandler, getGlobal } from '../../index'; import { updateChat, updateChatFullInfo } from '../../reducers'; import { removeGroupCall, updateGroupCall, updateGroupCallParticipant } from '../../reducers/calls'; @@ -88,6 +89,19 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { const { call } = update; + // Another call (P2P or group) is already active: auto-discard the new incoming call as busy. + const isInOtherPhoneCall = Boolean(phoneCall) && call.id !== phoneCall.id; + const isInGroupCall = Boolean(global.groupCalls.activeGroupCallId) && !phoneCall; + if (isInOtherPhoneCall || isInGroupCall) { + if (call.state !== 'discarded') { + callApi('discardCall', { + call, + isBusy: true, + }); + } + return undefined; + } + if (phoneCall) { if (call.state === 'discarded') { actions.playGroupCallSound({ sound: 'end' });