Skip to content
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] Update VideoPress upload processor (support self-closing block tag) #18287

Merged
merged 4 commits into from
Apr 24, 2023

Conversation

fluiddot
Copy link
Contributor

@fluiddot fluiddot commented Apr 19, 2023

Fixes wordpress-mobile/gutenberg-mobile#5678.

This PR updates the VideoPress upload processor following a recent change in the block format. Additionally, the upload processor logic has been updated to support the self-closing block tag (e.g. <!-- wp:videopress/video {"id":"1234","guid":"AbCdE" /-->), as the VideoPress block uses this format. Note that most of the changes are reverting the modifications introduced in #18187 (1419183).

To test

Testing instructions copied from #18187.

  1. Add a VideoPress block to an existing or new post.
  2. Select the choose from device option and upload a video.
  3. While there’s an ongoing upload, close the post with publishing changes.
  4. Verify that you see the upload progress in the post summary.
  5. Re-open the post and confirm the upload has completed.
  6. Preview the post and observe that the video can be played.

Default markup examples

Example default markup before upload:

<!-- wp:videopress/video {"id":"1234" /-->

Example default markup after upload:

<!-- wp:videopress/video {"id":"1234","guid":"AbCdE" /-->

Markup with attributes examples

Example markup before upload:

<!-- wp:videopress/video {"autoplay":true,"controls":false,"description":"","id":${localMediaId},"loop":true,"muted":true,"playsinline":true,"poster":"https://test.files.wordpress.com/2022/02/265-5000x5000-1.jpeg","preload":"none","seekbarColor":"#abb8c3","seekbarLoadingColor":"#cf2e2e","seekbarPlayedColor":"#9b51e0","title":"Demo title","useAverageColor":false} /-->

Example markup after upload:

<!-- wp:videopress/video {"autoplay":true,"controls":false,"description":"","id":${remoteMediaId},"loop":true,"muted":true,"playsinline":true,"poster":"https://test.files.wordpress.com/2022/02/265-5000x5000-1.jpeg","preload":"none","seekbarColor":"#abb8c3","seekbarLoadingColor":"#cf2e2e","seekbarPlayedColor":"#9b51e0","title":"Demo title","useAverageColor":false,"guid":"${videoPressGuid}"} /-->

Regression Notes

  1. Potential unintended areas of impact

This change could impact other upload processors due to the change related to supporting the self-closing tag.

  1. What I did to test those areas of impact (or what existing automated tests I relied on)

Manually tested the VideoPress upload processor and checked the unit tests of other upload processors.

  1. What automated tests I added (or what prevented me from doing so)

I added a test in 0d1ce8e and updated other unit tests.

PR submission checklist:

  • I have completed the Regression Notes.
  • 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.

UI Changes testing checklist:

  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • Talkback.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • Large and small screen sizes. (Tablet and smaller phones)
  • Multi-tasking: Split screen and Pop-up view. (Android 10 or higher)

@fluiddot fluiddot added this to the 22.3 milestone Apr 19, 2023
@fluiddot fluiddot self-assigned this Apr 19, 2023
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 19, 2023

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr18287-47a25ca
Commit47a25ca
Direct Downloadwordpress-prototype-build-pr18287-47a25ca.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 19, 2023

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr18287-47a25ca
Commit47a25ca
Direct Downloadjetpack-prototype-build-pr18287-47a25ca.apk
Note: Google Login is not supported on these builds.

Comment on lines +76 to +77
mBlockContentDocument = isSelfClosingTag ? null : parseHTML(captures.group(3));
mClosingComment = isSelfClosingTag ? null : captures.group(4);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Blocks with the self-closing tag won't have content so these properties are empty.

Comment on lines +128 to +130
String processBlock(String block) {
return processBlock(block, false);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is also used in unit tests. So, in order to avoid adding the isSelfClosingTag argument to all of them, I overloaded the function for convenience.

String blockTagSuffix = headerMatcher.group(2);
Boolean isSelfClosingTag = blockTagSuffix.equals("/-->");
if (isSelfClosingTag) {
positionBlockEnd = headerMatcher.end();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the block uses the self-closing tag, we don't need to loop over the content to find the end position.

@@ -11,7 +11,7 @@ public class MediaUploadCompletionProcessorPatterns {
public static final Pattern PATTERN_BLOCK_HEADER = Pattern.compile(new StringBuilder()
.append(PATTERN_BLOCK_PREFIX)
.append(MediaBlockType.getMatchingGroup())
.append(").*? -->\n?")
.append(").*? (/?-->)\n?")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This new capture group is used to determine if the block uses the self-closing tag.

Comment on lines +24 to +25
if (src?.startsWith("file:") == true) {
remove(SRC_ATTRIBUTE)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The src is removed when pointing to a local file, similar to how we do in the block's logic.

@@ -37,6 +37,14 @@ class MediaUploadCompletionProcessorTest {
Assertions.assertThat(blocks).isEqualTo(TestContent.newPostVideo)
}

@Test
fun `processPost splices id and guid for a VideoPress block`() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test was added because the VideoPress block wasn't being tested against the processContent function.

@fluiddot fluiddot marked this pull request as ready for review April 19, 2023 17:19
@fluiddot fluiddot requested review from jhnstn and SiobhyB April 19, 2023 17:20
@fluiddot fluiddot force-pushed the gutenberg/update/videopress-upload-processor branch from a07475c to 63f6297 Compare April 20, 2023 09:01
Remove unused import

Remove unused import

Update test: processBlock leaves VideoPress block unchanged
@fluiddot fluiddot force-pushed the gutenberg/update/videopress-upload-processor branch from 63f6297 to 47a25ca Compare April 20, 2023 09:06
Copy link
Contributor

@SiobhyB SiobhyB left a comment

Choose a reason for hiding this comment

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

I confirmed uploads works as expected after exiting a post with the changes from this PR. Thank you @fluiddot for the updates! 🙌 🚀

@fluiddot fluiddot merged commit bd46b53 into trunk Apr 24, 2023
@fluiddot fluiddot deleted the gutenberg/update/videopress-upload-processor branch April 24, 2023 07:46
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.

Update media upload processors following changes to save
3 participants