From bfe0cd8275f96d8daa56d16e80d3ba280537c210 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 27 Jun 2022 22:02:59 +0200 Subject: [PATCH] Calls: Fix old call panel being stuck (#1923) --- src/components/calls/phone/PhoneCall.tsx | 18 ++++++++++-------- src/global/actions/api/calls.async.ts | 8 ++++++++ src/global/actions/apiUpdaters/calls.ts | 18 +++++++++++++++--- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/components/calls/phone/PhoneCall.tsx b/src/components/calls/phone/PhoneCall.tsx index d810f345..863b176e 100644 --- a/src/components/calls/phone/PhoneCall.tsx +++ b/src/components/calls/phone/PhoneCall.tsx @@ -101,8 +101,16 @@ const PhoneCall: FC = ({ const isActive = phoneCall?.state === 'active'; const isConnected = phoneCall?.isConnected; + const [isHangingUp, startHangingUp, stopHangingUp] = useFlag(); + const handleHangUp = useCallback(() => { + startHangingUp(); + hangUp(); + }, [hangUp, startHangingUp]); + useEffect(() => { - if (isIncomingRequested) { + if (isHangingUp) { + playGroupCallSound({ sound: 'end' }); + } else if (isIncomingRequested) { playGroupCallSound({ sound: 'incoming' }); } else if (isBusy) { playGroupCallSound({ sound: 'busy' }); @@ -113,13 +121,7 @@ const PhoneCall: FC = ({ } else if (isConnected) { playGroupCallSound({ sound: 'connect' }); } - }, [isBusy, isDiscarded, isIncomingRequested, isOutgoingRequested, isConnected, playGroupCallSound]); - - const [isHangingUp, startHangingUp, stopHangingUp] = useFlag(); - const handleHangUp = useCallback(() => { - startHangingUp(); - hangUp(); - }, [hangUp, startHangingUp]); + }, [isBusy, isDiscarded, isIncomingRequested, isOutgoingRequested, isConnected, playGroupCallSound, isHangingUp]); useEffect(() => { if (phoneCall?.id) { diff --git a/src/global/actions/api/calls.async.ts b/src/global/actions/api/calls.async.ts index 072724c0..cbfd92ff 100644 --- a/src/global/actions/api/calls.async.ts +++ b/src/global/actions/api/calls.async.ts @@ -313,5 +313,13 @@ addActionHandler('hangUp', (global) => { }; } + setTimeout(() => { + setGlobal({ + ...getGlobal(), + phoneCall: undefined, + isCallPanelVisible: undefined, + }); + }, 500); + return undefined; }); diff --git a/src/global/actions/apiUpdaters/calls.ts b/src/global/actions/apiUpdaters/calls.ts index 4e0b23dc..c58111fe 100644 --- a/src/global/actions/apiUpdaters/calls.ts +++ b/src/global/actions/apiUpdaters/calls.ts @@ -69,16 +69,28 @@ addActionHandler('apiUpdate', (global, actions, update) => { currentUserId, } = global; - if (phoneCall) return undefined; - 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; if (!isOutgoing && call.state === 'requested') { onTickEnd(() => { notifyAboutCall({ call, - user: selectPhoneCallUser(global)!, + user: selectPhoneCallUser(getGlobal())!, }); });