optimize, refactor code

remove redundant code and checking
getTrashedAssetsForAlbum for iOS
tests for hash trashed assets
This commit is contained in:
Peter Ombodi 2025-10-06 11:41:34 +03:00
parent 3839e72028
commit 3eb2bf0342
24 changed files with 393 additions and 793 deletions

View file

@ -41,8 +41,6 @@ class PlatformAsset {
required this.durationInSeconds,
required this.orientation,
required this.isFavorite,
this.isTrashed,
this.volume,
});
String id;
@ -65,25 +63,8 @@ class PlatformAsset {
bool isFavorite;
bool? isTrashed;
String? volume;
List<Object?> _toList() {
return <Object?>[
id,
name,
type,
createdAt,
updatedAt,
width,
height,
durationInSeconds,
orientation,
isFavorite,
isTrashed,
volume,
];
return <Object?>[id, name, type, createdAt, updatedAt, width, height, durationInSeconds, orientation, isFavorite];
}
Object encode() {
@ -103,8 +84,6 @@ class PlatformAsset {
durationInSeconds: result[7]! as int,
orientation: result[8]! as int,
isFavorite: result[9]! as bool,
isTrashed: result[10] as bool?,
volume: result[11] as String?,
);
}
@ -265,45 +244,6 @@ class HashResult {
int get hashCode => Object.hashAll(_toList());
}
class TrashedAssetParams {
TrashedAssetParams({required this.id, required this.type, this.albumId});
String id;
int type;
String? albumId;
List<Object?> _toList() {
return <Object?>[id, type, albumId];
}
Object encode() {
return _toList();
}
static TrashedAssetParams decode(Object result) {
result as List<Object?>;
return TrashedAssetParams(id: result[0]! as String, type: result[1]! as int, albumId: result[2] as String?);
}
@override
// ignore: avoid_equals_and_hash_code_on_mutable_classes
bool operator ==(Object other) {
if (other is! TrashedAssetParams || other.runtimeType != runtimeType) {
return false;
}
if (identical(this, other)) {
return true;
}
return _deepEquals(encode(), other.encode());
}
@override
// ignore: avoid_equals_and_hash_code_on_mutable_classes
int get hashCode => Object.hashAll(_toList());
}
class _PigeonCodec extends StandardMessageCodec {
const _PigeonCodec();
@override
@ -323,9 +263,6 @@ class _PigeonCodec extends StandardMessageCodec {
} else if (value is HashResult) {
buffer.putUint8(132);
writeValue(buffer, value.encode());
} else if (value is TrashedAssetParams) {
buffer.putUint8(133);
writeValue(buffer, value.encode());
} else {
super.writeValue(buffer, value);
}
@ -342,8 +279,6 @@ class _PigeonCodec extends StandardMessageCodec {
return SyncDelta.decode(readValue(buffer)!);
case 132:
return HashResult.decode(readValue(buffer)!);
case 133:
return TrashedAssetParams.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
}
@ -655,32 +590,4 @@ class NativeSyncApi {
return (pigeonVar_replyList[0] as List<Object?>?)!.cast<PlatformAsset>();
}
}
Future<List<HashResult>> hashTrashedAssets(List<TrashedAssetParams> trashedAssets) async {
final String pigeonVar_channelName =
'dev.flutter.pigeon.immich_mobile.NativeSyncApi.hashTrashedAssets$pigeonVar_messageChannelSuffix';
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[trashedAssets]);
final List<Object?>? pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else if (pigeonVar_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (pigeonVar_replyList[0] as List<Object?>?)!.cast<HashResult>();
}
}
}