WP Stories: only allow updating a Post to the server when a Story is finished being saved #13518
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes Automattic/stories-android#587
As the issue describes, sometimes we'd end up having a Post with local URLs pointed to by the Story block, leading to a broken experience.
The current implementation of Stories manages the creation of a new block on the MediaSaveUploadBridge, and handles the updates to an existing block on a Post through Gutenberg and the Gutenberg bridge.
In the first case (a new Story post created from scratch, without using Gutenberg) everything goes smooth because we don't need to create the actual Post or Story block until we have all the media in place.
But in this latter case, we use temporary ids to reflect the progress of a slide saving operation on the visual representation of the Story block itself in mobile Gutenberg while this is taking place. In order to identify which Story block a progress event corresponds to, the temporary id the event carries is checked against the ones being hold in the media collection that represents the block.
These temporary ids make no sense for an entity other than the WPAndroid / mobile Gutenberg implementation of the Story block integration, so sending a Post with such data to the server is inevitably breaking the relationship between a Post and the media contained in it.
OTOH, the Editor and WPAndroid know how to handle uploads and conversions from local mediaIds to remote mediaIds so, it makes sense to just hold off from updating or pushing the transient Post content with temporary ids to the server whilst the saving operation is taking place. As soon as a saving operation finishes, order is re-established and a local Media id is obtained, which can be used for reference later.
As such, this PR implements this safeguard by keeping track of the
StorySaveProcessStart
andStorySaveResult
events in theStoriesEventListener
class. This tracked information can be queried inEditPostActivity
when the user taps on theUPDATE
button or attempts to exit the editor prematurely before the save operation has finished, and shows a brief Toast asking the user to wait for a bit.The amount of time the user will need to wait to tap
UPDATE
or exit the editor is as long as it takes for each of the Story's slides to be saved. Ideally, this is almost negligible with image backed story slides, but is noticeable for video backed slides. For example, on a random handset (as per my tests: a Pixel 2 and a Samsung S5e tablet) it takes approximately 3 to 4 seconds to save a 30 seconds video backed slide to finish saving, although saving multiple videos does not necessarily add up time linearly (given we are using coroutines to process up to 3 videos simultaneously) so, it shouldn't be much of a problem to wait a few seconds.Ideally, we'd to implement a queueing system that waits for media to be saved first, and then use the existing queue for uploading as per with any other regular WP Media / Post item, but it may add complexity and demand more thorough testing.
To test:
UPDATE
on the navigation bar, or try tapping Android's navigation back buttonStory being saved, please wait...
UPDATE
or the back button after the story has been saved should behave as usual.This gif shows all of these steps:
PR submission checklist:
RELEASE-NOTES.txt
if necessary.