Work around some issues when listImages returns <= 1 image.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 5 Sep 2010 21:46:22 +0000 (17:46 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 5 Sep 2010 21:46:22 +0000 (17:46 -0400)
ApertureToAnselExportPlugin/TURAnselKit/TURAnselGallery.m

index 75130d1..445dbda 100644 (file)
         NSArray *params;
         NSArray *order;
 
-//        if ([[anselController valueForKey:@"version"] intValue] == 2) {
-// listImages hasn't been refactored yet in version 2 API
-//        } else {
+        //if ([[anselController valueForKey:@"version"] intValue] == 2) {
+            // listImages hasn't been refactored yet in version 2 API
+        //} else {
             params = [NSArray arrayWithObjects:
                                @"ansel",                                //Scope
                                [NSNumber numberWithInt: _galleryId],    //Gallery Id
                                                kTURAnselAPIParamPerms,
                                                kTURAnselAPIParamThumbnailStyle,
                                                kTURAnselAPIParamFullPath, nil];
-//        }
+        //}
         NSDictionary *response = [anselController callRPCMethod: @"images.listImages"
                                                      withParams: params
                                                       withOrder: order];
         if (response) {
-            [imageList autorelease];
             if ([[anselController valueForKey:@"version"] intValue] == 2) {
                 // images.listImages returns a hash in version 2, not an array
-                imageList = [NSMutableArray arrayWithArray: [[[response objectForKey: (id)kWSMethodInvocationResult] retain] allValues]];
+                // Not sure where the bug is here, PHP/Horde/Cocoa WS, but if
+                // the array returned by listImages only contains a single image,
+                // the image id key is ignored and it's taken as a NSArray object.
+                // This still works since all the methods called on the results
+                // object are shared by both NSDictionary and NSArray.
+                NSArray *results = [response objectForKey: (id)kWSMethodInvocationResult];
+                if (![results count]) {
+                    return imageList;
+                }
+                imageList = [[NSMutableArray arrayWithArray: results] retain];
             } else {
                 imageList = [[response objectForKey: (id)kWSMethodInvocationResult] retain];
             }
-            NSLog(@"listImages: %@", imageList);
         }
     }