Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Pause media upload when internet connection unavailable #22282

Merged
merged 11 commits into from
Jan 10, 2024
2 changes: 1 addition & 1 deletion Gutenberg/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#
# LOCAL_GUTENBERG=../my-gutenberg-fork bundle exec pod install
ref:
tag: v1.110.0
tag: v1.111.0-alpha1
github_org: wordpress-mobile
repo_name: gutenberg-mobile
6 changes: 3 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ DEPENDENCIES:
- FSInteractiveMap (from `https://github.com/wordpress-mobile/FSInteractiveMap.git`, tag `0.2.0`)
- Gifu (= 3.3.1)
- Gridicons (~> 1.2)
- Gutenberg (from `https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.110.0.podspec`)
- Gutenberg (from `https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.111.0-alpha1.podspec`)
- JTAppleCalendar (~> 8.0.5)
- Kanvas (~> 1.4.4)
- MediaEditor (>= 1.2.2, ~> 1.2)
Expand Down Expand Up @@ -176,7 +176,7 @@ EXTERNAL SOURCES:
:git: https://github.com/wordpress-mobile/FSInteractiveMap.git
:tag: 0.2.0
Gutenberg:
:podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.110.0.podspec
:podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.111.0-alpha1.podspec

CHECKOUT OPTIONS:
FSInteractiveMap:
Expand All @@ -195,7 +195,7 @@ SPEC CHECKSUMS:
FSInteractiveMap: a396f610f48b76cb540baa87139d056429abda86
Gifu: 416d4e38c4c2fed012f019e0a1d3ffcb58e5b842
Gridicons: 4455b9f366960121430e45997e32112ae49ffe1d
Gutenberg: 0e64ef7d9c46ba0a681c82f5969622f3db9bf033
Gutenberg: 521e482a023de3559dd78da37a3b0d993ac3fe40
JTAppleCalendar: 16c6501b22cb27520372c28b0a2e0b12c8d0cd73
Kanvas: cc027f8058de881a4ae2b5aa5f05037b6d054d08
MediaEditor: d08314cfcbfac74361071a306b4bc3a39b3356ae
Expand Down
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
24.1
-----
* [**] Image block media uploads display a custom error message when there is no internet connection [https://github.com/wordpress-mobile/WordPress-iOS/pull/22282]
* [*] Allow trashing draft and scheduled posts with no confirmation [#22337]
* [*] Add "Share" action to the site context menu [#22298]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class GutenbergMediaInserterHelper: NSObject {
for media in post.media {
if media.remoteStatus == .failed {
gutenberg.mediaUploadUpdate(id: media.gutenbergUploadID, state: .uploading, progress: 0, url: media.absoluteThumbnailLocalURL, serverID: nil)
gutenberg.mediaUploadUpdate(id: media.gutenbergUploadID, state: .failed, progress: 0, url: nil, serverID: nil)
let finalState: Gutenberg.MediaUploadState = ReachabilityUtils.isInternetReachable() ? .failed : .paused
gutenberg.mediaUploadUpdate(id: media.gutenbergUploadID, state: finalState, progress: 0, url: nil, serverID: nil)
}
}
}
Expand Down Expand Up @@ -174,11 +175,12 @@ class GutenbergMediaInserterHelper: NSObject {
switch state {
case .processing:
gutenberg.mediaUploadUpdate(id: mediaUploadID, state: .uploading, progress: 0, url: nil, serverID: nil)
case .thumbnailReady(let url) where ReachabilityUtils.isInternetReachable() && media.remoteStatus == .failed:
gutenberg.mediaUploadUpdate(id: mediaUploadID, state: .failed, progress: 0, url: url, serverID: nil)
case .thumbnailReady(let url) where !ReachabilityUtils.isInternetReachable() && media.remoteStatus == .failed:
// The progress value passed is ignored by the editor, allowing the UI to retain the last known progress before pausing
gutenberg.mediaUploadUpdate(id: mediaUploadID, state: .paused, progress: 0, url: url, serverID: nil)
case .thumbnailReady(let url):
guard ReachabilityUtils.isInternetReachable() && media.remoteStatus != .failed else {
gutenberg.mediaUploadUpdate(id: mediaUploadID, state: .failed, progress: 0, url: url, serverID: nil)
return
}
gutenberg.mediaUploadUpdate(id: mediaUploadID, state: .uploading, progress: 0.20, url: url, serverID: nil)
break
case .uploading:
Expand Down Expand Up @@ -221,11 +223,17 @@ class GutenbergMediaInserterHelper: NSObject {
gutenberg.mediaUploadUpdate(id: mediaUploadID, state: .succeeded, progress: 1, url: url, serverID: mediaServerID)
}
case .failed(let error):
if error.code == NSURLErrorCancelled {
switch error.code {
case NSURLErrorCancelled:
gutenberg.mediaUploadUpdate(id: mediaUploadID, state: .reset, progress: 0, url: nil, serverID: nil)
return
case NSURLErrorNetworkConnectionLost: fallthrough
case NSURLErrorNotConnectedToInternet: fallthrough
case NSURLErrorTimedOut where !ReachabilityUtils.isInternetReachable():
// The progress value passed is ignored by the editor, allowing the UI to retain the last known progress before pausing
gutenberg.mediaUploadUpdate(id: mediaUploadID, state: .paused, progress: 0, url: nil, serverID: nil)
default:
gutenberg.mediaUploadUpdate(id: mediaUploadID, state: .failed, progress: 0, url: nil, serverID: nil)
}
gutenberg.mediaUploadUpdate(id: mediaUploadID, state: .failed, progress: 0, url: nil, serverID: nil)
case .progress(let value):
gutenberg.mediaUploadUpdate(id: mediaUploadID, state: .uploading, progress: Float(value), url: nil, serverID: nil)
}
Expand Down