1
0
mirror of https://github.com/immich-app/immich.git synced 2025-08-08 23:07:06 +02:00

Use owner instead of shared flag when fetching albums.

This commit is contained in:
Tom graham
2025-01-08 15:42:37 +11:00
parent e35465ccf3
commit a42911b290
4 changed files with 34 additions and 8 deletions

View File

@ -13,6 +13,7 @@ abstract interface class IAlbumRepository implements IDatabaseRepository {
String name, { String name, {
bool? shared, bool? shared,
bool? remote, bool? remote,
bool? owner,
}); });
Future<List<Album>> getAll({ Future<List<Album>> getAll({

View File

@ -46,8 +46,18 @@ class AlbumNotifier extends StateNotifier<List<Album>> {
) => ) =>
_albumService.createAlbum(albumTitle, assets, []); _albumService.createAlbum(albumTitle, assets, []);
Future<Album?> getAlbumByName(String albumName, {bool? remote, bool? shared}) => Future<Album?> getAlbumByName(
_albumService.getAlbumByName(albumName, remote: remote, shared: shared); String albumName, {
bool? remote,
bool? shared,
bool? owner,
}) =>
_albumService.getAlbumByName(
albumName,
remote: remote,
shared: shared,
owner: owner,
);
/// Create an album on the server with the same name as the selected album for backup /// Create an album on the server with the same name as the selected album for backup
/// First this will check if the album already exists on the server with name /// First this will check if the album already exists on the server with name
@ -55,7 +65,7 @@ class AlbumNotifier extends StateNotifier<List<Album>> {
Future<void> createSyncAlbum( Future<void> createSyncAlbum(
String albumName, String albumName,
) async { ) async {
final album = await getAlbumByName(albumName, remote: true, shared: false); final album = await getAlbumByName(albumName, remote: true, owner: true);
if (album != null) { if (album != null) {
return; return;
} }

View File

@ -34,11 +34,16 @@ class AlbumRepository extends DatabaseRepository implements IAlbumRepository {
Future<Album> create(Album album) => txn(() => db.albums.store(album)); Future<Album> create(Album album) => txn(() => db.albums.store(album));
@override @override
Future<Album?> getByName(String name, {bool? shared, bool? remote}) { Future<Album?> getByName(String name, {bool? shared, bool? remote, bool? owner}) {
var query = db.albums.filter().nameEqualTo(name); var query = db.albums.filter().nameEqualTo(name);
if (shared != null) { if (shared != null) {
query = query.sharedEqualTo(shared); query = query.sharedEqualTo(shared);
} }
if (owner == true) {
query = query.owner((q) => q.isarIdEqualTo(Store.get(StoreKey.currentUser).isarId));
} else if (owner == false) {
query = query.owner((q) => q.not().isarIdEqualTo(Store.get(StoreKey.currentUser).isarId));
}
if (remote == true) { if (remote == true) {
query = query.localIdIsNull(); query = query.localIdIsNull();
} else if (remote == false) { } else if (remote == false) {

View File

@ -212,7 +212,7 @@ class AlbumService {
for (int round = 0;; round++) { for (int round = 0;; round++) {
final proposedName = "$baseName${round == 0 ? "" : " ($round)"}"; final proposedName = "$baseName${round == 0 ? "" : " ($round)"}";
if (null == await _albumRepository.getByName(proposedName)) { if (null == await _albumRepository.getByName(proposedName, owner: true)) {
return proposedName; return proposedName;
} }
} }
@ -408,8 +408,18 @@ class AlbumService {
} }
} }
Future<Album?> getAlbumByName(String name, {bool? remote, bool? shared}) => Future<Album?> getAlbumByName(
_albumRepository.getByName(name, remote: remote, shared: shared); String name, {
bool? remote,
bool? shared,
bool? owner,
}) =>
_albumRepository.getByName(
name,
remote: remote,
shared: shared,
owner: owner,
);
/// ///
/// Add the uploaded asset to the selected albums /// Add the uploaded asset to the selected albums
@ -419,7 +429,7 @@ class AlbumService {
List<String> assetIds, List<String> assetIds,
) async { ) async {
for (final albumName in albumNames) { for (final albumName in albumNames) {
Album? album = await getAlbumByName(albumName, remote: true, shared: false); Album? album = await getAlbumByName(albumName, remote: true, owner: true);
album ??= await createAlbum(albumName, []); album ??= await createAlbum(albumName, []);
if (album != null && album.remoteId != null) { if (album != null && album.remoteId != null) {
await _albumApiRepository.addAssets(album.remoteId!, assetIds); await _albumApiRepository.addAssets(album.remoteId!, assetIds);