From 71e888d40fd4f683f7c60b86b9ebbb1006618d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sun, 18 Dec 2022 12:12:15 +0100 Subject: [PATCH] Refactor joinRoomHelper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- NextcloudTalk/NCRoomsManager.m | 45 +++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/NextcloudTalk/NCRoomsManager.m b/NextcloudTalk/NCRoomsManager.m index d9846ca4..9a92b80f 100644 --- a/NextcloudTalk/NCRoomsManager.m +++ b/NextcloudTalk/NCRoomsManager.m @@ -182,28 +182,33 @@ static NSInteger kIgnoreStatusCode = 999; } return; } - - if (!error) { - [NCUtils log:[NSString stringWithFormat:@"Joined room %@ in NC successfully.", token]]; - NCExternalSignalingController *extSignalingController = [[NCSettingsController sharedInstance] externalSignalingControllerForAccountId:activeAccount.accountId]; - if ([extSignalingController isEnabled]) { - [NCUtils log:[NSString stringWithFormat:@"Trying to join room %@ in external signaling server...", token]]; - [extSignalingController joinRoom:token withSessionId:sessionId withCompletionBlock:^(NSError *error) { - if (!error) { - [NCUtils log:[NSString stringWithFormat:@"Joined room %@ in external signaling server successfully.", token]]; - block(sessionId, nil, 0); - } else if (block) { - [NCUtils log:[NSString stringWithFormat:@"Failed joining room %@ in external signaling server.", token]]; - block(nil, error, statusCode); - } - }]; - } else if (block) { - // Joined room in NC successfully and no external signaling server configured. - block(sessionId, nil, 0); + + if (error) { + if (block) { + // Failed to join room in NC. + block(nil, error, statusCode); } + + return; + } + + [NCUtils log:[NSString stringWithFormat:@"Joined room %@ in NC successfully.", token]]; + NCExternalSignalingController *extSignalingController = [[NCSettingsController sharedInstance] externalSignalingControllerForAccountId:activeAccount.accountId]; + + if ([extSignalingController isEnabled]) { + [NCUtils log:[NSString stringWithFormat:@"Trying to join room %@ in external signaling server...", token]]; + [extSignalingController joinRoom:token withSessionId:sessionId withCompletionBlock:^(NSError *error) { + if (!error) { + [NCUtils log:[NSString stringWithFormat:@"Joined room %@ in external signaling server successfully.", token]]; + block(sessionId, nil, 0); + } else if (block) { + [NCUtils log:[NSString stringWithFormat:@"Failed joining room %@ in external signaling server.", token]]; + block(nil, error, statusCode); + } + }]; } else if (block) { - // Failed to join room in NC. - block(nil, error, statusCode); + // Joined room in NC successfully and no external signaling server configured. + block(sessionId, nil, 0); } }]; }