Repository navigation
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.
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.
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.
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.
Probably we can put this <!-- wp:image {\"id\":%s} --> in some constant ?
| return (postContent != null && postContent.contains(GUTENBERG_BLOCK_START)); | ||
| } | ||
|
|
||
| public static String replaceMediaFileWithUrl(Context context, @NonNull String postContent, |
There was a problem hiding this comment.
As this is a static method, maybe it's a good candidate for some Util or Helper?
There was a problem hiding this comment.
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.
…gment as it was already moved to PostUtils before
|
Thanks for your feedback, this is ready for another round @marecar3 🙇 |
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
MediaUploadReadyProcessorimplementation for GutenbergImageblocks 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.