-
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
Gutenberg - async media upload Post background processing #9132
Gutenberg - async media upload Post background processing #9132
Conversation
|
||
if (showAztecEditor) { | ||
if (showGutenbergEditor) { | ||
// TODO check if anything needs be done in Gutenberg |
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.
This // TODO mark left here on purpose
Matcher m = p.matcher(postContent.substring(iStartOfImgTag)); | ||
if (m.find()) { | ||
String src = m.group(); | ||
int startIndex = src.indexOf("src=") + 5; |
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.
Can we put magic number 5 in some variable so that we can remember what's the idea behind 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.
👍 addressed in 6c5ec0a
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.
er, re-wrote it in 924725e to a class constant so it's easier to read
// TODO: replace the URL | ||
if (!mediaFile.isVideo()) { | ||
// replace gutenberg block id holder with serverMediaId, and url_holder with remoteUrl | ||
String oldImgBlockHeader = String.format("<!-- wp:image {\"id\":%s} -->", localMediaId); |
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.
Probably we can put this <!-- wp:image {\"id\":%s} -->
in some constant ?
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.
addressed in a321f5e
@@ -368,6 +371,55 @@ public static boolean contentContainsGutenbergBlocks(String postContent) { | |||
return (postContent != null && postContent.contains(GUTENBERG_BLOCK_START)); | |||
} | |||
|
|||
public static String replaceMediaFileWithUrl(Context context, @NonNull String postContent, |
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.
As this is a static method, maybe it's a good candidate for some Util or Helper?
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.
That's a good idea, I was following the same pattern as we had for Aztec: in Aztec the class that can handle / is responsible for editing a Post is AztecEditorFragment, and we needed a static method as this manipulation of the Post's content happens asynchronously (that is, when the AztecEditorFragment is not instanced).
For Gutenberg instead, this responsibility can be split into another class as you suggested.
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.
addressed this change in 7472379
…gment as it was already moved to PostUtils before
Thanks for your feedback, this is ready for another round @marecar3 🙇 |
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.
Nice Job @mzorz!
Fixes part of wordpress-mobile/gutenberg-mobile#475
Follow up to #9129 (media upload progress reattach). That PR handles the visual updates, while this other PR handles the updates to a Gutenberg Post when an image upload finishes but the user is not currently using the Gutenberg editor.
This PR introduces a
MediaUploadReadyProcessor
implementation for GutenbergImage
blocks based on search & replace, and also makes Post<-> media associations aware of Gutenberg posts inpurgeMediaToPostAssociationsIfNotInPostAnymore
.For the first (
MediaUploadReadyProcessor
), I've been considering some possible paths and have made up my mind for the easiest to implement for now, but may as well not be the most reliable as it makes several assumptions regarding the structure of an Image block as it currently is.However, the PR works as per the current state of affairs, and I believe we shouldn't expect there to be breaking changes to the block structure in the future given it's one of the core blocks.
For further discussion
Other possibilities:
(this is indeed to be used only when the GB Editor is not on the foreground, but we should also consider situations in which we have already launched the background task and the user is also trying to bring GB editor up in the middle.)
use an HTML parser at least to make sense of the HTML tags to make url replacement a little bit more intelligent (or, HTML aware)
use some kind of regex or string replacement like this one here.
To test:
Pretty much we can follow the test cases described in #5780, writing here the most simple case (situation described in CASE B there):
Update release notes:
RELEASE-NOTES.txt
.