Skip to content

Conversation

mzorz
Copy link
Contributor

@mzorz mzorz commented May 26, 2020

Builds on top of #11987

This PR implements the needed changes to listen to a StorySaveResult and then triggering the UploadService to upload the composed images.

For this, a new class is introduced, called StoryMediaSaveUploadBridge that is both a LifecycleObserver and a EditorMediaListener, which carries with this responsibility.

How it works

First, the StoryComposerActivity is now creating a backing Post, which will contain the story content in the format of a Gallery.

The post is instantiated and kept empty, given we won't populate its content until later when we know the media Ids for each of the saved story frames.

The StoryMediaSaveUploadBridge is registered as a LifeycleObserver of the Application class, and subscribes to EventBus StorySaveResult events in its onCreate() observer override.
When all of a Story's frames are successfully saved to disk (which is the responsibility of FrameSaveManager and FrameSaveService in the stories library), this class will then:

  • add each of the saved images as Media items to the WP Media Store (which will then be uploaded to the site). When these are created, we obtain a local mediaId for each (this is simply the id in the MediaStore).
  • the Post that was earlier created contains just a gallery shortcode for now (until we implement the actual Gutenberg story block) to demonstrate the functionality for alpha, and we use a placeholder with the localids, for example
[gallery type="slideshow" ids="placeholderLocalId3,placeholderLocalId4,placeholderLocalId5"]
  • the UploadService takes care of uploading the media. Once these have been uploaded, we obtain the remote MediaId (the actual mediaId field in FluxC's MediaStore) and the post content is updated by replacing the placeholders with each remoteId correspondingly, for example:
[gallery type="slideshow" ids="190,191,192"]
  • once media is finished uploading, the UploadService also takes care of uploading the corresponding Post.

  • in the case the user decides to abandon the Story creation screen without pubslishing, the backing Post will be discarded. Any frames saved to that point will remain as media in their device (not media in the WP libraries, just on their device as raw image / video files)

Error handling

  • if an error occurs while saving, the UploadService is never triggered. The Story won't be uploaded (and no new media will be created on the site's Media Library) until all of the frames are saved successfullly
  • once the Post is ready to upload and it's enqueued to upoload, the UploadService takes care of everything else (retrying, offline support etc) as per with any other regular Post.

Videos

Videos are not supported yet, given the Gallery only supports images. There's no code in this PR or in the stories library in general to prevent this, given it'd be just adding unnecessary work. If you add a video to a Story, and it gets saved correctly, etc. it will be uploaded to the site and added to the Gallery, but it won't show in the resulting Post.

To test:

  • create a story (only add text to your frames, not emoji for now)
  • tap PUBLISH
  • observe it gets saved, and then it gets uploaded
  • once it's published you'll be able to see it on the web. Tap on the published snackbar "VIEW" button if you'd like.

PR submission checklist:

  • I have considered adding unit tests where possible.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

mzorz added 2 commits May 26, 2020 12:02
…ress class so we can trigger the UploadService from there
… payload to the FrameSaveService and get it back when a SaveResult is ready
@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented May 26, 2020

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented May 26, 2020

You can test the changes on this Pull Request by downloading the APK here.

mzorz added 3 commits May 26, 2020 18:26
…ch of the StoryFrameItem composed frame files
…files and add them as Media and insert them into a Post, then upload
@mzorz mzorz added this to the 15.2 milestone May 28, 2020
Base automatically changed from feature/wp-stories-part6-mediapicker-wpmedia2 to feature/wp-stories-base June 19, 2020 13:30
editPostRepository.getPost(),
site
)
uploadService.uploadPost(WordPress.getContext(), editPostRepository.id, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we inject this context somehow so that we avoid using the static method call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been checking this, I think we need to make a context factory so it's injectable. I've seen sometimes we use init() to pass some variables to ViewModels and other injectable classes in WPAndroid, so went that way for now in 85bda8b

Copy link
Contributor

@jd-alexander jd-alexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mzorz great work on this 😄 I left some comments but overall the solution works really nicely. It was great seeing the story converted to a post!

jd-alexander and others added 4 commits June 19, 2020 18:10
…rt9-emoji-compat

WP Stories integration: add EmojiCompat library for stories emoji support
Co-authored-by: Joel Dean <[email protected]>
…rt92-notif-delete-intent

WP Stories integration - setting the base error notification ID and setDelete PendingIntent for error notification
…rt10-tracks-notifications

WP Stories integration - implement StoryNotificationTrackerProvider interface
@peril-wordpress-mobile
Copy link

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS

@mzorz
Copy link
Contributor Author

mzorz commented Jun 22, 2020

Hi @mzorz great work on this 😄 I left some comments but overall the solution works really nicely. It was great seeing the story converted to a post!

Thanks a lot for your review! Should be ready for a second round @jd-alexander 🙇

Copy link
Contributor

@jd-alexander jd-alexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes @mzorz Ran another test and all works well! LGTM 🚢

@jd-alexander jd-alexander merged commit b3eb54a into feature/wp-stories-base Jun 22, 2020
@jd-alexander jd-alexander deleted the feature/wp-stories-part8-upload-service branch June 22, 2020 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants