Conversation
|
|
||
| [mediaObjects enumerateObjectsUsingBlock:^(Media *media, NSUInteger idx, BOOL *stop) { | ||
| dispatch_group_enter(group); | ||
| [self deleteMedia:media success:^{ |
There was a problem hiding this comment.
This looks like case to reconsider implementing back support for batch calls in the REST API . :)
There was a problem hiding this comment.
Did we have it previously?
There was a problem hiding this comment.
Yes we did, it was removed when the API code was updated to swift and URLSession.
Maybe add a issue for us to have a look in the future.
|
One scenario:
It didn't crash! But, it would be cool if we could reliably pop the detail view. I also imagine it would crash if proceeding on to editing details. |
|
Very similar to the case in #6858 (comment)
|
|
Looks like the Cancel bar button item stays enabled during the deletion of items, as does the trash button. |
|
|
||
| [self.wordPressComRestApi POST:requestUrl | ||
| parameters:nil | ||
| success:^(id responseObject, NSHTTPURLResponse *response) { |
There was a problem hiding this comment.
Should we check the API response for "status": "deleted" as seen on https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/media/%24media_ID/delete/?
There was a problem hiding this comment.
Our delete post code doesn't seem to check the response, but I guess it couldn't hurt to do so. I've updated the remotes code to do this. I wasn't really sure what sort of error to pass if the response wasn't what we expected. Any suggestions? Is what I've done okay?
There was a problem hiding this comment.
While a bit painful, probably best go ahead and knock it out now with something like https://github.com/wordpress-mobile/WordPress-iOS/blob/develop/WordPress/Classes/Services/MediaService.m#L339 and a message of "Something went wrong, please try again" or the like.
| NSParameterAssert([media.mediaID longLongValue] > 0); | ||
|
|
||
| NSArray *parameters = [self XMLRPCArgumentsWithExtra:media.mediaID]; | ||
| [self.api callMethod:@"wp.deleteFile" |
There was a problem hiding this comment.
Hmm, couldn't find any documentation for this endpoint, was wondering if it also had some sort of success result to parse for the response.
There was a problem hiding this comment.
It's actually just an alias for wp.deletePost, which returns true if successful. I guess we should check that value.
| success:(nullable void (^)())success | ||
| failure:(nullable void (^)(NSError * _Nonnull error))failure; | ||
|
|
||
| /** |
| @param progress a block that will be invoked after each media item is deleted successfully | ||
| @param success a block that will be invoked when the media deletion finished with success | ||
| @param failure a block that will be invoked when there is an error. | ||
| */ |
There was a problem hiding this comment.
We could be a bit more Swifty in Obj-C and also name this method deleteMedia with the different argument types from (void)deleteMedia:(nonnull Media *)media 😃
Also a : alignment issue with the declaration.
There was a problem hiding this comment.
I went with deleteMultiple... to match the existing updateMultiple... method. Perhaps we could revisit this in the future (convert the whole lot to Swift? 😁)
| // Check the media hasn't been deleted whilst we were loading. | ||
| if (!media || media.isDeleted) { | ||
| if (success) { | ||
| success(nil); |
There was a problem hiding this comment.
Looks like this would go ahead against the _Nonnull in success:(nullable void (^)(UIImage * _Nonnull image))success.
There was a problem hiding this comment.
I've adjusted this to return a new, empty UIImage. Alternative would be to change the method signature, but I think it's probably best to leave that as-is?
|
|
||
| @objc private func trashTapped() { | ||
| let alertController = UIAlertController(title: nil, | ||
| message: NSLocalizedString("Are you sure you want to permanently delete these items?", comment: "Message prompting the user to confirm that they want to permanently delete a group of media items."), preferredStyle: .alert) |
There was a problem hiding this comment.
Looking at Calypso, we should also provide a singular form of this text when only selecting one item and pressing delete. Are you sure you want to permanently delete this item?
|
Thanks for the review, @kurzee, and for catching those edge cases! I think I've covered them all now, except for:
I'm not quite sure I understand. You mean in the media library view, when the HUD is visible? I just tested it here and I wasn't able to tap those items. Care to take another look? |
|
For this one #6858 (comment) I was able to reproduce, however only the "Cancel" left bar button item remained enabled, while the trash button disable, both were visible so the editing state is still enabled. Note: I guess this is expected though since we had entered the editing state. |
All good on this one. |
|
Everything checks out, just the errors comment, which could be separate if you want or tackled with refactoring later. Also, conflict on Podfile.lock.
|
|
Thanks @kurzee! As discussed, staying in Edit mode is intentional and we can improve the errors later if we need to :) |
This PR adds the ability to delete media items from the Media Library. There are two ways to do it:
Note: This PR currently references a MediaPicker-iOS branch which contains a couple of necessary tweaks. Once that's approved, I'll push out a new pod version and update this branch accordingly.
To test:
Needs review: @kurzee