-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Automatically upload local drafts #9774
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
Conversation
The method `LocalDraftUploadStarter.uploadLocalDrafts` is called when: - The internet comes back online - The Posts activity is shown - When the user performs a pull-to-refresh in any of the Posts tabs
- Removed unnecessary `@Provides` 🤦♂️ - Using a simple `getPostsForSite()` method for now. This should probably be replaced with a FluxC method
It does not need to be a singleton right now. Perhaps later.
Also added helpers.
In this way, we can guarantee that `site` is not `null`.
The `mocked*` can be misleading because the returned instances are not mocks. It is the parameters that are mocked.
WordPress/src/main/java/org/wordpress/android/ui/uploads/LocalDraftUploadStarter.kt
Outdated
Show resolved
Hide resolved
malinajirka
left a comment
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 @shiki;)! Good job - the code looks good and it works as described! I've left a couple of in-code comments.
The auto-upload never happens if the Post List is not open. I think this is one of those things that we will need to have an architectural and design discussion about soon.
I believe, even if we decide to create a sync service or something similar we'll still be able to reuse most of this code. ;)
For this PR, I wanted to focus on the process flow and architecture so I intentionally did not include these.
Auto-upload in Pages.
I think the LocalDraftUploadStarter will upload even pages as postStore.getLocalDrafts(site) returns both posts and pages. If you meant, that you haven't added the logic to start the LocalDraftUploadStarter from the pages list screen, then ignore this comment :).
SideNote: I've also noticed the ConnectionStatusLiveData emits changes even when the internet connection changes from LTE -> Wifi or other way round. We might want to consider adding getDistinct(). Wdyt?
WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt
Show resolved
Hide resolved
|
|
||
| fun start(site: SiteModel) { | ||
| /** | ||
| * @param postListEventsListenerEnabled This is only provided to make this class testable in unit tests. |
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.
I think we might want to consider wrapping fun listenForPostListEvents(..) with an injectable class and inject it into the PostListMainViewModel (inject mocked version in unit tests). I'd rather avoid @ VisibleForTesting unless we really need it. Wdyt?
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.
Thank you for noticing this. This was the part that I didn't like much. An injectable class would probably be better. I might end up making PostListEventListener public or refactoring it a bit. I'll think about it. 🤔
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.
Used a Factory in e26e540.
| } | ||
|
|
||
| val localDrafts = postStore.getLocalDrafts(site) | ||
| localDrafts.forEach { UploadService.uploadPost(context, it) } |
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.
I think the internet connection broadcast receiver can send multiple updates within a short timeframe. If I'm not missing anything this code will put multiple instances of the post into the UploadService queue. Should we check for example PostUploadHandler.isPostUploadingOrQueued. I know it'd be far from fool proof solution, but it might at least reduce the number of duplicate requests? Wdyt?
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.
I might have misread UploadService.unpackPostIntent. I saw the usage of PostUploadHandler.isPostUploadingOrQueued in there and just assumed that it will ignore posts that are currently in the queue. I should have tested that.
My original plan for this class was for it to be a @Singleton and manage its own queue so it will not do a query and upload in a short timeframe. I abandoned that to keep it simple and get your feedback. 🙂 Which turned out to be a good decision. I'll wait for the discussion with Maxime and everyone else before moving forward.
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.
|
Great review, @malinajirka!
Answered in this FluxC conversation.
Good catch! Discussed in this conversation. |
|
Design-wise this looks pretty good, I have two things I noticed:
|
|
Thanks @mattmiklic! I'll jump in as it's more related to the recent post list changes than to this PR.
Makes sense;). We can certainly do that, I'd suggest creating a separate ticket as it seems unrelated.
I discussed this issue with Sylvester. The problem is the bottom padding is added there by the system (it's a part of the progress bar). We could somehow workaround it, but we ran out of time for the project so we decided to keep it as it is for now. |
|
Thank you, @mattmiklic! I created #9790 for the label rename. |
|
Agree with @mattmiklic's feedback. Otherwise looks good! |
This method is what is used for uploading in Post List → Retry and it fixes the issue with uploads failing if they have a media.
This is so we can mock it in unit tests. It does not currently work in unit tests because of the `EventBus` usage.
…9568-upload-local-drafts # Conflicts: # WordPress/src/main/java/org/wordpress/android/viewmodel/helpers/ConnectionStatusLiveData.kt # build.gradle
Logic is still intact. The dependencies just changed.
# Conflicts: # build.gradle
|
@shiki Just to make sure we are on the same page and we are not waiting on each other :P. This is still marked as "Not Ready for Review". |
|
@malinajirka Thanks for checking. Yep, I'll fix the conflicts, retest, and let you know when it's ready. |
|
@malinajirka This is now ready for review again. 🙂 |
malinajirka
left a comment
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 @shiki ! I've reviewed the changes and tested the app again and everything looks good to me;)! Good job!

Closes #9568.
This adds auto-upload of Local Drafts when any one of these happens.
The auto-upload never happens if the Post List is not open. I think this is one of those things that we will need to have an architectural and design discussion about soon.
Not Covered Yet
For this PR, I wanted to focus on the process flow and architecture so I intentionally did not include these.
Locally Changedstatus #8957.I have updated the description of #9568 to list those that have not been covered yet.
FluxC PR
There is a companion FluxC PR for this: wordpress-mobile/WordPress-FluxC-Android#1243.
Testing
Release Notes
RELEASE-NOTES.txt.Status