Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ target 'WordPress' do
## Gutenberg (React Native)
## =====================
##
gutenberg :tag => 'v1.47.0'
gutenberg :tag => 'v1.47.2'

## Third party libraries
## =====================
Expand Down
174 changes: 87 additions & 87 deletions Podfile.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
16.9
-----

16.8.1
-----

* [**] Stories: Fixed an issue which could remove content from a post when a new Story block was edited. [#16059]

16.8
-----
Expand Down
6 changes: 3 additions & 3 deletions WordPress/Classes/Services/Stories/CameraHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class CameraHandler: CameraControllerDelegate {

private func endEditing(editor: StoryEditor, onDismiss: @escaping () -> Void) {
showDiscardAlert(on: editor.topmostPresentedViewController) {
editor.cancelEditing()
if editor.presentedViewController is GutenbergViewController == false {
if editor.presentingViewController is AztecNavigationController == false {
editor.cancelEditing()
editor.post.managedObjectContext?.delete(editor.post)
onDismiss()
}
onDismiss()
}
}

Expand Down
48 changes: 20 additions & 28 deletions WordPress/Classes/Services/Stories/StoryEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,22 @@ class StoryEditor: CameraController {
case unsupportedDevice
}

typealias Results = Result<AbstractPost, PostCoordinator.SavingError>
typealias UpdateResult = Result<String, PostCoordinator.SavingError>
typealias UploadResult = Result<Void, PostCoordinator.SavingError>

static func editor(blog: Blog,
context: NSManagedObjectContext,
updated: @escaping (Results) -> Void,
uploaded: @escaping (Results) -> Void) throws -> StoryEditor {
updated: @escaping (UpdateResult) -> Void,
uploaded: @escaping (UploadResult) -> Void) throws -> StoryEditor {
let post = PostService(managedObjectContext: context).createDraftPost(for: blog)
return try editor(post: post, mediaFiles: nil, publishOnCompletion: true, updated: updated, uploaded: uploaded)
}

static func editor(post: AbstractPost,
mediaFiles: [MediaFile]?,
publishOnCompletion: Bool = false,
updated: @escaping (Results) -> Void,
uploaded: @escaping (Results) -> Void) throws -> StoryEditor {
updated: @escaping (UpdateResult) -> Void,
uploaded: @escaping (UploadResult) -> Void) throws -> StoryEditor {

guard !UIDevice.isPad() else {
throw EditorCreationError.unsupportedDevice
Expand Down Expand Up @@ -138,8 +139,8 @@ class StoryEditor: CameraController {
tagCollection: UIView?,
mediaFiles: [MediaFile]?,
publishOnCompletion: Bool,
updated: @escaping (Results) -> Void,
uploaded: @escaping (Results) -> Void
updated: @escaping (UpdateResult) -> Void,
uploaded: @escaping (UploadResult) -> Void
) {
self.post = post
self.onClose = onClose
Expand Down Expand Up @@ -184,32 +185,23 @@ class StoryEditor: CameraController {
guard let self = self else { return }

let uploads: (String, [Media])? = try? self.poster?.upload(mediaItems: postMedia, post: post, completion: { post in
uploaded(post)
uploaded(.success(()))
})

if let firstMediaFile = mediaFiles?.first {
let processor = GutenbergBlockProcessor(for: "wp:jetpack/story", replacer: { block in
let mediaFiles = block.attributes["mediaFiles"] as? [[String: Any]]
if let mediaFile = mediaFiles?.first, mediaFile["url"] as? String == firstMediaFile.url {
return uploads?.0
} else {
return nil
}
})
post.content = processor.process(post.content ?? "")
} else {
post.content = uploads?.0
}

do {
try post.managedObjectContext?.save()
} catch let error {
assertionFailure("Failed to save post during story upload: \(error)")
}
let content = uploads?.0 ?? ""

updated(.success(post))
updated(.success(content))

if publishOnCompletion {
// Replace the contents if we are publishing a new post
post.content = content

do {
try post.managedObjectContext?.save()
} catch let error {
assertionFailure("Failed to save post during story update: \(error)")
}

self.publishPost(action: .publish, dismissWhenDone: true, analyticsStat:
.editorPublishedPost)
} else {
Expand Down
9 changes: 8 additions & 1 deletion WordPress/Classes/Services/Stories/StoryPoster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ struct MediaFile: Codable {
}

init(dictionary: [String: Any]) throws {
// We must handle both possible types because the Gutenberg `replaceBlock` method seems to be changing the type of this field.
let id: String
do {
id = try dictionary.value(key: CodingKeys.id.stringValue, type: NSNumber.self).stringValue
} catch {
id = try dictionary.value(key: CodingKeys.id.stringValue, type: String.self)
}
self.init(alt: try dictionary.value(key: CodingKeys.alt.stringValue, type: String.self),
caption: try dictionary.value(key: CodingKeys.caption.stringValue, type: String.self),
id: try dictionary.value(key: CodingKeys.id.stringValue, type: String.self),
id: id,
link: try dictionary.value(key: CodingKeys.link.stringValue, type: String.self),
mime: try dictionary.value(key: CodingKeys.mime.stringValue, type: String.self),
type: try dictionary.value(key: CodingKeys.type.stringValue, type: String.self),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ extension GutenbergViewController: GutenbergBridgeDelegate {
}

do {
try showEditor(files: files)
try showEditor(files: files, blockID: blockId)
} catch let error {
switch error {
case StoryEditor.EditorCreationError.unsupportedDevice:
Expand All @@ -701,31 +701,22 @@ extension GutenbergViewController: GutenbergBridgeDelegate {
}
}

func showEditor(files: [MediaFile]) throws {
func showEditor(files: [MediaFile], blockID: String) throws {
storyEditor = try StoryEditor.editor(post: post, mediaFiles: files, publishOnCompletion: false, updated: { [weak self] result in
switch result {
case .success:
case .success(let content):
self?.gutenberg.replace(blockID: blockID, content: content)
self?.dismiss(animated: true, completion: nil)
case .failure(let error):
self?.dismiss(animated: true, completion: nil)
let controller = UIAlertController(title: "Failed to create story", message: "Error: \(error)", preferredStyle: .alert)
let dismiss = UIAlertAction(title: "Dismiss", style: .default) { _ in
controller.dismiss(animated: true, completion: nil)
}
controller.addAction(dismiss)
self?.present(controller, animated: true, completion: nil)
DDLogError("Failed to update story: \(error)")
}
}, uploaded: { [weak self] result in
}, uploaded: { result in
switch result {
case .success(let post):
self?.setHTML(post.content ?? "")
case .success:
break // Posts will be updated when the MediaFilesProcessor receives upload events
case .failure(let error):
let controller = UIAlertController(title: "Failed to create story", message: "Error: \(error)", preferredStyle: .alert)
let dismiss = UIAlertAction(title: "Dismiss", style: .default) { _ in
controller.dismiss(animated: true, completion: nil)
}
controller.addAction(dismiss)
self?.present(controller, animated: true, completion: nil)
DDLogError("Failed to upload story: \(error)")
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ extension WPTabBarController {
break
case .failure(let error):
self?.dismiss(animated: true, completion: nil)
let controller = UIAlertController(title: "Failed to create story", message: "Error: \(error)", preferredStyle: .alert)
let dismiss = UIAlertAction(title: "Dismiss", style: .default) { _ in
controller.dismiss(animated: true, completion: nil)
}
controller.addAction(dismiss)
self?.present(controller, animated: true, completion: nil)
DDLogError("Failed to create story: \(error)")
}
})

Expand Down