Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash on tests race-condition #1911

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NextcloudTalk/NCSettingsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ typedef NS_ENUM(NSInteger, NCPreferredFileSorting) {
+ (instancetype)sharedInstance;
- (void)addNewAccountForUser:(NSString *)user withToken:(NSString *)token inServer:(NSString *)server;
- (void)setActiveAccountWithAccountId:(NSString *)accountId;
- (void)getUserProfileForAccountId:(NSString *)accountId withCompletionBlock:(UpdatedProfileCompletionBlock)block;
- (void)getUserProfileForAccountId:(NSString *)accountId withCompletionBlock:(UpdatedProfileCompletionBlock _Nonnull)block;
- (void)logoutAccountWithAccountId:(NSString *)accountId withCompletionBlock:(LogoutCompletionBlock)block;
- (void)getCapabilitiesForAccountId:(NSString *)accountId withCompletionBlock:(GetCapabilitiesCompletionBlock)block;
- (void)updateSignalingConfigurationForAccountId:(NSString * _Nonnull)accountId withCompletionBlock:(UpdateSignalingConfigCompletionBlock _Nonnull)block;
Expand Down
23 changes: 12 additions & 11 deletions NextcloudTalk/NCSettingsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,8 @@ - (void)getUserProfileForAccountId:(NSString *)accountId withCompletionBlock:(Up
TalkAccount *account = [[NCDatabaseManager sharedInstance] talkAccountForAccountId:accountId];

if (!account) {
if (block) {
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil];
block(error);
}
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil];
block(error);

return;
}
Expand All @@ -379,6 +377,13 @@ - (void)getUserProfileForAccountId:(NSString *)accountId withCompletionBlock:(Up
NSPredicate *query = [NSPredicate predicateWithFormat:@"accountId = %@", account.accountId];
TalkAccount *managedActiveAccount = [TalkAccount objectsWithPredicate:query].firstObject;

if (!managedActiveAccount) {
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil];
block(error);

return;
}

managedActiveAccount.userId = [userProfile objectForKey:kUserProfileUserId];
// "display-name" is returned by /cloud/user endpoint
// change to kUserProfileDisplayName ("displayName") when using /cloud/users/{userId} endpoint
Expand All @@ -400,15 +405,11 @@ - (void)getUserProfileForAccountId:(NSString *)accountId withCompletionBlock:(Up

TalkAccount *unmanagedUpdatedAccount = [[TalkAccount alloc] initWithValue:managedActiveAccount];
[[NCAPIController sharedInstance] saveProfileImageForAccount:unmanagedUpdatedAccount];

if (block) {
block(nil);
}

block(nil);
} else {
NSLog(@"Error while getting the user profile");
if (block) {
block(error);
}
block(error);
}
}];
}
Expand Down
Loading