浏览代码

UserProfile

Marino Faggiana 8 年之前
父节点
当前提交
c51c91c564

+ 2 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.m

@@ -1441,6 +1441,8 @@
                 userProfile.address = [datas valueForKey:@"address"];
                 userProfile.displayName = [datas valueForKey:@"displayname"];
                 userProfile.email = [datas valueForKey:@"email"];
+                if ([userProfile.email isKindOfClass:[NSNull class]])
+                    userProfile.email = @"";
                 userProfile.enabled = [[datas valueForKey:@"enabled"] boolValue];
                 userProfile.id = [datas valueForKey:@"id"];
                 userProfile.phone = [datas valueForKey:@"phone"];

+ 3 - 0
iOSClient/FileSystem/CCCoreData.h

@@ -32,6 +32,7 @@
 #import "CCUtility.h"
 #import "CCExifGeo.h"
 #import "CCGraphics.h"
+#import "OCUserProfile.h"
 
 #import "TableAccount+CoreDataClass.h"
 #import "TableCertificates+CoreDataClass.h"
@@ -91,6 +92,8 @@
 + (void)setCameraUploadFolderPath:(NSString *)pathName activeUrl:(NSString *)activeUrl activeAccount:(NSString *)activeAccount;
 + (void)setCameraUploadSaveAlbum:(BOOL)saveAlbum activeAccount:(NSString *)activeAccount;
 
++ (void)setUserProfileActiveAccount:(NSString *)activeAccount userProfile:(OCUserProfile *)userProfile;
+
 // ===== Certificates =====
 
 + (void)addCertificate:(NSString *)certificateLocation;

+ 25 - 0
iOSClient/FileSystem/CCCoreData.m

@@ -501,6 +501,31 @@
     }];
 }
 
++ (void)setUserProfileActiveAccount:(NSString *)activeAccount userProfile:(OCUserProfile *)userProfile
+{
+    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
+        
+        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@)", activeAccount];
+        TableAccount *record = [TableAccount MR_findFirstWithPredicate:predicate inContext:localContext];
+        
+        if (record) {
+            record.enabled = [NSNumber numberWithBool:userProfile.enabled];
+            record.address = userProfile.address;
+            record.displayName = userProfile.displayName;
+            record.email = userProfile.email;
+            record.phone = userProfile.phone;
+            record.twitter = userProfile.twitter;
+            record.webpage = userProfile.webpage;
+            
+            record.quota = [NSNumber numberWithDouble:userProfile.quota];
+            record.quotaFree = [NSNumber numberWithDouble:userProfile.quotaFree];
+            record.quotaRelative = [NSNumber numberWithDouble:userProfile.quotaRelative];
+            record.quotaTotal = [NSNumber numberWithDouble:userProfile.quotaTotal];
+            record.quotaUsed = [NSNumber numberWithDouble:userProfile.quotaUsed];
+        }
+    }];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Certificates =====
 #pragma --------------------------------------------------------------------------------------------

+ 5 - 2
iOSClient/Main/CCMain.m

@@ -1115,6 +1115,11 @@
 #pragma mark ==== Request Server  ====
 #pragma --------------------------------------------------------------------------------------------
 
+- (void)getUserProfileSuccess:(CCMetadataNet *)metadataNet userProfile:(OCUserProfile *)userProfile
+{
+    [CCCoreData setUserProfileActiveAccount:metadataNet.account userProfile:userProfile];
+}
+
 - (void)getCapabilitiesOfServerSuccess:(OCCapabilities *)capabilities
 {
     app.capabilities = capabilities;
@@ -1166,8 +1171,6 @@
     metadataNet.selector = selectorReadFileQuota;
     metadataNet.serverUrl = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl];
     [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-    
-    
 }
 
 #pragma --------------------------------------------------------------------------------------------