From b2492e2ce05255bf21f6bfc9dbfa213cca0d11c4 Mon Sep 17 00:00:00 2001 From: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Date: Wed, 30 Jul 2025 02:01:55 +0530 Subject: [PATCH] feat: add cloud id during native sync # Conflicts: # mobile/lib/platform/native_sync_api.g.dart --- .../app/alextran/immich/sync/Messages.g.kt | 18 ++++++++++++++++++ .../alextran/immich/sync/MessagesImplBase.kt | 4 ++++ mobile/ios/Runner/Sync/Messages.g.swift | 16 ++++++++++++++++ mobile/ios/Runner/Sync/MessagesImpl.swift | 16 ++++++++++++++++ mobile/pigeon/native_sync_api.dart | 2 ++ 5 files changed, 56 insertions(+) diff --git a/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/Messages.g.kt b/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/Messages.g.kt index 9c618d9ed0..9ee55b5874 100644 --- a/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/Messages.g.kt +++ b/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/Messages.g.kt @@ -260,6 +260,7 @@ interface NativeSyncApi { fun getAssetsCountSince(albumId: String, timestamp: Long): Long fun getAssetsForAlbum(albumId: String, updatedTimeCond: Long?): List fun hashPaths(paths: List): List + fun getCloudIdForAssetIds(assetIds: List): Map companion object { /** The codec used by NativeSyncApi. */ @@ -418,6 +419,23 @@ interface NativeSyncApi { channel.setMessageHandler(null) } } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.immich_mobile.NativeSyncApi.getCloudIdForAssetIds$separatedMessageChannelSuffix", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val assetIdsArg = args[0] as List + val wrapped: List = try { + listOf(api.getCloudIdForAssetIds(assetIdsArg)) + } catch (exception: Throwable) { + MessagesPigeonUtils.wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } } } } diff --git a/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt b/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt index b2ceb8a9f2..1abd9c39c8 100644 --- a/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt +++ b/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt @@ -234,4 +234,8 @@ open class NativeSyncApiImplBase(context: Context) { } } } + + fun getCloudIdForAssetIds(assetIds: List): Map { + throw IllegalStateException("Method not supported on Android.") + } } diff --git a/mobile/ios/Runner/Sync/Messages.g.swift b/mobile/ios/Runner/Sync/Messages.g.swift index 19f4384672..9afcff7d23 100644 --- a/mobile/ios/Runner/Sync/Messages.g.swift +++ b/mobile/ios/Runner/Sync/Messages.g.swift @@ -324,6 +324,7 @@ protocol NativeSyncApi { func getAssetsCountSince(albumId: String, timestamp: Int64) throws -> Int64 func getAssetsForAlbum(albumId: String, updatedTimeCond: Int64?) throws -> [PlatformAsset] func hashPaths(paths: [String]) throws -> [FlutterStandardTypedData?] + func getCloudIdForAssetIds(assetIds: [String]) throws -> [String: String?] } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -476,5 +477,20 @@ class NativeSyncApiSetup { } else { hashPathsChannel.setMessageHandler(nil) } + let getCloudIdForAssetIdsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.NativeSyncApi.getCloudIdForAssetIds\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getCloudIdForAssetIdsChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let assetIdsArg = args[0] as! [String] + do { + let result = try api.getCloudIdForAssetIds(assetIds: assetIdsArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getCloudIdForAssetIdsChannel.setMessageHandler(nil) + } } } diff --git a/mobile/ios/Runner/Sync/MessagesImpl.swift b/mobile/ios/Runner/Sync/MessagesImpl.swift index 2810dee7c1..dd4afc6b37 100644 --- a/mobile/ios/Runner/Sync/MessagesImpl.swift +++ b/mobile/ios/Runner/Sync/MessagesImpl.swift @@ -286,4 +286,20 @@ class NativeSyncApiImpl: NativeSyncApi { return FlutterStandardTypedData(bytes: Data(digest)) } } + + func getCloudIdForAssetIds(assetIds: [String]) throws -> [String : String?] { + guard #available(iOS 16, *) else { + return Dictionary( + uniqueKeysWithValues: assetIds.map { ($0, nil as String?) } + ) + } + + var mappings: [String: String?] = [:] + let result = PHPhotoLibrary.shared().cloudIdentifierMappings(forLocalIdentifiers: assetIds) + for (key, value) in result { + let id = try? value.get().stringValue + mappings[key] = id + } + return mappings; + } } diff --git a/mobile/pigeon/native_sync_api.dart b/mobile/pigeon/native_sync_api.dart index e84c814c3d..d015f62b27 100644 --- a/mobile/pigeon/native_sync_api.dart +++ b/mobile/pigeon/native_sync_api.dart @@ -96,4 +96,6 @@ abstract class NativeSyncApi { @TaskQueue(type: TaskQueueType.serialBackgroundThread) List hashPaths(List paths); + + Map getCloudIdForAssetIds(List assetIds); }