mirror of
https://github.com/immich-app/immich.git
synced 2025-12-28 09:14:59 +03:00
refactor(mobile): album api repository for album service (#12791)
* refactor(mobile): album api repository for album service
This commit is contained in:
committed by
GitHub
parent
94fc1f213a
commit
3868736799
@@ -3,6 +3,8 @@ import 'package:immich_mobile/entities/asset.entity.dart';
|
||||
import 'package:immich_mobile/entities/user.entity.dart';
|
||||
import 'package:immich_mobile/utils/datetime_comparison.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
// ignore: implementation_imports
|
||||
import 'package:isar/src/common/isar_links_common.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
part 'album.entity.g.dart';
|
||||
@@ -23,6 +25,7 @@ class Album {
|
||||
required this.activityEnabled,
|
||||
});
|
||||
|
||||
// fields stored in DB
|
||||
Id id = Isar.autoIncrement;
|
||||
@Index(unique: false, replace: false, type: IndexType.hash)
|
||||
String? remoteId;
|
||||
@@ -41,9 +44,17 @@ class Album {
|
||||
final IsarLinks<User> sharedUsers = IsarLinks<User>();
|
||||
final IsarLinks<Asset> assets = IsarLinks<Asset>();
|
||||
|
||||
// transient fields
|
||||
@ignore
|
||||
bool isAll = false;
|
||||
|
||||
@ignore
|
||||
String? remoteThumbnailAssetId;
|
||||
|
||||
@ignore
|
||||
int remoteAssetCount = 0;
|
||||
|
||||
// getters
|
||||
@ignore
|
||||
bool get isRemote => remoteId != null;
|
||||
|
||||
@@ -74,6 +85,18 @@ class Album {
|
||||
@ignore
|
||||
String get eTagKeyAssetCount => "device-album-$localId-asset-count";
|
||||
|
||||
// the following getter are needed because Isar links do not make data
|
||||
// accessible in an object freshly created (not loaded from DB)
|
||||
|
||||
@ignore
|
||||
Iterable<User> get remoteUsers => sharedUsers.isEmpty
|
||||
? (sharedUsers as IsarLinksCommon<User>).addedObjects
|
||||
: sharedUsers;
|
||||
|
||||
@ignore
|
||||
Iterable<Asset> get remoteAssets =>
|
||||
assets.isEmpty ? (assets as IsarLinksCommon<Asset>).addedObjects : assets;
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
if (other is! Album) return false;
|
||||
@@ -129,6 +152,7 @@ class Album {
|
||||
endDate: dto.endDate,
|
||||
activityEnabled: dto.isActivityEnabled,
|
||||
);
|
||||
a.remoteAssetCount = dto.assetCount;
|
||||
a.owner.value = await db.users.getById(dto.ownerId);
|
||||
if (dto.albumThumbnailAssetId != null) {
|
||||
a.thumbnail.value = await db.assets
|
||||
@@ -164,7 +188,3 @@ extension AssetsHelper on IsarCollection<Album> {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
extension AlbumResponseDtoHelper on AlbumResponseDto {
|
||||
List<Asset> getAssets() => assets.map(Asset.remote).toList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user