Skip to content

Commit 268b411

Browse files
fix: sync is_favorite from native (#20412)
* feat: sync is_favorite from native * handle favorite during upload * Update mobile/ios/Runner/Sync/MessagesImpl.swift Co-authored-by: Alex <[email protected]> --------- Co-authored-by: shenlong-tanwen <[email protected]> Co-authored-by: Alex <[email protected]>
1 parent 07ed060 commit 268b411

File tree

9 files changed

+30
-8
lines changed

9 files changed

+30
-8
lines changed

mobile/android/app/src/main/kotlin/app/alextran/immich/sync/Messages.g.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ data class PlatformAsset (
8888
val width: Long? = null,
8989
val height: Long? = null,
9090
val durationInSeconds: Long,
91-
val orientation: Long
91+
val orientation: Long,
92+
val isFavorite: Boolean
9293
)
9394
{
9495
companion object {
@@ -102,7 +103,8 @@ data class PlatformAsset (
102103
val height = pigeonVar_list[6] as Long?
103104
val durationInSeconds = pigeonVar_list[7] as Long
104105
val orientation = pigeonVar_list[8] as Long
105-
return PlatformAsset(id, name, type, createdAt, updatedAt, width, height, durationInSeconds, orientation)
106+
val isFavorite = pigeonVar_list[9] as Boolean
107+
return PlatformAsset(id, name, type, createdAt, updatedAt, width, height, durationInSeconds, orientation, isFavorite)
106108
}
107109
}
108110
fun toList(): List<Any?> {
@@ -116,6 +118,7 @@ data class PlatformAsset (
116118
height,
117119
durationInSeconds,
118120
orientation,
121+
isFavorite,
119122
)
120123
}
121124
override fun equals(other: Any?): Boolean {

mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ open class NativeSyncApiImplBase(context: Context) {
4242
MediaStore.MediaColumns.HEIGHT,
4343
MediaStore.MediaColumns.DURATION,
4444
MediaStore.MediaColumns.ORIENTATION,
45+
MediaStore.MediaColumns.IS_FAVORITE,
4546
)
4647

4748
const val HASH_BUFFER_SIZE = 2 * 1024 * 1024
@@ -77,6 +78,7 @@ open class NativeSyncApiImplBase(context: Context) {
7778
val durationColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.DURATION)
7879
val orientationColumn =
7980
c.getColumnIndexOrThrow(MediaStore.MediaColumns.ORIENTATION)
81+
val favoriteColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.IS_FAVORITE)
8082

8183
while (c.moveToNext()) {
8284
val id = c.getLong(idColumn).toString()
@@ -105,6 +107,7 @@ open class NativeSyncApiImplBase(context: Context) {
105107
else c.getLong(durationColumn) / 1000
106108
val bucketId = c.getString(bucketIdColumn)
107109
val orientation = c.getInt(orientationColumn)
110+
val isFavorite = c.getInt(favoriteColumn) != 0;
108111

109112
val asset = PlatformAsset(
110113
id,
@@ -116,6 +119,7 @@ open class NativeSyncApiImplBase(context: Context) {
116119
height,
117120
duration,
118121
orientation.toLong(),
122+
isFavorite,
119123
)
120124
yield(AssetResult.ValidAsset(asset, bucketId))
121125
}

mobile/ios/Runner/Sync/Messages.g.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct PlatformAsset: Hashable {
139139
var height: Int64? = nil
140140
var durationInSeconds: Int64
141141
var orientation: Int64
142+
var isFavorite: Bool
142143

143144

144145
// swift-format-ignore: AlwaysUseLowerCamelCase
@@ -152,6 +153,7 @@ struct PlatformAsset: Hashable {
152153
let height: Int64? = nilOrValue(pigeonVar_list[6])
153154
let durationInSeconds = pigeonVar_list[7] as! Int64
154155
let orientation = pigeonVar_list[8] as! Int64
156+
let isFavorite = pigeonVar_list[9] as! Bool
155157

156158
return PlatformAsset(
157159
id: id,
@@ -162,7 +164,8 @@ struct PlatformAsset: Hashable {
162164
width: width,
163165
height: height,
164166
durationInSeconds: durationInSeconds,
165-
orientation: orientation
167+
orientation: orientation,
168+
isFavorite: isFavorite
166169
)
167170
}
168171
func toList() -> [Any?] {
@@ -176,6 +179,7 @@ struct PlatformAsset: Hashable {
176179
height,
177180
durationInSeconds,
178181
orientation,
182+
isFavorite,
179183
]
180184
}
181185
static func == (lhs: PlatformAsset, rhs: PlatformAsset) -> Bool {

mobile/ios/Runner/Sync/MessagesImpl.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ extension PHAsset {
2828
width: Int64(pixelWidth),
2929
height: Int64(pixelHeight),
3030
durationInSeconds: Int64(duration),
31-
orientation: 0
31+
orientation: 0,
32+
isFavorite: isFavorite
3233
)
3334
}
3435
}

mobile/lib/domain/services/local_sync.service.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ extension on Iterable<PlatformAsset> {
312312
height: e.height,
313313
durationInSeconds: e.durationInSeconds,
314314
orientation: e.orientation,
315+
isFavorite: e.isFavorite,
315316
),
316317
).toList();
317318
}

mobile/lib/infrastructure/repositories/local_album.repository.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ class DriftLocalAlbumRepository extends DriftDatabaseRepository {
236236
id: asset.id,
237237
orientation: Value(asset.orientation),
238238
checksum: const Value(null),
239+
isFavorite: Value(asset.isFavorite),
239240
);
240241
batch.insert<$LocalAssetEntityTable, LocalAssetEntityData>(
241242
_db.localAssetEntity,

mobile/lib/platform/native_sync_api.g.dart

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile/lib/services/upload.service.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class UploadService {
247247
metadata: metadata,
248248
group: group,
249249
priority: priority,
250+
isFavorite: asset.isFavorite,
250251
);
251252
}
252253

@@ -270,6 +271,7 @@ class UploadService {
270271
fields: fields,
271272
group: kBackupLivePhotoGroup,
272273
priority: 0, // Highest priority to get upload immediately
274+
isFavorite: asset.isFavorite,
273275
);
274276
}
275277

@@ -281,6 +283,7 @@ class UploadService {
281283
String? deviceAssetId,
282284
String? metadata,
283285
int? priority,
286+
bool? isFavorite,
284287
}) async {
285288
final serverEndpoint = Store.get(StoreKey.serverEndpoint);
286289
final url = Uri.parse('$serverEndpoint/assets').toString();
@@ -297,7 +300,7 @@ class UploadService {
297300
'deviceId': deviceId,
298301
'fileCreatedAt': fileCreatedAt.toUtc().toIso8601String(),
299302
'fileModifiedAt': fileModifiedAt.toUtc().toIso8601String(),
300-
'isFavorite': 'false',
303+
'isFavorite': isFavorite?.toString() ?? 'false',
301304
'duration': '0',
302305
if (fields != null) ...fields,
303306
};

mobile/pigeon/native_sync_api.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import 'package:pigeon/pigeon.dart';
55
dartOut: 'lib/platform/native_sync_api.g.dart',
66
swiftOut: 'ios/Runner/Sync/Messages.g.swift',
77
swiftOptions: SwiftOptions(),
8-
kotlinOut:
9-
'android/app/src/main/kotlin/app/alextran/immich/sync/Messages.g.kt',
8+
kotlinOut: 'android/app/src/main/kotlin/app/alextran/immich/sync/Messages.g.kt',
109
kotlinOptions: KotlinOptions(package: 'app.alextran.immich.sync'),
1110
dartOptions: DartOptions(),
1211
dartPackageName: 'immich_mobile',
@@ -24,6 +23,7 @@ class PlatformAsset {
2423
final int? height;
2524
final int durationInSeconds;
2625
final int orientation;
26+
final bool isFavorite;
2727

2828
const PlatformAsset({
2929
required this.id,
@@ -35,6 +35,7 @@ class PlatformAsset {
3535
this.height,
3636
this.durationInSeconds = 0,
3737
this.orientation = 0,
38+
this.isFavorite = false,
3839
});
3940
}
4041

0 commit comments

Comments
 (0)