зеркало из https://github.com/nextcloud/talk-ios.git
Explicitly pass account for profile, capabilities and signaling methods
Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Родитель
e53ec85b28
Коммит
c000e3cc86
|
@ -110,7 +110,7 @@ NSString * const NCConnectionStateHasChangedNotification = @"NCConnectionStat
|
|||
[[NCUserInterfaceController sharedInstance] presentLoginViewController];
|
||||
} else if (!activeAccount.userId || !activeAccount.userDisplayName) {
|
||||
[self setAppState:kAppStateMissingUserProfile];
|
||||
[[NCSettingsController sharedInstance] getUserProfileWithCompletionBlock:^(NSError *error) {
|
||||
[[NCSettingsController sharedInstance] getUserProfileForAccountId:activeAccount.accountId withCompletionBlock:^(NSError *error) {
|
||||
if (error) {
|
||||
[self notifyAppState];
|
||||
} else {
|
||||
|
@ -119,22 +119,23 @@ NSString * const NCConnectionStateHasChangedNotification = @"NCConnectionStat
|
|||
}];
|
||||
} else if (!activeAccountSignalingConfig) {
|
||||
[self setAppState:kAppStateMissingServerCapabilities];
|
||||
[[NCSettingsController sharedInstance] getCapabilitiesWithCompletionBlock:^(NSError *error) {
|
||||
[[NCSettingsController sharedInstance] getCapabilitiesForAccountId:activeAccount.accountId withCompletionBlock:^(NSError *error) {
|
||||
if (error) {
|
||||
[self notifyAppState];
|
||||
} else {
|
||||
[self setAppState:kAppStateMissingSignalingConfiguration];
|
||||
[[NCSettingsController sharedInstance] getSignalingConfigurationWithCompletionBlock:^(NSError *error) {
|
||||
if (error) {
|
||||
[self notifyAppState];
|
||||
} else {
|
||||
// SetSignalingConfiguration should be called just once
|
||||
TalkAccount *account = [[NCDatabaseManager sharedInstance] activeAccount];
|
||||
[[NCSettingsController sharedInstance] setSignalingConfigurationForAccountId:account.accountId];
|
||||
[self checkAppState];
|
||||
}
|
||||
}];
|
||||
return;
|
||||
}
|
||||
|
||||
[self setAppState:kAppStateMissingSignalingConfiguration];
|
||||
[[NCSettingsController sharedInstance] getSignalingConfigurationForAccountId:activeAccount.accountId withCompletionBlock:^(NSError *error) {
|
||||
if (error) {
|
||||
[self notifyAppState];
|
||||
return;
|
||||
}
|
||||
|
||||
// SetSignalingConfiguration should be called just once
|
||||
[[NCSettingsController sharedInstance] setSignalingConfigurationForAccountId:activeAccount.accountId];
|
||||
[self checkAppState];
|
||||
}];
|
||||
}];
|
||||
} else {
|
||||
[self setAppState:kAppStateReady];
|
||||
|
|
|
@ -68,10 +68,10 @@ typedef enum NCPreferredFileSorting {
|
|||
+ (instancetype)sharedInstance;
|
||||
- (void)addNewAccountForUser:(NSString *)user withToken:(NSString *)token inServer:(NSString *)server;
|
||||
- (void)setActiveAccountWithAccountId:(NSString *)accountId;
|
||||
- (void)getUserProfileWithCompletionBlock:(UpdatedProfileCompletionBlock)block;
|
||||
- (void)getUserProfileForAccountId:(NSString *)accountId withCompletionBlock:(UpdatedProfileCompletionBlock)block;
|
||||
- (void)logoutAccountWithAccountId:(NSString *)accountId withCompletionBlock:(LogoutCompletionBlock)block;
|
||||
- (void)getCapabilitiesWithCompletionBlock:(GetCapabilitiesCompletionBlock)block;
|
||||
- (void)getSignalingConfigurationWithCompletionBlock:(GetSignalingConfigCompletionBlock)block;
|
||||
- (void)getCapabilitiesForAccountId:(NSString *)accountId withCompletionBlock:(GetCapabilitiesCompletionBlock)block;
|
||||
- (void)getSignalingConfigurationForAccountId:(NSString *)accountId withCompletionBlock:(GetSignalingConfigCompletionBlock)block;
|
||||
- (void)setSignalingConfigurationForAccountId:(NSString *)accountId;
|
||||
- (NCExternalSignalingController *)externalSignalingControllerForAccountId:(NSString *)accountId;
|
||||
- (void)connectDisconnectedExternalSignalingControllers;
|
||||
|
|
|
@ -217,12 +217,12 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
|
|||
return;
|
||||
}
|
||||
|
||||
[[NCSettingsController sharedInstance] getCapabilitiesWithCompletionBlock:^(NSError *error) {
|
||||
[[NCSettingsController sharedInstance] getCapabilitiesForAccountId:accountId withCompletionBlock:^(NSError *error) {
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
|
||||
[[NCSettingsController sharedInstance] getSignalingConfigurationWithCompletionBlock:^(NSError *error) {
|
||||
[[NCSettingsController sharedInstance] getSignalingConfigurationForAccountId:accountId withCompletionBlock:^(NSError *error) {
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
|
@ -230,9 +230,8 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
|
|||
BGTaskHelper *bgTask = [BGTaskHelper startBackgroundTaskWithName:@"NCUpdateSignalingConfiguration" expirationHandler:nil];
|
||||
|
||||
// SetSignalingConfiguration should be called just once
|
||||
TalkAccount *account = [[NCDatabaseManager sharedInstance] activeAccount];
|
||||
[[NCSettingsController sharedInstance] setSignalingConfigurationForAccountId:account.accountId];
|
||||
[[NCDatabaseManager sharedInstance] updateTalkConfigurationHashForAccountId:account.accountId withHash:configurationHash];
|
||||
[[NCSettingsController sharedInstance] setSignalingConfigurationForAccountId:accountId];
|
||||
[[NCDatabaseManager sharedInstance] updateTalkConfigurationHashForAccountId:accountId withHash:configurationHash];
|
||||
|
||||
[bgTask stopBackgroundTask];
|
||||
}];
|
||||
|
@ -299,9 +298,20 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
|
|||
|
||||
#pragma mark - User Profile
|
||||
|
||||
- (void)getUserProfileWithCompletionBlock:(UpdatedProfileCompletionBlock)block
|
||||
- (void)getUserProfileForAccountId:(NSString *)accountId withCompletionBlock:(UpdatedProfileCompletionBlock)block
|
||||
{
|
||||
[[NCAPIController sharedInstance] getUserProfileForAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSDictionary *userProfile, NSError *error) {
|
||||
TalkAccount *account = [[NCDatabaseManager sharedInstance] talkAccountForAccountId:accountId];
|
||||
|
||||
if (!account) {
|
||||
if (block) {
|
||||
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil];
|
||||
block(error);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
[[NCAPIController sharedInstance] getUserProfileForAccount:account withCompletionBlock:^(NSDictionary *userProfile, NSError *error) {
|
||||
if (!error) {
|
||||
id emailObject = [userProfile objectForKey:kUserProfileEmail];
|
||||
NSString *email = emailObject;
|
||||
|
@ -310,7 +320,10 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
|
|||
}
|
||||
RLMRealm *realm = [RLMRealm defaultRealm];
|
||||
[realm beginWriteTransaction];
|
||||
TalkAccount *managedActiveAccount = [TalkAccount objectsWhere:(@"active = true")].firstObject;
|
||||
|
||||
NSPredicate *query = [NSPredicate predicateWithFormat:@"accountId = %@", account.accountId];
|
||||
TalkAccount *managedActiveAccount = [TalkAccount objectsWithPredicate:query].firstObject;
|
||||
|
||||
managedActiveAccount.userId = [userProfile objectForKey:kUserProfileUserId];
|
||||
// "display-name" is returned by /cloud/user endpoint
|
||||
// change to kUserProfileDisplayName ("displayName") when using /cloud/users/{userId} endpoint
|
||||
|
@ -327,12 +340,18 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
|
|||
managedActiveAccount.twitter = [userProfile objectForKey:kUserProfileTwitter];
|
||||
managedActiveAccount.twitterScope = [userProfile objectForKey:kUserProfileTwitterScope];
|
||||
managedActiveAccount.avatarScope = [userProfile objectForKey:kUserProfileAvatarScope];
|
||||
|
||||
[realm commitWriteTransaction];
|
||||
[[NCAPIController sharedInstance] saveProfileImageForAccount:[[NCDatabaseManager sharedInstance] activeAccount]];
|
||||
if (block) block(nil);
|
||||
[[NCAPIController sharedInstance] saveProfileImageForAccount:account];
|
||||
|
||||
if (block) {
|
||||
block(nil);
|
||||
}
|
||||
} else {
|
||||
NSLog(@"Error while getting the user profile");
|
||||
if (block) block(error);
|
||||
if (block) {
|
||||
block(error);
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
@ -399,16 +418,25 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
|
|||
|
||||
#pragma mark - Signaling Configuration
|
||||
|
||||
- (void)getSignalingConfigurationWithCompletionBlock:(GetSignalingConfigCompletionBlock)block
|
||||
- (void)getSignalingConfigurationForAccountId:(NSString *)accountId withCompletionBlock:(GetSignalingConfigCompletionBlock)block
|
||||
{
|
||||
[[NCAPIController sharedInstance] getSignalingSettingsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSDictionary *settings, NSError *error) {
|
||||
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
||||
TalkAccount *account = [[NCDatabaseManager sharedInstance] talkAccountForAccountId:accountId];
|
||||
|
||||
if (!account) {
|
||||
if (block) {
|
||||
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil];
|
||||
block(error);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
[[NCAPIController sharedInstance] getSignalingSettingsForAccount:account withCompletionBlock:^(NSDictionary *settings, NSError *error) {
|
||||
if (!error) {
|
||||
NSDictionary *signalingConfiguration = [[settings objectForKey:@"ocs"] objectForKey:@"data"];
|
||||
|
||||
if (signalingConfiguration && activeAccount && activeAccount.accountId) {
|
||||
[self->_signalingConfigutations setObject:signalingConfiguration forKey:activeAccount.accountId];
|
||||
if (signalingConfiguration && account && account.accountId) {
|
||||
[self->_signalingConfigutations setObject:signalingConfiguration forKey:account.accountId];
|
||||
|
||||
if (block) {
|
||||
block(nil);
|
||||
|
@ -481,32 +509,44 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
|
|||
|
||||
#pragma mark - Server Capabilities
|
||||
|
||||
- (void)getCapabilitiesWithCompletionBlock:(GetCapabilitiesCompletionBlock)block;
|
||||
- (void)getCapabilitiesForAccountId:(NSString *)accountId withCompletionBlock:(GetCapabilitiesCompletionBlock)block
|
||||
{
|
||||
[[NCAPIController sharedInstance] getServerCapabilitiesForAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSDictionary *serverCapabilities, NSError *error) {
|
||||
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
||||
TalkAccount *account = [[NCDatabaseManager sharedInstance] talkAccountForAccountId:accountId];
|
||||
|
||||
if (!account) {
|
||||
if (block) {
|
||||
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil];
|
||||
block(error);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
[[NCAPIController sharedInstance] getServerCapabilitiesForAccount:account withCompletionBlock:^(NSDictionary *serverCapabilities, NSError *error) {
|
||||
if (!error && [serverCapabilities isKindOfClass:[NSDictionary class]]) {
|
||||
BGTaskHelper *bgTask = [BGTaskHelper startBackgroundTaskWithName:@"NCUpdateCapabilitiesTransaction" expirationHandler:nil];
|
||||
[NCUtils log:@"Start update capabilities transaction"];
|
||||
[[NCDatabaseManager sharedInstance] setServerCapabilities:serverCapabilities forAccountId:activeAccount.accountId];
|
||||
[self checkServerCapabilities];
|
||||
[[NCDatabaseManager sharedInstance] setServerCapabilities:serverCapabilities forAccountId:account.accountId];
|
||||
[self checkServerCapabilitiesForAccount:account];
|
||||
[bgTask stopBackgroundTask];
|
||||
[NCUtils log:@"End update capabilities transaction"];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NCServerCapabilitiesUpdatedNotification
|
||||
object:self
|
||||
userInfo:nil];
|
||||
if (block) block(nil);
|
||||
if (block) {
|
||||
block(nil);
|
||||
}
|
||||
} else {
|
||||
NSLog(@"Error while getting server capabilities");
|
||||
if (block) block(error);
|
||||
if (block) {
|
||||
block(error);
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)checkServerCapabilities
|
||||
- (void)checkServerCapabilitiesForAccount:(TalkAccount *)account
|
||||
{
|
||||
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
||||
ServerCapabilities *serverCapabilities = [[NCDatabaseManager sharedInstance] serverCapabilitiesForAccountId:activeAccount.accountId];
|
||||
ServerCapabilities *serverCapabilities = [[NCDatabaseManager sharedInstance] serverCapabilitiesForAccountId:account.accountId];
|
||||
if (serverCapabilities) {
|
||||
NSArray *talkFeatures = [serverCapabilities.talkCapabilities valueForKey:@"self"];
|
||||
if (!talkFeatures || [talkFeatures count] == 0) {
|
||||
|
|
|
@ -457,7 +457,8 @@
|
|||
[_mainViewController dismissViewControllerAnimated:YES completion:^{
|
||||
[[NCConnectionController sharedInstance] checkAppState];
|
||||
// Get server capabilities again to check if user is allowed to use Nextcloud Talk
|
||||
[[NCSettingsController sharedInstance] getCapabilitiesWithCompletionBlock:nil];
|
||||
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
||||
[[NCSettingsController sharedInstance] getCapabilitiesForAccountId:activeAccount.accountId withCompletionBlock:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
|
@ -468,7 +469,8 @@
|
|||
[_mainViewController dismissViewControllerAnimated:YES completion:^{
|
||||
[[NCConnectionController sharedInstance] checkAppState];
|
||||
// Get server capabilities again to check if user is allowed to use Nextcloud Talk
|
||||
[[NCSettingsController sharedInstance] getCapabilitiesWithCompletionBlock:nil];
|
||||
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
||||
[[NCSettingsController sharedInstance] getCapabilitiesForAccountId:activeAccount.accountId withCompletionBlock:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
|
|
|
@ -200,7 +200,8 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate {
|
|||
// MARK: User Profile
|
||||
|
||||
func refreshUserProfile() {
|
||||
NCSettingsController.sharedInstance().getUserProfile { _ in
|
||||
let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
|
||||
NCSettingsController.sharedInstance().getUserProfile(forAccountId: activeAccount.accountId) { _ in
|
||||
self.tableView.reloadData()
|
||||
}
|
||||
self.getActiveUserStatus()
|
||||
|
@ -268,7 +269,8 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate {
|
|||
// MARK: User phone number
|
||||
|
||||
func checkUserPhoneNumber() {
|
||||
NCSettingsController.sharedInstance().getUserProfile { _ in
|
||||
let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
|
||||
NCSettingsController.sharedInstance().getUserProfile(forAccountId: activeAccount.accountId) { _ in
|
||||
let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
|
||||
if activeAccount.phone.isEmpty {
|
||||
self.presentSetPhoneNumberDialog()
|
||||
|
@ -435,9 +437,11 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate {
|
|||
|
||||
@objc func readStatusValueChanged(_ sender: Any?) {
|
||||
readStatusSwitch.isEnabled = false
|
||||
NCAPIController.sharedInstance().setReadStatusPrivacySettingEnabled(!readStatusSwitch.isOn, for: NCDatabaseManager.sharedInstance().activeAccount()) { error in
|
||||
let account = NCDatabaseManager.sharedInstance().activeAccount()
|
||||
|
||||
NCAPIController.sharedInstance().setReadStatusPrivacySettingEnabled(!readStatusSwitch.isOn, for: account) { error in
|
||||
if error == nil {
|
||||
NCSettingsController.sharedInstance().getCapabilitiesWithCompletionBlock { error in
|
||||
NCSettingsController.sharedInstance().getCapabilitiesForAccountId(account.accountId) { error in
|
||||
if error == nil {
|
||||
self.readStatusSwitch.isEnabled = true
|
||||
self.tableView.reloadData()
|
||||
|
|
|
@ -38,7 +38,7 @@ extension UserProfileTableViewController {
|
|||
}
|
||||
|
||||
func refreshUserProfile() {
|
||||
NCSettingsController.sharedInstance().getUserProfile { _ in
|
||||
NCSettingsController.sharedInstance().getUserProfile(forAccountId: account.accountId) { _ in
|
||||
self.account = NCDatabaseManager.sharedInstance().activeAccount()
|
||||
self.refreshProfileTableView()
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче