Fix joining deleted call links leaving call active
Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com>
This commit is contained in:
		
					parent
					
						
							
								b86663b1b7
							
						
					
				
			
			
				commit
				
					
						a099c402ff
					
				
			
		
					 2 changed files with 68 additions and 24 deletions
				
			
		| 
						 | 
				
			
			@ -2252,6 +2252,7 @@ const _startCallLinkLobby = async ({
 | 
			
		|||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  let success = false;
 | 
			
		||||
  try {
 | 
			
		||||
    dispatch({
 | 
			
		||||
      type: WAITING_FOR_CALL_LINK_LOBBY,
 | 
			
		||||
| 
						 | 
				
			
			@ -2342,22 +2343,25 @@ const _startCallLinkLobby = async ({
 | 
			
		|||
        isConversationTooBigToRing: false,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
    success = true;
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    log.error(`${logId}: Failed to start lobby`, Errors.toLogFormat(error));
 | 
			
		||||
  } finally {
 | 
			
		||||
    if (!success) {
 | 
			
		||||
      try {
 | 
			
		||||
        calling.stopCallingLobby(roomId);
 | 
			
		||||
      } catch (innerError) {
 | 
			
		||||
        log.error(
 | 
			
		||||
          `${logId}: Failed to stop calling lobby`,
 | 
			
		||||
          Errors.toLogFormat(innerError)
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      calling.stopCallingLobby(roomId);
 | 
			
		||||
    } catch (innerError) {
 | 
			
		||||
      log.error(
 | 
			
		||||
        `${logId}: Failed to stop calling lobby`,
 | 
			
		||||
        Errors.toLogFormat(innerError)
 | 
			
		||||
      );
 | 
			
		||||
      dispatch({
 | 
			
		||||
        type: CALL_LOBBY_FAILED,
 | 
			
		||||
        payload: { conversationId: roomId },
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    dispatch({
 | 
			
		||||
      type: CALL_LOBBY_FAILED,
 | 
			
		||||
      payload: { conversationId: roomId },
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2437,6 +2441,7 @@ function startCallingLobby({
 | 
			
		|||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let success = false;
 | 
			
		||||
    try {
 | 
			
		||||
      dispatch({
 | 
			
		||||
        type: WAITING_FOR_CALLING_LOBBY,
 | 
			
		||||
| 
						 | 
				
			
			@ -2473,22 +2478,25 @@ function startCallingLobby({
 | 
			
		|||
          isConversationTooBigToRing: isConversationTooBigToRing(conversation),
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
      success = true;
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
      log.error(`${logId}: Failed to start lobby`, Errors.toLogFormat(error));
 | 
			
		||||
    } finally {
 | 
			
		||||
      if (!success) {
 | 
			
		||||
        try {
 | 
			
		||||
          calling.stopCallingLobby(conversationId);
 | 
			
		||||
        } catch (innerError) {
 | 
			
		||||
          log.error(
 | 
			
		||||
            `${logId}: Failed to stop calling lobby`,
 | 
			
		||||
            Errors.toLogFormat(innerError)
 | 
			
		||||
          );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
      try {
 | 
			
		||||
        calling.stopCallingLobby(conversationId);
 | 
			
		||||
      } catch (innerError) {
 | 
			
		||||
        log.error(
 | 
			
		||||
          `${logId}: Failed to stop calling lobby`,
 | 
			
		||||
          Errors.toLogFormat(innerError)
 | 
			
		||||
        );
 | 
			
		||||
        dispatch({
 | 
			
		||||
          type: CALL_LOBBY_FAILED,
 | 
			
		||||
          payload: { conversationId },
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      dispatch({
 | 
			
		||||
        type: CALL_LOBBY_FAILED,
 | 
			
		||||
        payload: { conversationId },
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1579,6 +1579,42 @@ describe('calling duck', () => {
 | 
			
		|||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    describe('startCallLinkLobby for deleted links', () => {
 | 
			
		||||
      beforeEach(function (this: Mocha.Context) {
 | 
			
		||||
        this.callingServiceReadCallLink = this.sandbox
 | 
			
		||||
          .stub(callingService, 'readCallLink')
 | 
			
		||||
          .resolves(null);
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const doAction = async (
 | 
			
		||||
        payload: StartCallLinkLobbyType
 | 
			
		||||
      ): Promise<{ dispatch: sinon.SinonSpy }> => {
 | 
			
		||||
        const { startCallLinkLobby } = actions;
 | 
			
		||||
        const dispatch = sinon.spy();
 | 
			
		||||
        await startCallLinkLobby(payload)(dispatch, getEmptyRootState, null);
 | 
			
		||||
        return { dispatch };
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      it('fails', async function (this: Mocha.Context) {
 | 
			
		||||
        const { roomId, rootKey } = FAKE_CALL_LINK;
 | 
			
		||||
        const { dispatch } = await doAction({ rootKey });
 | 
			
		||||
 | 
			
		||||
        sinon.assert.calledTwice(dispatch);
 | 
			
		||||
        sinon.assert.calledWith(dispatch, {
 | 
			
		||||
          type: 'calling/WAITING_FOR_CALL_LINK_LOBBY',
 | 
			
		||||
          payload: {
 | 
			
		||||
            roomId,
 | 
			
		||||
          },
 | 
			
		||||
        });
 | 
			
		||||
        sinon.assert.calledWith(dispatch, {
 | 
			
		||||
          type: 'calling/CALL_LOBBY_FAILED',
 | 
			
		||||
          payload: {
 | 
			
		||||
            conversationId: roomId,
 | 
			
		||||
          },
 | 
			
		||||
        });
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    describe('peekNotConnectedGroupCall', () => {
 | 
			
		||||
      const { peekNotConnectedGroupCall } = actions;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue