wordpress-mobile / WordPress-Android

WordPress for Android
http://android.wordpress.org
GNU General Public License v2.0
2.99k stars 1.33k forks source link

Blank post trying to share media/links from another app when block editor enabled #10570

Closed mrfoxtalbot closed 4 years ago

mrfoxtalbot commented 5 years ago

Expected behavior

When using the sharing feature from other apps into a new post on the WordPress App I would expect the title for the new post to be created automatically, and the shared content (link or image) to be added to the content.

Actual behavior

If you have the block editor enabled, using the "share to WordPress" feature will create a new empty post, it will not add the title or the content.

Interestingly enough, if you are sharing an image the image will be uploaded to the Media Library, but will not be inserted into the post.

Steps to reproduce the behavior

  1. Enable "Block Editor" option in a given blog (as this is a per-site setting)
  2. Open a different app (Gallery, Youtube).
  3. Share a video or an image from that other app into the WordPress app
  4. You will be redirected to new blank post, but the shared content will NOT be added to that new post.

Enable block editor

Screenshot_20191004-183619

Share image or link from a different app

Screenshot_20191004-184100  1

The new post is empty!

Screenshot_20191004-183944
Tested on [device], Android [version], WPAndroid [version]
mrfoxtalbot commented 5 years ago

For some reason I am not being allowed to add tags to this issue, I am not sure why.

designsimply commented 5 years ago

đź‘‹ @mrfoxtalbot labels may only be added by those with write access. We review new issues often though and if you are not able to add labels then they will mostly likely be added within a few days!

designsimply commented 5 years ago

Tested and confirmed using WPAndroid 13.4-rc-1 on Pixel 3 Android 10. (1m29s)

Added to the Prioritized Android list because it involves the editor and sharing which are both very important flows for this app.

mrfoxtalbot commented 5 years ago

labels may only be added by those with write access.

Got it, thank you Sheri!

hafizrahman commented 5 years ago

I'm looking into this.

hafizrahman commented 5 years ago

Troubleshooting notes so far:

The functions that does the filling both for Aztec and Gutenberg is here:

https://github.com/wordpress-mobile/WordPress-Android/blob/48c886ef6734254a20cf6479bb36014f889adb35/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java#L2373

I am not super familiar with how Gutenberg works yet in the app, but my hunch is that the editor is not loaded completely yet when mEditorFragment.setTitle(title) is being called in the function above, hence why it has no effect on Gutenberg.

Specifically with Gutenberg, there's this EditorFragmentListener. onEditorFragmentContentReady() function that's being called once the editor finishes loading. Calling setPostContentFromShareAction() inside that function seems to make things work in my test.

There's also a small need to convert the content part to into a paragraph block, otherwise it's just added as a regular <p>content</p> code that's then shown as unrecognized block in the editor.

hafizrahman commented 5 years ago

@shiki Curious about what you would recommend for the situation above.

  1. Is my assessment above correct, or am I missing something?
  2. If it is correct, how would I go with structuring the code part? With what I mentioned above, the raw fix would be to have one setPostContentFromShareAction() inside fillContentEditorFields() as it is now for Aztec, then add another setPostContentFromShareAction() inside onEditorFragmentContentReady() for Gutenberg.

Nevertheless, that feels a bit odd to me (and probably will make the code more confusing to read). I would love it to be called from a single place, that handles both the Aztec and Gutenberg cases, but I'm not sure how I would structure it.

hafizrahman commented 5 years ago

Adding a drawing I made to understand the logic flow inside EditPostActivity.java because why not:

wp android - understanding issue 10570
shiki commented 4 years ago

@hafizrahman Sorry I missed this.

It looks like you're on the right track. Though I agree that onEditorFragmentContentReady seems like an odd place for the change.

One thing I noticed is that when editing an existing post within WordPress, the fillContentEditorFields() is just enough for Gutenberg to preload the existing post's title and content. It looks like calling setContent and setTitle only works once with GutenbergEditorFragment. The second call does not seem to work.

This is the case when sharing since, first, the setContent is called in:

https://github.com/wordpress-mobile/WordPress-Android/blob/aed0c79108ba08424af38b3eb28c2772a98bdc40/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java#L2346

And then it's called again when setPostContentFromShareAction() is executed:

https://github.com/wordpress-mobile/WordPress-Android/blob/aed0c79108ba08424af38b3eb28c2772a98bdc40/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java#L2362-L2363

Note that this call is still inside fillContentEditorFields().

It looks like the fillContentEditorFields() would require a re-ordering of the sequence so that if there is a shared INTENT, we should not call the first setContent on the GutenbergEditorFragment. I was able to test this hypothesis by changing fillContentEditorFields() to this:

    private void fillContentEditorFields() {
        // Needed blog settings needed by the editor
        mEditorFragment.setFeaturedImageSupported(mSite.isFeaturedImageSupported());

        if (!mHasSetPostContent) {
            mHasSetPostContent = true;
            setPostContentFromShareAction();
            return;
        }

With this code, I was able to share from Youtube and the title and content was loaded. The content was showing up as “Unsupported“ though. There's probably a function somewhere we can use to create a compatible paragraph.

I hope this helps. 🙂

mzorz commented 4 years ago

Just leaving a comment here that I tried with alpha-195 and was able to share an image to WordPress from Photos app and also from WhatsApp and a new Post is created, the image gets uploaded and inserted into an image block in the Gutenberg editor. Youtube on the contrary, does show the observed behavior (empty Post).

maxme commented 4 years ago

I had the same issue trying to share a link using alpha-203 (14.1). The weird part is that the post title and content is correctly set but it's not shown in the editor.

https://bia.is/s/GDyK/share-link-with-gutenberg.webm