Skip to content

High performance self-hosted photo and video management solution.

fix(mobile): 14983 Images upload to shared album with common name (#15127)

Tom Grahamefbc0cb1928b
diff --git a/mobile/lib/interfaces/album.interface.dart b/mobile/lib/interfaces/album.interface.dart
index bdf11f18de..cabf2dee53 100644
--- a/mobile/lib/interfaces/album.interface.dart
+++ b/mobile/lib/interfaces/album.interface.dart
@@ -13,6 +13,7 @@ abstract interface class IAlbumRepository implements IDatabaseRepository {
String name, {
bool? shared,
bool? remote,
+ bool? owner,
});
Future<List<Album>> getAll({
diff --git a/mobile/lib/providers/album/album.provider.dart b/mobile/lib/providers/album/album.provider.dart
index b3d619a815..8c06faaa6a 100644
--- a/mobile/lib/providers/album/album.provider.dart
+++ b/mobile/lib/providers/album/album.provider.dart
@@ -46,8 +46,18 @@ class AlbumNotifier extends StateNotifier<List<Album>> {
) =>
_albumService.createAlbum(albumTitle, assets, []);
- Future<Album?> getAlbumByName(String albumName, {bool remoteOnly = false}) =>
- _albumService.getAlbumByName(albumName, remoteOnly);
+ Future<Album?> getAlbumByName(
+ 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
/// 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(
String albumName,
) async {
- final album = await getAlbumByName(albumName, remoteOnly: true);
+ final album = await getAlbumByName(albumName, remote: true, owner: true);
if (album != null) {
return;
}
diff --git a/mobile/lib/repositories/album.repository.dart b/mobile/lib/repositories/album.repository.dart
index 2c78e4c238..adf83b33d4 100644
--- a/mobile/lib/repositories/album.repository.dart
+++ b/mobile/lib/repositories/album.repository.dart
@@ -34,11 +34,25 @@ class AlbumRepository extends DatabaseRepository implements IAlbumRepository {
Future<Album> create(Album album) => txn(() => db.albums.store(album));
@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);
if (shared != null) {
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) {
query = query.localIdIsNull();
} else if (remote == false) {
diff --git a/mobile/lib/services/album.service.dart b/mobile/lib/services/album.service.dart
index 5f013c0e53..a993705e11 100644
--- a/mobile/lib/services/album.service.dart
+++ b/mobile/lib/services/album.service.dart
@@ -170,7 +170,12 @@ class AlbumService {
try {
await _userService.refreshUsers();
final (sharedAlbum, ownedAlbum) = await (
+ // Note: `shared: true` is required to get albums that don't belong to
+ // us due to unusual behaviour on the API but this will also return our
+ // own shared albums
_albumApiRepository.getAll(shared: true),
+ // Passing null (or nothing) for `shared` returns only albums that
+ // explicitly belong to us
_albumApiRepository.getAll(shared: null)
).wait;
@@ -212,7 +217,7 @@ class AlbumService {
for (int 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;
}
}
@@ -408,8 +413,18 @@ class AlbumService {
}
}
- Future<Album?> getAlbumByName(String name, bool remoteOnly) =>
- _albumRepository.getByName(name, remote: remoteOnly ? true : null);
+ Future<Album?> getAlbumByName(
+ 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
@@ -419,7 +434,7 @@ class AlbumService {
List<String> assetIds,
) async {
for (final albumName in albumNames) {
- Album? album = await getAlbumByName(albumName, true);
+ Album? album = await getAlbumByName(albumName, remote: true, owner: true);
album ??= await createAlbum(albumName, []);
if (album != null && album.remoteId != null) {
await _albumApiRepository.addAssets(album.remoteId!, assetIds);