Calls: Fix old call panel being stuck (#1923)

This commit is contained in:
Alexander Zinchuk 2022-06-27 22:02:59 +02:00
parent d509583a0c
commit bfe0cd8275
3 changed files with 33 additions and 11 deletions

View File

@ -101,8 +101,16 @@ const PhoneCall: FC<StateProps> = ({
const isActive = phoneCall?.state === 'active'; const isActive = phoneCall?.state === 'active';
const isConnected = phoneCall?.isConnected; const isConnected = phoneCall?.isConnected;
const [isHangingUp, startHangingUp, stopHangingUp] = useFlag();
const handleHangUp = useCallback(() => {
startHangingUp();
hangUp();
}, [hangUp, startHangingUp]);
useEffect(() => { useEffect(() => {
if (isIncomingRequested) { if (isHangingUp) {
playGroupCallSound({ sound: 'end' });
} else if (isIncomingRequested) {
playGroupCallSound({ sound: 'incoming' }); playGroupCallSound({ sound: 'incoming' });
} else if (isBusy) { } else if (isBusy) {
playGroupCallSound({ sound: 'busy' }); playGroupCallSound({ sound: 'busy' });
@ -113,13 +121,7 @@ const PhoneCall: FC<StateProps> = ({
} else if (isConnected) { } else if (isConnected) {
playGroupCallSound({ sound: 'connect' }); playGroupCallSound({ sound: 'connect' });
} }
}, [isBusy, isDiscarded, isIncomingRequested, isOutgoingRequested, isConnected, playGroupCallSound]); }, [isBusy, isDiscarded, isIncomingRequested, isOutgoingRequested, isConnected, playGroupCallSound, isHangingUp]);
const [isHangingUp, startHangingUp, stopHangingUp] = useFlag();
const handleHangUp = useCallback(() => {
startHangingUp();
hangUp();
}, [hangUp, startHangingUp]);
useEffect(() => { useEffect(() => {
if (phoneCall?.id) { if (phoneCall?.id) {

View File

@ -313,5 +313,13 @@ addActionHandler('hangUp', (global) => {
}; };
} }
setTimeout(() => {
setGlobal({
...getGlobal(),
phoneCall: undefined,
isCallPanelVisible: undefined,
});
}, 500);
return undefined; return undefined;
}); });

View File

@ -69,16 +69,28 @@ addActionHandler('apiUpdate', (global, actions, update) => {
currentUserId, currentUserId,
} = global; } = global;
if (phoneCall) return undefined;
const { call } = update; const { call } = update;
if (phoneCall) {
if (call.state === 'discarded') {
return {
...global,
...(call.needRating && { ratingPhoneCall: call }),
isCallPanelVisible: undefined,
phoneCall: undefined,
};
}
return undefined;
}
const isOutgoing = call?.adminId === currentUserId; const isOutgoing = call?.adminId === currentUserId;
if (!isOutgoing && call.state === 'requested') { if (!isOutgoing && call.state === 'requested') {
onTickEnd(() => { onTickEnd(() => {
notifyAboutCall({ notifyAboutCall({
call, call,
user: selectPhoneCallUser(global)!, user: selectPhoneCallUser(getGlobal())!,
}); });
}); });