Created
October 9, 2019 22:18
-
-
Save shiki/b85daa31ef72d07daf10cd7c430fd85f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --cc Podfile.lock | |
index 0396ee1cef,4c4b941c72..0000000000 | |
--- a/Podfile.lock | |
+++ b/Podfile.lock | |
@@@ -230,11 -230,11 +230,16 @@@ PODS | |
- UIDeviceIdentifier (~> 1.1.4) | |
- WordPressShared (~> 1.8.0) | |
- wpxmlrpc (= 0.8.4) | |
++<<<<<<< HEAD | |
+ - WordPressMocks (0.0.5) | |
+ - WordPressShared (1.8.8-beta.1): | |
++======= | |
+ - WordPressMocks (0.0.6) | |
+ - WordPressShared (1.8.7): | |
++>>>>>>> origin/develop | |
- CocoaLumberjack (~> 3.4) | |
- FormatterKit/TimeIntervalFormatter (= 1.8.2) | |
- - WordPressUI (1.3.5) | |
+ - WordPressUI (1.4-beta.1) | |
- WPMediaPicker (1.4.2) | |
- wpxmlrpc (0.8.4) | |
- yoga (0.60.0-patched.React) | |
@@@ -300,14 -300,14 +305,23 @@@ DEPENDENCIES | |
- SimulatorStatusMagic | |
- Starscream (= 3.0.6) | |
- SVProgressHUD (= 2.2.5) | |
++<<<<<<< HEAD | |
+ - WordPress-Editor-iOS (~> 1.9.0) | |
+ - WordPressAuthenticator (~> 1.9.0) | |
+ - WordPressKit (~> 4.5.0) | |
+ - WordPressMocks (~> 0.0.5) | |
+ - WordPressShared (~> 1.8.8-beta.1) | |
+ - WordPressUI (~> 1.3.5) | |
++======= | |
+ - WordPress-Editor-iOS (~> 1.10.1) | |
+ - WordPressAuthenticator (~> 1.10.1-beta.1) | |
+ - WordPressKit (~> 4.5.1) | |
+ - WordPressMocks (~> 0.0.6) | |
+ - WordPressShared (~> 1.8.7) | |
+ - WordPressUI (~> 1.4-beta.1) | |
++>>>>>>> origin/develop | |
- WPMediaPicker (~> 1.4.2) | |
- - yoga (from `https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/v1.13.0/react-native-gutenberg-bridge/third-party-podspecs/yoga.podspec.json`) | |
+ - yoga (from `https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/0d13e85fcbd70e6a1ccff18c6eb897550a307961/react-native-gutenberg-bridge/third-party-podspecs/yoga.podspec.json`) | |
- ZendeskSDK (from `https://github.com/zendesk/zendesk_sdk_ios`, tag `3.0.1-swift5.1-GM`) | |
- ZIPFoundation (~> 0.9.8) | |
@@@ -490,19 -490,19 +504,33 @@@ SPEC CHECKSUMS | |
Starscream: ef3ece99d765eeccb67de105bfa143f929026cf5 | |
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6 | |
UIDeviceIdentifier: 8f8a24b257a4d978c8d40ad1e7355b944ffbfa8c | |
++<<<<<<< HEAD | |
+ WordPress-Aztec-iOS: e58c7ab55b0bae53418a705876093fed314b6586 | |
+ WordPress-Editor-iOS: 36114a1e155b0696939dba80989652c185e91e01 | |
+ WordPressAuthenticator: 4a047f354ff6486b2b446a2c4d517611800eed48 | |
+ WordPressKit: 87ba4cce3f5269e26a09568a749ec1b8b2ba2267 | |
+ WordPressMocks: d8088f718439556ff3856d5881aef581740cd26a | |
+ WordPressShared: 43343deb20fa5a094d31b18646986a1bd1cbc0d8 | |
+ WordPressUI: 1b006c7440e85e724b9773c7ebe3a2e783f70941 | |
++======= | |
+ WordPress-Aztec-iOS: 419ebf7a333fe147da33e4754978f20a5fd08a86 | |
+ WordPress-Editor-iOS: b3ec2b9484c76ad30918ed5dfe87bbbf9fa9de7d | |
+ WordPressAuthenticator: f88358bd25edacfff23d78bb2aef5c3d5d176cbd | |
+ WordPressKit: c35230114bbd380d63250b6d9a43337c29266c9b | |
+ WordPressMocks: 5913bd04586a360212e07a8ccbcb36068d4425a3 | |
+ WordPressShared: 09cf184caa614835f5811e8609227165201e6d3e | |
+ WordPressUI: 35b144885c8e5817ba6874b68accc200bda61ee1 | |
++>>>>>>> origin/develop | |
WPMediaPicker: 1897f312c7b41114ffd239fb782431ae602134a1 | |
wpxmlrpc: 6ba55c773cfa27083ae4a2173e69b19f46da98e2 | |
yoga: 4e71c9a33abf45ba55af55ae9cbc86f4234bb2a9 | |
ZendeskSDK: 787414f9240ee6ef8cfe4ea0f00e8b4d01d2d264 | |
ZIPFoundation: 89df685c971926b0323087952320bdfee9f0b6ef | |
++<<<<<<< HEAD | |
+PODFILE CHECKSUM: 4c28b67ad9b6a69cbd107e315c64d20ce36ac095 | |
++======= | |
+ PODFILE CHECKSUM: 3dc9b3e36e4c8322f602d3582db24ce521fd60e4 | |
++>>>>>>> origin/develop | |
COCOAPODS: 1.7.5 | |
diff --cc WordPress/Classes/Services/PostCoordinator.swift | |
index e6ade0f97e,233503ed25..0000000000 | |
--- a/WordPress/Classes/Services/PostCoordinator.swift | |
+++ b/WordPress/Classes/Services/PostCoordinator.swift | |
@@@ -38,78 -35,16 +38,82 @@@ class PostCoordinator: NSObject | |
self.mainService = mainService ?? PostService(managedObjectContext: mainContext) | |
self.backgroundService = backgroundService ?? PostService(managedObjectContext: backgroundContext) | |
self.mediaCoordinator = mediaCoordinator ?? MediaCoordinator.shared | |
+ self.failedPostsFetcher = failedPostsFetcher ?? FailedPostsFetcher(mainContext) | |
+ } | |
+ | |
++<<<<<<< HEAD | |
+ // MARK: - Uploading Media | |
+ | |
+ /// Uploads all local media for the post, and returns `true` if it was possible to start uploads for all | |
+ /// of the existing media for the post. | |
+ /// | |
+ /// - Parameters: | |
+ /// - post: the post to get the media to upload from. | |
+ /// - automatedRetry: true if this call is the result of an automated upload-retry attempt. | |
+ /// | |
+ /// - Returns: `true` if all media in the post is uploading or was uploaded, `false` otherwise. | |
+ /// | |
+ private func uploadMedia(for post: AbstractPost, automatedRetry: Bool = false) -> Bool { | |
+ let mediaService = MediaService(managedObjectContext: backgroundContext) | |
+ let failedMedia: [Media] = post.media.filter({ $0.remoteStatus == .failed }) | |
+ let mediasToUpload: [Media] | |
+ | |
+ if automatedRetry { | |
+ mediasToUpload = mediaService.failedMediaForUpload(in: post, automatedRetry: automatedRetry) | |
+ } else { | |
+ mediasToUpload = failedMedia | |
+ } | |
+ | |
+ mediasToUpload.forEach { mediaObject in | |
+ mediaCoordinator.retryMedia(mediaObject, automatedRetry: automatedRetry) | |
+ } | |
+ | |
+ let isPushingAllPendingMedia = mediasToUpload.count == failedMedia.count | |
+ return isPushingAllPendingMedia | |
+ } | |
+ | |
+ func save(_ postToSave: AbstractPost, automatedRetry: Bool = false) { | |
+ prepareToSave(postToSave, automatedRetry: automatedRetry) { post in | |
+ self.upload(post: post) | |
+ } | |
+ } | |
+ | |
+ func autoSave(_ postToSave: AbstractPost, automatedRetry: Bool = false) { | |
+ prepareToSave(postToSave, automatedRetry: automatedRetry) { post in | |
+ self.mainService.autoSave(post, success: { uploadedPost, _ in }, failure: { _ in }) | |
+ } | |
+ } | |
+ | |
+ func publish(_ post: AbstractPost) { | |
+ if post.status == .draft { | |
+ post.status = .publish | |
+ } | |
+ | |
+ if post.status != .scheduled { | |
+ post.date_created_gmt = Date() | |
+ } | |
+ | |
+ post.shouldAttemptAutoUpload = true | |
+ | |
+ save(post) | |
} | |
+ func moveToDraft(_ post: AbstractPost) { | |
+ post.status = .draft | |
+ save(post) | |
+ } | |
++======= | |
+ // MARK: - Misc | |
++>>>>>>> origin/develop | |
- /// Saves the post to both the local database and the server if available. | |
- /// If media is still uploading it keeps track of the ongoing media operations and updates the post content when they finish | |
+ /// If media is still uploading it keeps track of the ongoing media operations and updates the post content when they finish. | |
+ /// Then, it calls the completion block with the post ready to be saved/uploaded. | |
/// | |
/// - Parameter post: the post to save | |
+ /// - Parameter automatedRetry: if this is an automated retry, without user intervenction | |
+ /// - Parameter then: a block to perform after post is ready to be saved | |
/// | |
- func save(_ postToSave: AbstractPost, automatedRetry: Bool = false) { | |
+ private func prepareToSave(_ postToSave: AbstractPost, automatedRetry: Bool = false, then completion: @escaping (AbstractPost) -> ()) { | |
var post = postToSave | |
if postToSave.isRevision() && !postToSave.hasRemote(), let originalPost = postToSave.original { | |
@@@ -118,9 -53,7 +122,13 @@@ | |
post.deleteRevision() | |
} | |
++<<<<<<< HEAD | |
+ post.autoUploadAttemptsCount = NSNumber(value: automatedRetry ? post.autoUploadAttemptsCount.intValue + 1 : 0) | |
+ | |
+ guard uploadMedia(for: post, automatedRetry: automatedRetry) else { | |
++======= | |
+ guard mediaCoordinator.uploadMedia(for: post, automatedRetry: automatedRetry) else { | |
++>>>>>>> origin/develop | |
change(post: post, status: .failed) | |
return | |
} | |
@@@ -314,34 -247,24 +322,48 @@@ | |
} | |
private func change(post: AbstractPost, status: AbstractPostRemoteStatus) { | |
++<<<<<<< HEAD | |
+ post.managedObjectContext?.perform { | |
+ post.remoteStatus = status | |
+ try? post.managedObjectContext?.save() | |
++======= | |
+ guard let context = post.managedObjectContext else { | |
+ return | |
+ } | |
+ context.perform { | |
+ if status == .failed { | |
+ self.mainService.markAsFailedAndDraftIfNeeded(post: post) | |
+ } else { | |
+ post.remoteStatus = status | |
+ } | |
+ | |
+ ContextManager.sharedInstance().saveContextAndWait(context) | |
++>>>>>>> origin/develop | |
} | |
} | |
+ | |
+ /// Cancel active and pending automatic uploads of the post. | |
+ func cancelAutoUploadOf(_ post: AbstractPost) { | |
+ cancelAnyPendingSaveOf(post: post) | |
+ | |
+ post.shouldAttemptAutoUpload = false | |
+ | |
+ let moc = post.managedObjectContext | |
+ | |
+ moc?.perform { | |
+ try? moc?.save() | |
+ } | |
+ | |
+ let notice = Notice(title: PostAutoUploadMessages.cancelMessage(for: post.status), message: "") | |
+ ActionDispatcher.dispatch(NoticeAction.post(notice)) | |
+ } | |
} | |
+// MARK: - Automatic Uploads | |
+ | |
extension PostCoordinator: Uploader { | |
func resume() { | |
- mainService.getFailedPosts { [weak self] posts in | |
+ failedPostsFetcher.postsAndRetryActions { [weak self] postsAndActions in | |
guard let self = self else { | |
return | |
} | |
diff --cc WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift | |
index 04a406c82a,3cbb2bfc37..0000000000 | |
--- a/WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift | |
+++ b/WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift | |
@@@ -33,7 -33,7 +33,11 @@@ extension PostEditor where Self: UIView | |
dismissWhenDone: Bool, | |
analyticsStat: WPAnalyticsStat?) { | |
++<<<<<<< HEAD | |
+ mapUIContentToPostAndSave(immediate: true) | |
++======= | |
+ MediaCoordinator.shared.uploadMedia(for: post) | |
++>>>>>>> origin/develop | |
// Cancel publishing if media is currently being uploaded | |
if !action.isAsync && !dismissWhenDone && isUploadingMedia { | |
diff --cc WordPress/WordPress.xcodeproj/project.pbxproj | |
index ee13a544c7,89c955013e..0000000000 | |
--- a/WordPress/WordPress.xcodeproj/project.pbxproj | |
+++ b/WordPress/WordPress.xcodeproj/project.pbxproj | |
@@@ -5726,7 -5683,7 +5728,11 @@@ | |
570BFD8A22823D7B007859A8 /* PostActionSheet.swift */, | |
570265142298921800F2214C /* PostListTableViewHandler.swift */, | |
57047A4E22A961BC00B461DF /* PostSearchHeader.swift */, | |
++<<<<<<< HEAD | |
+ 8B8FE8562343952B00F9AD2E /* PostAutoUploadMessages.swift */, | |
++======= | |
+ 7E92A1FA233CB1B7006D281B /* Autosaver.swift */, | |
++>>>>>>> origin/develop | |
); | |
name = Utils; | |
sourceTree = "<group>"; | |
diff --cc WordPress/WordPressTest/PostBuilder.swift | |
index 1847b89020,ad5a9c4526..0000000000 | |
--- a/WordPress/WordPressTest/PostBuilder.swift | |
+++ b/WordPress/WordPressTest/PostBuilder.swift | |
@@@ -3,13 -3,28 +3,35 @@@ import Foundatio | |
@testable import WordPress | |
class PostBuilder { | |
+ private let post: Post | |
- var post: Post! | |
+ init(_ context: NSManagedObjectContext = PostBuilder.setUpInMemoryManagedObjectContext()) { | |
+ post = Post(context: context) | |
++<<<<<<< HEAD | |
+ // Non-null Core Data properties | |
+ post.blog = BlogBuilder(context).build() | |
++======= | |
+ private static func buildPost(context: NSManagedObjectContext) -> Post { | |
+ let blog = NSEntityDescription.insertNewObject(forEntityName: Blog.entityName(), into: context) as! Blog | |
+ blog.xmlrpc = "http://example.com/xmlrpc.php" | |
+ blog.url = "http://example.com" | |
+ blog.username = "test" | |
+ blog.password = "test" | |
+ | |
+ let post = NSEntityDescription.insertNewObject(forEntityName: Post.entityName(), into: context) as! Post | |
+ post.blog = blog | |
+ | |
+ return post | |
+ } | |
+ | |
+ init() { | |
+ post = PostBuilder.buildPost(context: setUpInMemoryManagedObjectContext()) | |
+ } | |
+ | |
+ init(_ context: NSManagedObjectContext) { | |
+ post = PostBuilder.buildPost(context: context) | |
++>>>>>>> origin/develop | |
} | |
func published() -> PostBuilder { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment