-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix upload notification not shown on retry #9956
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for diving into this @malinajirka 🙇
Good call on adding what was missing in order to make the notification being shown 👍
While reviewing this, I found another couple problems, which are not strictly related to this PR but may be quick to solve.
Problem A: with Posts with media (in particular, Aztec posts with media) - it is indeed a bit tricky, as also some things changed since the gradual introduction of Gutenberg that made things slip a bit.
So, the problem actually started with the introduction of hardcoding isAztecEnabled
and isGutenbergEnabled
to true
in #9208, given the following condition would never be met:
boolean processWithAztec =
AppPrefs.isAztecEditorEnabled() && !AppPrefs.isGutenbergEditorEnabled()
&& !postHasGutenbergBlocks;
(given both return true
, you can't have isAztecEnabled()
and !isGutenbergEnabled()
at the same time).
This in turn made the flag being passed to retryUpload()
to be false
, and thus this part of code wouldn't be run: https://github.com/wordpress-mobile/WordPress-Android/blob/develop/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java#L751-L753
This effectively means the Post wouldn't get registered for the upload, and media (if the Post contained failed media) wouldn't get retried.
The solution to this would be to just remove the isAztecEnabled()
and isGutenbergEnabled
calls and replace the flag check with this when calling retryUpload()
:
boolean postHasGutenbergBlocks = PostUtils.contentContainsGutenbergBlocks(post.getContent());
retryUpload(post, !postHasGutenbergBlocks);
Re: the following:
I've removed this line
mPostUploadNotifier.removePostInfoFromForegroundNotificationData(post, mediaToRetry);
but tbh I'm not sure what was the initial purpose of the line. I haven't find any reason why we need to invoke it on this place. If I keep it there, the upload notification will always show "1 post remaining" even when I invoke retry on three posts.
I think the reason why it was there is because the retryUpload() method was mostly there to implement the "RETRY" button on a Notification (or on the Posts list itself). Apparently we haven't tested retrying more than one Post at once, hence the defect of assuming we could call mPostUploadNotifier.removePostInfoFromForegroundNotificationData()
there in that place.
I've locally tried and made a change in PostUploadHandler
and added a proper call to removePostInfoFromForegroundNotification
to adjust the sNotificationData
data in the place where an error is captured, as that's a more proper place to handle it, and it seemed to work well.
If you're ok with these changes, feel free to apply them - I prepared a patch where you can see them / you can also download the file and apply it to your branch if you think they're good (use git apply mario.patch
on the command line to make the modifs happen): https://gist.github.com/mzorz/33899b7293e796098d317d3b7ecd1eca
Following is a list of other two things that I found but don't have a suggestion for solving (we may open new issues)
Problem B:
- Open the editor
- don't write nothing (no title, no content), but just send the app to the background (this will make the Post be saved locally! even if empty)
- bring the app back to the foreground
- observe the
UploadService
gets triggered and wants to upload the empty post (which is wrong), and thus generates an annoying error notification.
Also, if you go back to the Posts list the Post will cease to exist, and so the Notification's RETRY button will do nothing (if you tap on the Notification, a "Post no longer exists" message will be shown).
Problem C:
- turn airplane mode ON
- start a draft, give it a title, some content
- exit the editor and observe it's saved as Local Drafts
- open it again
- edit the title or content
- tap on SAVE (navigation bar)
- observe the "Ready to publish? Keep editing / Publish immediately" dialog is shown --> it should only be saving then update here (probably should also say UPDATE instead of SAVE up there)
Again, thanks for this PR, and let me know about the other issues (don't know if they're under someone's radar already)
@@ -784,6 +783,7 @@ private void retryUpload(PostModel post, boolean processWithAztec) { | |||
// send event so Editors can handle clearing Failed statuses properly if Post is being edited right now | |||
EventBus.getDefault().post(new UploadService.UploadMediaRetryEvent(mediaToRetry)); | |||
} else { | |||
mPostUploadNotifier.addPostInfoToForegroundNotification(post, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch here - it definitely seems the right place where to add it
Woow, thank you so much for the thorough review and for the great suggestions!
I've applied your patch. Thanks!!
This was recently fixed in #9962.
I've created a new issue - #9966. Thanks @mzorz! I have just applied your patch and tested the app and it LGTM! It's ready for another round/merge. 🙇 |
Hey! I'm moving this to 12.7 since 12.6 has been cut. If you want it to land 12.6, please feel free to move it back, target the release branch and ping me to build a new beta. |
Just a friendly reminder to please make sure to manually merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Just looked into it @malinajirka , LGTM, approving now, feel free to make the develop
merge into this branch first 👍
Thanks @mzorz !;) I've merged develop into the branch + I verified everything is migrated to AndroidX (no changes were required). I've also updated release notes - moved the note about this fix into 12.7. |
I'm merging this as the PR has been approved. 🚢 |
Fixes #9951
This PR takes care of promoting the UploadService to the foreground (shows an upload in progress notification) when retrying upload.
I've removed this line
mPostUploadNotifier.removePostInfoFromForegroundNotificationData(post, mediaToRetry);
but tbh I'm not sure what was the initial purpose of the line. I haven't find any reason why we need to invoke it on this place. If I keep it there, the upload notification will always show "1 post remaining" even when I invoke retry on three posts.
Imagine we have 3 posts
sNotificationData.mTotalPostItems
to 1mPostUploadNotifier.removePostInfoFromForegroundNotificationData(post, mediaToRetry);
-> decreasessNotificationData.mTotalPostItems
to 0 -> and increases it back to 1To test:
Update release notes:
RELEASE-NOTES.txt
.Before/After gifs