diff --git a/mobile/lib/domain/services/remote_album.service.dart b/mobile/lib/domain/services/remote_album.service.dart index cc28dfafd5..13dfadb8d8 100644 --- a/mobile/lib/domain/services/remote_album.service.dart +++ b/mobile/lib/domain/services/remote_album.service.dart @@ -120,6 +120,10 @@ class RemoteAlbumService { return _repository.getSharedUsers(albumId); } + Future getUserRole(String albumId, String userId) { + return _repository.getUserRole(albumId, userId); + } + Future> getAssets(String albumId) { return _repository.getAssets(albumId); } diff --git a/mobile/lib/infrastructure/repositories/remote_album.repository.dart b/mobile/lib/infrastructure/repositories/remote_album.repository.dart index 5dfe4ac9b3..6f83295620 100644 --- a/mobile/lib/infrastructure/repositories/remote_album.repository.dart +++ b/mobile/lib/infrastructure/repositories/remote_album.repository.dart @@ -221,6 +221,15 @@ class DriftRemoteAlbumRepository extends DriftDatabaseRepository { .get(); } + Future getUserRole(String albumId, String userId) async { + final query = _db.remoteAlbumUserEntity.select() + ..where((row) => row.albumId.equals(albumId) & row.userId.equals(userId)) + ..limit(1); + + final result = await query.getSingleOrNull(); + return result?.role; + } + Future> getAssets(String albumId) { final query = _db.remoteAlbumAssetEntity.select().join([ innerJoin(_db.remoteAssetEntity, _db.remoteAssetEntity.id.equalsExp(_db.remoteAlbumAssetEntity.assetId)), diff --git a/mobile/lib/presentation/pages/drift_remote_album.page.dart b/mobile/lib/presentation/pages/drift_remote_album.page.dart index e6f1bf108e..e306b8cbd3 100644 --- a/mobile/lib/presentation/pages/drift_remote_album.page.dart +++ b/mobile/lib/presentation/pages/drift_remote_album.page.dart @@ -169,9 +169,10 @@ class _RemoteAlbumPageState extends ConsumerState { context.pushRoute(const DriftActivitiesRoute()); } - void showOptionSheet(BuildContext context) { + Future showOptionSheet(BuildContext context) async { final user = ref.watch(currentUserProvider); final isOwner = user != null ? user.id == _album.ownerId : false; + final canEdit = await ref.read(remoteAlbumUserRoleProvider((_album.id, user!.id)).future) == AlbumUserRole.editor; showModalBottomSheet( context: context, @@ -193,10 +194,12 @@ class _RemoteAlbumPageState extends ConsumerState { context.pop(); } : null, - onAddPhotos: () async { - await addAssets(context); - context.pop(); - }, + onAddPhotos: isOwner || canEdit + ? () async { + await addAssets(context); + context.pop(); + } + : null, onToggleAlbumOrder: () async { await toggleAlbumOrder(); context.pop(); diff --git a/mobile/lib/providers/infrastructure/remote_album.provider.dart b/mobile/lib/providers/infrastructure/remote_album.provider.dart index 38ba52dc56..ffdbe8aa36 100644 --- a/mobile/lib/providers/infrastructure/remote_album.provider.dart +++ b/mobile/lib/providers/infrastructure/remote_album.provider.dart @@ -178,3 +178,13 @@ final remoteAlbumSharedUsersProvider = FutureProvider.autoDispose.family(( + ref, + data, +) async { + final link = ref.keepAlive(); + ref.onDispose(() => link.close()); + final service = ref.watch(remoteAlbumServiceProvider); + return service.getUserRole(data.$1, data.$2); +});