Skip to content

Media service to support the mobile apps#1338

Merged
crazytonyli merged 19 commits into
trunkfrom
task/media-service-sync-media
May 15, 2026
Merged

Media service to support the mobile apps#1338
crazytonyli merged 19 commits into
trunkfrom
task/media-service-sync-media

Conversation

@crazytonyli
Copy link
Copy Markdown
Contributor

@crazytonyli crazytonyli commented May 13, 2026

Description

Supporting the iOS Media Library V2 work. Adds MediaService + MediaMetadataCollectionWithEditContext mirroring the existing PostService / PostMetadataCollectionWithEditContext pattern so the iOS side can consume media through the canonical cached + paginated + observable collection path.

The mutation surface is deliberately narrower than the post side: no create_media, no update_media, and no membership-update path on the collection. We'll implement that when we reach that stage on the iOS app side.

Changes

  1. wp_mobile_cache: media_edit_context table (migration 0014), DbTable::MediaEditContext, EntityType::MediaEditContext, MediaRepository<EditContext> (mirrors PostRepository minus term relationships), plus a MediaBuilder test fixture.
  2. wp_mobile: MediaListFilter (subset of MediaListParams minus pagination, include/exclude, and date ranges), media_list_filter_cache_key, MediaService with sync / fetch / state tracking, and MediaMetadataCollectionWithEditContext reusing MetadataCollectionCore and the shared wp_mobile_metadata_item! macro. Includes an integration test against the test server.
  3. wp_api: hand-implement PartialEq + Eq + Hash on MediaDetails (string-compare on the raw JSON payload, FIXME left in place to revisit) and drop SparseMedia's #[WpContextualDontDerivePartialEq] so the contextual media types derive the traits like the post side. Without this, the regenerated FullEntityMediaWithEditContext Swift wrapper couldn't synthesize Equatable + Hashable. scripts/swift-bindings.sh's patch_wp_api is extended to append extension MediaWith{Edit,Embed,View}Context: Hashable {} (mirrors how the post side handles AnyJson).

Test plan

  • cargo test -p wp_api -p wp_mobile_cache -p wp_mobile
  • cargo test -p wp_mobile_integration_tests --test test_media_collection (needs make test-server)
  • make xcframework + spot-check that the regenerated Swift wrapper exposes WpService.media(), MediaService.createMediaMetadataCollectionWithEditContext(...), MediaListFilter, MediaMetadataCollectionItem, and MediaItemState.

Changelog

  • I've added an entry to CHANGELOG.md under ## [Unreleased], using the Keep a Changelog categories (Added, Changed, Deprecated, Removed, Fixed, Security). Prefix breaking changes with **BREAKING:**.

…ndings

SparseMedia opted out of PartialEq via #[WpContextualDontDerivePartialEq]
because MediaDetails.payload (Box<RawValue>) can't auto-derive PartialEq.
That suppression cascaded to MediaWithEditContext and broke Swift's
auto-synthesis for FullEntityMediaWithEditContext. Hand-implement
PartialEq/Eq/Hash on MediaDetails by raw-JSON-string comparison, mark it
exported to Swift via #[uniffi::export(Eq, Hash)], drop the contextual
opt-out so the contextual media types derive the traits like the post
side, and extend the Swift bindings patch script to add Hashable
extensions for the contextual media types (MediaDetails is a reference
type so uniffi can't auto-synthesize the conformance on the Record).
@crazytonyli crazytonyli marked this pull request as ready for review May 13, 2026 22:10
@wpmobilebot
Copy link
Copy Markdown
Collaborator

wpmobilebot commented May 13, 2026

XCFramework Build

This PR's XCFramework is available for testing. Add to your Package.swift:

.package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1338")

Built from 4f70ea9

Copy link
Copy Markdown
Contributor

@oguzkocer oguzkocer left a comment

Choose a reason for hiding this comment

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

I raised one important issue, but it's safe to address it in a subsequent PR, so I am approving to unblock.

Comment thread CHANGELOG.md Outdated

### Changed

- `MediaDetails` now derives `Eq + Hash` (raw-JSON-string comparison, FIXME left in place) and is exported via `#[uniffi::export(Eq, Hash)]`; `SparseMedia`'s `#[WpContextualDontDerivePartialEq]` opt-out is removed so `MediaWithEditContext` and the generated `FullEntityMediaWithEditContext` Swift wrapper synthesize `Equatable + Hashable`
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.

I don't think there is a FIXME in the diff, and really, we shouldn't use FIXMEs. So, this is probably a left over from a Claude session.

Comment thread wp_mobile/src/service/media.rs Outdated
// `Missing`/`Stale` until the next full refresh. Failure here is
// logged but not propagated: the REST delete and local row delete
// already succeeded.
let media_list_prefix = format!("site_{:?}:edit:media:", self.db_site.row_id);
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.

This prefix logic is duplicated in create_media_metadata_collection_with_edit_context which could lead to issues if one is altered.

Extract the shared edit-context media list key prefix into a single helper so the prefix used to scrub a deleted media item from every cached list matches the prefix used when constructing a collection's ListKey. Drop the stale FIXME mention from the MediaDetails changelog entry since no FIXME was ever added to the diff.
@crazytonyli
Copy link
Copy Markdown
Contributor Author

@oguzkocer Thanks for the review. I have addressed your comments in a new commit.

@crazytonyli crazytonyli enabled auto-merge (squash) May 15, 2026 09:54
@crazytonyli crazytonyli merged commit 1612c39 into trunk May 15, 2026
34 checks passed
@crazytonyli crazytonyli deleted the task/media-service-sync-media branch May 15, 2026 10:22
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.

3 participants