-
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
Autosave or update draft #11251
Autosave or update draft #11251
Conversation
You can test the changes on this Pull Request by downloading the APK here. |
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 @oguzkocer! I think this approach should work. I've left some questions to clarify some parts, but I like it overall.
WordPress/src/main/java/org/wordpress/android/ui/uploads/AutoSavePostIfNotDraftUseCase.kt
Outdated
Show resolved
Hide resolved
WordPress/src/main/java/org/wordpress/android/ui/uploads/AutoSavePostIfNotDraftUseCase.kt
Outdated
Show resolved
Hide resolved
WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadHandler.java
Show resolved
Hide resolved
WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadHandler.java
Outdated
Show resolved
Hide resolved
WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadHandler.java
Outdated
Show resolved
Hide resolved
WordPress/src/main/java/org/wordpress/android/ui/uploads/AutoSavePostIfNotDraftUseCase.kt
Outdated
Show resolved
Hide resolved
@malinajirka I've addressed almost everything we talked about yesterday and I think it's ready for a look. I still have documentation and unit tests to add, but to save time on those, I want to make sure we are all good with the approach and the behavior we want. One good news I have is, if we set the publish date of the post and then upload it as draft, the date is preserved and the I am not sure how we should test the errors, but I have added the test cases I was thinking of. Let me know what you think! Test Notes
The results should be the same. In the first set of tests, the upload will happen as soon as the editor is closed. In the second set, it'll happen as soon as connection is available. In the third, all changes will happen as soon as connection is available one after the other. How to verify an autosave:
Test cases:
|
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 have reviewed the code again and tested all the scenarios. I have found some things I'm not sure about. Let me know what you think ;)
Dangling upload in progress notification
- Turn on the airplane mode
- Edit 3 different published posts and don't explicitly save the changes
- Turn off the airplane mode
- Notice the changes are auto-saved but the uploading notification doesn't disappear
(I think it might be related to one of my in-code comments (event priority).)
One good news I have is, if we set the publish date of the post and then upload it as draft, the date is preserved and the Schedule button shows up in Calypso. In the app it says Publish but I think that's a bug.
Hmm, interesting. Tbh I'm not sure it's a bug. The editor actions rely on the state being valid. The fact that our architecture allows saving an invalid state (PostStatus: Published, Date: in the future) is unfortunate, but I think checking for this invalid state all over the place is even worse. The app shows "Publish" action since the PostStatus is "Draft" which is correct. If what I said is true, I'd consider reseting the date when we change the status to "Draft". Wdyt?
WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadHandler.java
Outdated
Show resolved
Hide resolved
WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadHandler.java
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
@Subscribe(threadMode = BACKGROUND) |
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'm sorry I missed this during the initial review 😞
The previous implementation was subscribed on the MAIN thread and had priority set to 9. We wanted to ensure the PostUploadHandler receives the event before UploadService.
The UploadService invokes stopServiceIfUploadsComplete
and checks mPostUploadHandler.hasInProgressUploads()
. If we don't use the priority, we'll introduce a race condition as mPostUploadHandler.hasInProgressUploads()
will return true or false depending on which class received the event first, UploadService vs PostUploadHandler.
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 have made this change in bb985b1, but I couldn't test it because I can't reproduce the issue even before the change. Also, as discussed on Slack, I think there is a better way to handle the priority issue, so I'll open an issue for that once this PR is merged.
@malinajirka Thank you for the review. I've fixed the issues you mentioned and replied to your comments with the commit hashes. I've then added documentation in 1268a78. Finally, I worked on the unit tests in all the remaining commits (between 174b742 and 26db1f9) which are contained in one file Let me know what you think! |
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 @oguzkocer! I've reviewed the changes and tested several scenarios. I haven't encountered any issues.
Feel free to merge this PR. I'm not merging it since the description still says This is a discussion PR and will be closed once it serves it's purpose ...
.
Thanks @malinajirka! I intended to close this PR and open a fresh one when we figured out the approach. However, that happened fairly late in the PR, so I think opening a fresh one would just confuse us if we need to refer back to it. |
This is a PR to discuss possible approaches to fix #10951. This issue is happening because
/autosave
endpoint has the following behavior:Unfortunately we are unable to address the issue in the API side, so we are left to fix it in the client in a somewhat hacky way. We'll do what the API does and update the actual draft instead of calling
/autosave
. This will fix the comments getting disabled issue and also make it obvious what's happening in the client side. (we didn't know that API was updating the actual draft until recently)@malinajirka As discussed on Slack, I don't really know what the best way to go about this is. The approach I like the most is to encapsulate the solution as much as possible so it doesn't affect the rest of the app.
I have considered 3 types of use cases for this:
AutoSavePostOrUpdateDraftUseCase
: If we were to go with this, we'd encapsulate everything in the use case and don't return a result back toPostUploadHandler
until the whole thing is done.AutoSavePostIfNotDraftUseCase
: This is the use case I explored in this PR. The reason I tried this one over the first option is the complication around push post inPostUploadHandler
. If we go with the first option we'll have to duplicate the push post logic or refactor that logic into a usecase and somehow chain them. Refactoring is probably a good idea, but I am not sure how complicated it'll be.FetchPostStatusUseCase
: This would be the simplest approach and we'll just return the remote post status toPostUploadHandler
. Architecturally, this makes the most sense because it does one thing only. If we (only) do this, we can't encapsulate the complication. However, if we go with the first option, we can have this as a helper use case which would work very well.There are other combinations of these approaches and we might even go with something completely different. I was hoping your experience with
PostUploadHandler
, however little that might be, could be helpful in deciding what makes the most sense time/value-wise.Please keep in mind that this is a heavily WIP PR and the goal is to figure out the solution we want as fast as possible. The polish will come later and the
TODO
s in the PR points to things that I am already thinking about. That said, please feel free to comment on them, especially the question ones.This is a discussion PR and will be closed once it serves it's purpose, so both testing steps and PR submission checklist is removed.I decided to keep this PR open since it took a lot of discussion to figure out the solution. I don't think opening a new PR would have served any real purpose after the solution was figured out.