Calls: Discard incoming calls as busy when already in a call (#6952)

This commit is contained in:
zubiden 2026-06-01 01:15:52 +02:00 committed by Alexander Zinchuk
parent 198da4736e
commit e6ba963240
2 changed files with 22 additions and 10 deletions

View File

@ -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;

View File

@ -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' });