2025-07-10 11:59:15 -05:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
|
import 'package:immich_mobile/domain/models/album/album.model.dart';
|
2026-04-22 16:52:23 +02:00
|
|
|
import 'package:immich_mobile/domain/models/user.model.dart';
|
2025-07-10 11:59:15 -05:00
|
|
|
import 'package:immich_mobile/providers/api.provider.dart';
|
|
|
|
|
import 'package:immich_mobile/repositories/api.repository.dart';
|
|
|
|
|
// ignore: import_rule_openapi
|
2026-04-22 16:52:23 +02:00
|
|
|
import 'package:openapi/api.dart' hide AlbumUserRole;
|
2025-07-10 11:59:15 -05:00
|
|
|
|
|
|
|
|
final driftAlbumApiRepositoryProvider = Provider(
|
|
|
|
|
(ref) => DriftAlbumApiRepository(ref.watch(apiServiceProvider).albumsApi),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
class DriftAlbumApiRepository extends ApiRepository {
|
|
|
|
|
final AlbumsApi _api;
|
|
|
|
|
|
|
|
|
|
DriftAlbumApiRepository(this._api);
|
|
|
|
|
|
2026-04-22 16:52:23 +02:00
|
|
|
Future<RemoteAlbum> createDriftAlbum(
|
|
|
|
|
String name,
|
|
|
|
|
UserDto owner, {
|
|
|
|
|
required Iterable<String> assetIds,
|
|
|
|
|
String? description,
|
|
|
|
|
}) async {
|
2025-07-10 11:59:15 -05:00
|
|
|
final responseDto = await checkNull(
|
2026-06-03 14:13:17 +02:00
|
|
|
_api.createAlbum(
|
|
|
|
|
CreateAlbumDto(
|
|
|
|
|
albumName: name,
|
|
|
|
|
description: description == null ? const Optional.absent() : Optional.present(description),
|
|
|
|
|
assetIds: Optional.present(assetIds.toList()),
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-07-10 11:59:15 -05:00
|
|
|
);
|
|
|
|
|
|
2026-04-22 16:52:23 +02:00
|
|
|
return responseDto.toRemoteAlbum(owner);
|
2025-07-10 11:59:15 -05:00
|
|
|
}
|
2025-07-11 10:06:53 -05:00
|
|
|
|
2025-07-29 00:34:03 +05:30
|
|
|
Future<({List<String> removed, List<String> failed})> removeAssets(String albumId, Iterable<String> assetIds) async {
|
|
|
|
|
final response = await checkNull(_api.removeAssetFromAlbum(albumId, BulkIdsDto(ids: assetIds.toList())));
|
2025-07-11 10:06:53 -05:00
|
|
|
final List<String> removed = [], failed = [];
|
|
|
|
|
for (final dto in response) {
|
|
|
|
|
if (dto.success) {
|
|
|
|
|
removed.add(dto.id);
|
|
|
|
|
} else {
|
|
|
|
|
failed.add(dto.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (removed: removed, failed: failed);
|
|
|
|
|
}
|
2025-07-15 20:37:44 -05:00
|
|
|
|
2026-06-03 08:16:19 -04:00
|
|
|
Future<({List<String> added, List<String> failed})> addAssets(
|
|
|
|
|
String albumId,
|
|
|
|
|
Iterable<String> assetIds, {
|
|
|
|
|
Future<void>? abortTrigger,
|
|
|
|
|
}) async {
|
|
|
|
|
final response = await checkNull(
|
|
|
|
|
_api.addAssetsToAlbum(albumId, BulkIdsDto(ids: assetIds.toList()), abortTrigger: abortTrigger),
|
|
|
|
|
);
|
2025-07-15 20:37:44 -05:00
|
|
|
final List<String> added = [], failed = [];
|
|
|
|
|
for (final dto in response) {
|
|
|
|
|
if (dto.success) {
|
|
|
|
|
added.add(dto.id);
|
|
|
|
|
} else {
|
|
|
|
|
failed.add(dto.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (added: added, failed: failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<RemoteAlbum> updateAlbum(
|
2026-04-22 16:52:23 +02:00
|
|
|
String albumId,
|
|
|
|
|
UserDto owner, {
|
2025-07-15 20:37:44 -05:00
|
|
|
String? name,
|
|
|
|
|
String? description,
|
|
|
|
|
String? thumbnailAssetId,
|
|
|
|
|
bool? isActivityEnabled,
|
|
|
|
|
AlbumAssetOrder? order,
|
|
|
|
|
}) async {
|
|
|
|
|
AssetOrder? apiOrder;
|
|
|
|
|
if (order != null) {
|
2025-07-25 08:07:22 +05:30
|
|
|
apiOrder = order == AlbumAssetOrder.asc ? AssetOrder.asc : AssetOrder.desc;
|
2025-07-15 20:37:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final responseDto = await checkNull(
|
|
|
|
|
_api.updateAlbumInfo(
|
|
|
|
|
albumId,
|
|
|
|
|
UpdateAlbumDto(
|
2026-06-03 14:13:17 +02:00
|
|
|
albumName: name == null ? const Optional.absent() : Optional.present(name),
|
|
|
|
|
description: description == null ? const Optional.absent() : Optional.present(description),
|
|
|
|
|
albumThumbnailAssetId: thumbnailAssetId == null
|
|
|
|
|
? const Optional.absent()
|
|
|
|
|
: Optional.present(thumbnailAssetId),
|
|
|
|
|
isActivityEnabled: isActivityEnabled == null ? const Optional.absent() : Optional.present(isActivityEnabled),
|
|
|
|
|
order: apiOrder == null ? const Optional.absent() : Optional.present(apiOrder),
|
2025-07-15 20:37:44 -05:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
2026-04-22 16:52:23 +02:00
|
|
|
return responseDto.toRemoteAlbum(owner);
|
2025-07-15 20:37:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> deleteAlbum(String albumId) {
|
|
|
|
|
return _api.deleteAlbum(albumId);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 16:52:23 +02:00
|
|
|
Future<void> addUsers(String albumId, Iterable<String> userIds) async {
|
2025-07-25 08:07:22 +05:30
|
|
|
final albumUsers = userIds.map((userId) => AlbumUserAddDto(userId: userId)).toList();
|
2026-04-22 16:52:23 +02:00
|
|
|
await checkNull(_api.addUsersToAlbum(albumId, AddUsersDto(albumUsers: albumUsers)));
|
2025-07-15 20:37:44 -05:00
|
|
|
}
|
2025-08-05 10:31:58 -05:00
|
|
|
|
|
|
|
|
Future<void> removeUser(String albumId, {required String userId}) async {
|
|
|
|
|
await _api.removeUserFromAlbum(albumId, userId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> setActivityStatus(String albumId, bool isEnabled) async {
|
2026-06-03 14:13:17 +02:00
|
|
|
final response = await checkNull(
|
|
|
|
|
_api.updateAlbumInfo(albumId, UpdateAlbumDto(isActivityEnabled: Optional.present(isEnabled))),
|
|
|
|
|
);
|
2025-08-05 10:31:58 -05:00
|
|
|
return response.isActivityEnabled;
|
|
|
|
|
}
|
2025-07-10 11:59:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension on AlbumResponseDto {
|
2026-04-22 16:52:23 +02:00
|
|
|
RemoteAlbum toRemoteAlbum(final UserDto user) {
|
2025-07-10 11:59:15 -05:00
|
|
|
return RemoteAlbum(
|
|
|
|
|
id: id,
|
|
|
|
|
name: albumName,
|
2026-04-22 16:52:23 +02:00
|
|
|
ownerId: user.id,
|
|
|
|
|
ownerName: user.name,
|
2025-07-10 11:59:15 -05:00
|
|
|
description: description,
|
|
|
|
|
createdAt: createdAt,
|
|
|
|
|
updatedAt: updatedAt,
|
|
|
|
|
thumbnailAssetId: albumThumbnailAssetId,
|
|
|
|
|
isActivityEnabled: isActivityEnabled,
|
2026-06-03 14:13:17 +02:00
|
|
|
order: order.orElse(null) == AssetOrder.asc ? AlbumAssetOrder.asc : AlbumAssetOrder.desc,
|
2025-07-10 11:59:15 -05:00
|
|
|
assetCount: assetCount,
|
2025-08-14 17:50:56 -05:00
|
|
|
isShared: albumUsers.length > 2,
|
2025-07-10 11:59:15 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|