feat: add cloud id during native sync

# Conflicts:
#	mobile/lib/platform/native_sync_api.g.dart
This commit is contained in:
shenlong-tanwen 2025-07-30 02:01:55 +05:30
parent 55544591a6
commit b2492e2ce0
5 changed files with 56 additions and 0 deletions

View File

@ -260,6 +260,7 @@ interface NativeSyncApi {
fun getAssetsCountSince(albumId: String, timestamp: Long): Long
fun getAssetsForAlbum(albumId: String, updatedTimeCond: Long?): List<PlatformAsset>
fun hashPaths(paths: List<String>): List<ByteArray?>
fun getCloudIdForAssetIds(assetIds: List<String>): Map<String, String?>
companion object {
/** The codec used by NativeSyncApi. */
@ -418,6 +419,23 @@ interface NativeSyncApi {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.NativeSyncApi.getCloudIdForAssetIds$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val assetIdsArg = args[0] as List<String>
val wrapped: List<Any?> = try {
listOf(api.getCloudIdForAssetIds(assetIdsArg))
} catch (exception: Throwable) {
MessagesPigeonUtils.wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
}
}
}

View File

@ -234,4 +234,8 @@ open class NativeSyncApiImplBase(context: Context) {
}
}
}
fun getCloudIdForAssetIds(assetIds: List<String>): Map<String, String?> {
throw IllegalStateException("Method not supported on Android.")
}
}

View File

@ -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)
}
}
}

View File

@ -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;
}
}

View File

@ -96,4 +96,6 @@ abstract class NativeSyncApi {
@TaskQueue(type: TaskQueueType.serialBackgroundThread)
List<Uint8List?> hashPaths(List<String> paths);
Map<String, String?> getCloudIdForAssetIds(List<String> assetIds);
}