Skip to content

External media sources and app-side integration - #25623

Open
crazytonyli wants to merge 2 commits into
trunkfrom
task/media-v2-upload-integration
Open

crazytonyli wants to merge 2 commits into
trunkfrom
task/media-v2-upload-integration

Conversation

@crazytonyli

Copy link
Copy Markdown
Contributor

Note

This PR will be merged after #25622.

@dangermattic

Copy link
Copy Markdown
Collaborator
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot

wpmobilebot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number34022
VersionPR #25623
Bundle IDorg.wordpress.alpha
Commite7c0873
Installation URL42q74ejfmbrtg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number34022
VersionPR #25623
Bundle IDcom.jetpack.alpha
Commite7c0873
Installation URL6miqm5k66hls8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch 4 times, most recently from 8e6e032 to 4666912 Compare June 12, 2026 00:50
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch from 4666912 to 64a7b18 Compare June 16, 2026 03:38
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch from 64a7b18 to 9aa7332 Compare June 16, 2026 03:43
@crazytonyli crazytonyli changed the title Wire the app-side uploader registry and lifecycle teardown External media sources and app-side integration Jun 16, 2026
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch from 989a00e to 671677b Compare June 16, 2026 08:28
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch 2 times, most recently from 9d04372 to a3cb5b6 Compare June 19, 2026 00:20
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch from a3cb5b6 to 9b8eb9e Compare July 7, 2026 22:09
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch from 9b8eb9e to 4136cb2 Compare August 26, 2026 00:00
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch from 4136cb2 to 75209a7 Compare August 26, 2026 07:39
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch from 75209a7 to e7c0873 Compare August 26, 2026 23:49
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch from e7c0873 to 8fdbbd2 Compare November 11, 2026 23:46
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch from 8fdbbd2 to ace66bf Compare November 16, 2026 04:30
@crazytonyli
crazytonyli removed this pull request from stack #25910 November 16, 2026 17:40
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch from ace66bf to df2a5e6 Compare November 16, 2026 17:40
@crazytonyli
crazytonyli added this pull request to stack #26407 November 16, 2026 17:41
Base automatically changed from task/media-v2-upload-ui to trunk December 1, 2026 21:45
Tear down uploaders by observing Core Data blog deletions on the main context instead of hooking individual removal call sites. This covers every deletion path with one mechanism, including sync-driven cleanup of dead blogs and the account cascade on logout, and it keeps self-hosted uploaders alive through a WordPress.com-only logout.
Stock Photos, Tenor GIFs, and Image Playground as picker sheets that wrap
the existing UIKit pickers, adapt their output to the module's external
media model, and feed the M4 uploader. Wires the picker options into
routing and adds the adapter and routing tests.
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-integration branch from df2a5e6 to 98c4b93 Compare December 2, 2026 00:30
@crazytonyli
crazytonyli requested a review from jkmassel December 2, 2026 00:33
@crazytonyli crazytonyli added this to the 27.6 milestone Dec 2, 2026
@crazytonyli
crazytonyli marked this pull request as ready for review December 2, 2026 00:34

@wpmobilebot wpmobilebot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve. I validated this on an iPhone 17 Pro simulator running iOS 26.5, Debug builds of both apps, signed in to the WordPress.com test account.

  • Jetpack: Media → + now shows Free Photo Library. I searched, picked two photos and tapped Add. The banner showed "Uploading 2 items", and both photos landed at the top of the grid. On the site they are pexels-photo-<id>.jpeg, image/jpeg, with the Pexels attribution caption kept. Cancel closes the sheet, and the menu still works afterwards.
  • WordPress app: the item is hidden, matching V1's jetpackFeaturesEnabled() gate.
  • Tests: the PR's suites pass locally (MediaUploaderRegistryTests, ExternalRemoteMediaAdapterTests, MediaLibraryRoutingExternalSourcesTests), and CI is green.

Gaps: Image Playground isn't available in the simulator, so I didn't exercise ImagePlaygroundPickerSheet. I checked the logout and site-removal teardown only with unit tests, not in the app (see the inline comment).

The inline comments are non-blocking.

) {
self.clientFactory = clientFactory
deletionObserver = NotificationCenter.default.addObserver(
forName: .NSManagedObjectContextObjectsDidChange,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: Teardown misses blogs deleted on a background context when the main context no longer holds that Blog. That covers the two main paths the doc comment lists: BlogService.removeBlog and AccountService.removeDefaultWordPressComAccount both delete in performAndSave, as does sync cleanup (mergeBlogs).

automaticallyMergesChangesFromParent only reports a deletion in ObjectsDidChange / NSDeletedObjectsKey for an object registered in mainContext. The registry keeps only the object ID, so once the user leaves Media and the Blog is dropped from the main context, the uploader stays in the registry. Its uploads then fail with siteUnavailable, and staged files remain until the app relaunches.

I proved it with a test that vends an uploader, drops the Blog from mainContext, then deletes it via contextManager.performAndSave. The Blog row is gone from the store, but registry.hasUploader(blogID:) is still true. The same test with the Blog still referenced on main passes:

✔ Derived-context deletion tears down uploader while the Blog is still referenced on main
✘ Derived-context deletion tears down uploader after the main-context Blog was released
   Expectation failed: !registry.hasUploader(blogID: id)

This isn't a regression, since trunk has no teardown, but the stated goal doesn't hold. A notification that carries deleted object IDs regardless of registration should close it, e.g. .NSManagedObjectContextDidSaveObjectIDs from any context on the same coordinator, or .NSManagedObjectContextDidMergeChangesObjectIDs on mainContext. Listening to saves or merges, not ObjectsDidChange, would also stop unsaved deletes from triggering teardown. It's worth adding a derived-context case to blogDeletionTearsDownUploader.

// A nil api posts the fix-auth-token notification
// from the getter itself, which triggers the
// re-sign-in flow, so this is not a dead end.
return AnyView(EmptyView())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question (unverified): When the lookup fails here (token cleared or blog deleted while Media is open), activePicker is already set. The sheet would then present a blank EmptyView with no Cancel button, and didCancel() never fires. Separately, the blog.wordPressComRestApi != nil gate on line 55 runs when the screen is built. That getter posts .wpAccountRequiresShowingSigninForWPComFixingAuthToken when the token is empty, whereas V1 only touches it on tap. To prove either, open Media with an account whose authToken is empty (e.g. a Jetpack-connected self-hosted site with an application password) and screenshot the sheet or the unprompted sign-in. Returning a view that calls delegate.didCancel() and dismisses, and gating on blog.account?.authToken?.isEmpty == false, would avoid both.

import WordPressMediaLibrary

extension ExternalRemoteMedia {
/// Stock Photos: prefer the asset's title (Pexels names are descriptive

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: This comment, and the "Sunset over the harbor" fixture in ExternalRemoteMediaAdapterTests, treat asset.name as a descriptive title. The live /meta/external-media/pexels response has name: "pexels-photo-31007138.jpeg"; the descriptive text is in title ("large container ship in hamburg harbor"). The behaviour is right and matches V1: uploads end up as pexels-photo-<id>.jpeg, and the deletingPathExtension is what makes that work. Consider rewording the comment and using a realistic name in the fixture so nobody later "fixes" this to use title.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants