mirror of
				https://github.com/immich-app/immich.git
				synced 2025-10-31 10:37:11 -04:00 
			
		
		
		
	fix: show only owned assets in places and map (#22585)
Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									950f268cb0
								
							
						
					
					
						commit
						a2b25b7a74
					
				| @ -84,8 +84,8 @@ class AssetService { | ||||
|     return 1.0; | ||||
|   } | ||||
| 
 | ||||
|   Future<List<(String, String)>> getPlaces() { | ||||
|     return _remoteAssetRepository.getPlaces(); | ||||
|   Future<List<(String, String)>> getPlaces(String userId) { | ||||
|     return _remoteAssetRepository.getPlaces(userId); | ||||
|   } | ||||
| 
 | ||||
|   Future<(int local, int remote)> getAssetCounts() async { | ||||
|  | ||||
| @ -59,7 +59,8 @@ class TimelineFactory { | ||||
| 
 | ||||
|   TimelineService fromAssets(List<BaseAsset> assets) => TimelineService(_timelineRepository.fromAssets(assets)); | ||||
| 
 | ||||
|   TimelineService map(LatLngBounds bounds) => TimelineService(_timelineRepository.map(bounds, groupBy)); | ||||
|   TimelineService map(String userId, LatLngBounds bounds) => | ||||
|       TimelineService(_timelineRepository.map(userId, bounds, groupBy)); | ||||
| } | ||||
| 
 | ||||
| class TimelineService { | ||||
|  | ||||
| @ -81,9 +81,11 @@ class RemoteAssetRepository extends DriftDatabaseRepository { | ||||
|         .getSingleOrNull(); | ||||
|   } | ||||
| 
 | ||||
|   Future<List<(String, String)>> getPlaces() { | ||||
|   Future<List<(String, String)>> getPlaces(String userId) { | ||||
|     final asset = Subquery( | ||||
|       _db.remoteAssetEntity.select()..orderBy([(row) => OrderingTerm.desc(row.createdAt)]), | ||||
|       _db.remoteAssetEntity.select() | ||||
|         ..where((row) => row.ownerId.equals(userId)) | ||||
|         ..orderBy([(row) => OrderingTerm.desc(row.createdAt)]), | ||||
|       "asset", | ||||
|     ); | ||||
| 
 | ||||
|  | ||||
| @ -431,12 +431,16 @@ class DriftTimelineRepository extends DriftDatabaseRepository { | ||||
|     return query.map((row) => row.readTable(_db.remoteAssetEntity).toDto()).get(); | ||||
|   } | ||||
| 
 | ||||
|   TimelineQuery map(LatLngBounds bounds, GroupAssetsBy groupBy) => ( | ||||
|     bucketSource: () => _watchMapBucket(bounds, groupBy: groupBy), | ||||
|     assetSource: (offset, count) => _getMapBucketAssets(bounds, offset: offset, count: count), | ||||
|   TimelineQuery map(String userId, LatLngBounds bounds, GroupAssetsBy groupBy) => ( | ||||
|     bucketSource: () => _watchMapBucket(userId, bounds, groupBy: groupBy), | ||||
|     assetSource: (offset, count) => _getMapBucketAssets(userId, bounds, offset: offset, count: count), | ||||
|   ); | ||||
| 
 | ||||
|   Stream<List<Bucket>> _watchMapBucket(LatLngBounds bounds, {GroupAssetsBy groupBy = GroupAssetsBy.day}) { | ||||
|   Stream<List<Bucket>> _watchMapBucket( | ||||
|     String userId, | ||||
|     LatLngBounds bounds, { | ||||
|     GroupAssetsBy groupBy = GroupAssetsBy.day, | ||||
|   }) { | ||||
|     if (groupBy == GroupAssetsBy.none) { | ||||
|       // TODO: Support GroupAssetsBy.none | ||||
|       throw UnsupportedError("GroupAssetsBy.none is not supported for _watchMapBucket"); | ||||
| @ -455,7 +459,8 @@ class DriftTimelineRepository extends DriftDatabaseRepository { | ||||
|         ), | ||||
|       ]) | ||||
|       ..where( | ||||
|         _db.remoteExifEntity.inBounds(bounds) & | ||||
|         _db.remoteAssetEntity.ownerId.equals(userId) & | ||||
|             _db.remoteExifEntity.inBounds(bounds) & | ||||
|             _db.remoteAssetEntity.visibility.equalsValue(AssetVisibility.timeline) & | ||||
|             _db.remoteAssetEntity.deletedAt.isNull(), | ||||
|       ) | ||||
| @ -469,7 +474,12 @@ class DriftTimelineRepository extends DriftDatabaseRepository { | ||||
|     }).watch(); | ||||
|   } | ||||
| 
 | ||||
|   Future<List<BaseAsset>> _getMapBucketAssets(LatLngBounds bounds, {required int offset, required int count}) { | ||||
|   Future<List<BaseAsset>> _getMapBucketAssets( | ||||
|     String userId, | ||||
|     LatLngBounds bounds, { | ||||
|     required int offset, | ||||
|     required int count, | ||||
|   }) { | ||||
|     final query = | ||||
|         _db.remoteAssetEntity.select().join([ | ||||
|             innerJoin( | ||||
| @ -479,7 +489,8 @@ class DriftTimelineRepository extends DriftDatabaseRepository { | ||||
|             ), | ||||
|           ]) | ||||
|           ..where( | ||||
|             _db.remoteExifEntity.inBounds(bounds) & | ||||
|             _db.remoteAssetEntity.ownerId.equals(userId) & | ||||
|                 _db.remoteExifEntity.inBounds(bounds) & | ||||
|                 _db.remoteAssetEntity.visibility.equalsValue(AssetVisibility.timeline) & | ||||
|                 _db.remoteAssetEntity.deletedAt.isNull(), | ||||
|           ) | ||||
|  | ||||
| @ -5,6 +5,7 @@ import 'package:immich_mobile/presentation/widgets/bottom_sheet/base_bottom_shee | ||||
| import 'package:immich_mobile/presentation/widgets/map/map.state.dart'; | ||||
| import 'package:immich_mobile/presentation/widgets/timeline/timeline.widget.dart'; | ||||
| import 'package:immich_mobile/providers/infrastructure/timeline.provider.dart'; | ||||
| import 'package:immich_mobile/providers/user.provider.dart'; | ||||
| 
 | ||||
| class MapBottomSheet extends StatelessWidget { | ||||
|   const MapBottomSheet({super.key}); | ||||
| @ -32,8 +33,13 @@ class _ScopedMapTimeline extends StatelessWidget { | ||||
|     return ProviderScope( | ||||
|       overrides: [ | ||||
|         timelineServiceProvider.overrideWith((ref) { | ||||
|           final user = ref.watch(currentUserProvider); | ||||
|           if (user == null) { | ||||
|             throw Exception('User must be logged in to access archive'); | ||||
|           } | ||||
| 
 | ||||
|           final bounds = ref.watch(mapStateProvider).bounds; | ||||
|           final timelineService = ref.watch(timelineFactoryProvider).map(bounds); | ||||
|           final timelineService = ref.watch(timelineFactoryProvider).map(user.id, bounds); | ||||
|           ref.onDispose(timelineService.dispose); | ||||
|           return timelineService; | ||||
|         }), | ||||
|  | ||||
| @ -3,6 +3,7 @@ import 'package:immich_mobile/domain/services/asset.service.dart'; | ||||
| import 'package:immich_mobile/infrastructure/repositories/local_asset.repository.dart'; | ||||
| import 'package:immich_mobile/infrastructure/repositories/remote_asset.repository.dart'; | ||||
| import 'package:immich_mobile/providers/infrastructure/db.provider.dart'; | ||||
| import 'package:immich_mobile/providers/user.provider.dart'; | ||||
| 
 | ||||
| final localAssetRepository = Provider<DriftLocalAssetRepository>( | ||||
|   (ref) => DriftLocalAssetRepository(ref.watch(driftProvider)), | ||||
| @ -19,9 +20,13 @@ final assetServiceProvider = Provider( | ||||
|   ), | ||||
| ); | ||||
| 
 | ||||
| final placesProvider = FutureProvider<List<(String, String)>>( | ||||
|   (ref) => AssetService( | ||||
|     remoteAssetRepository: ref.watch(remoteAssetRepositoryProvider), | ||||
|     localAssetRepository: ref.watch(localAssetRepository), | ||||
|   ).getPlaces(), | ||||
| ); | ||||
| final placesProvider = FutureProvider<List<(String, String)>>((ref) { | ||||
|   final assetService = ref.watch(assetServiceProvider); | ||||
|   final auth = ref.watch(currentUserProvider); | ||||
| 
 | ||||
|   if (auth == null) { | ||||
|     return Future.value(const []); | ||||
|   } | ||||
| 
 | ||||
|   return assetService.getPlaces(auth.id); | ||||
| }); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user