Skip to content

High performance self-hosted photo and video management solution.

feat(mobile): drift favorite page (#19783)

Daimoleand149d6fa3f13
diff --git a/mobile/lib/domain/services/timeline.service.dart b/mobile/lib/domain/services/timeline.service.dart
index 2e56e6e10c..7e2c586b28 100644
--- a/mobile/lib/domain/services/timeline.service.dart
+++ b/mobile/lib/domain/services/timeline.service.dart
@@ -54,6 +54,13 @@ class TimelineFactory {
_timelineRepository.watchRemoteBucket(albumId, groupBy: groupBy),
);
+ TimelineService favorite(String userId) => TimelineService(
+ assetSource: (offset, count) => _timelineRepository
+ .getFavoriteBucketAssets(userId, offset: offset, count: count),
+ bucketSource: () =>
+ _timelineRepository.watchFavoriteBucket(userId, groupBy: groupBy),
+ );
+
TimelineService trash(String userId) => TimelineService(
assetSource: (offset, count) => _timelineRepository
.getTrashBucketAssets(userId, offset: offset, count: count),
diff --git a/mobile/lib/infrastructure/repositories/timeline.repository.dart b/mobile/lib/infrastructure/repositories/timeline.repository.dart
index 45e2c5dac9..a40b4f950a 100644
--- a/mobile/lib/infrastructure/repositories/timeline.repository.dart
+++ b/mobile/lib/infrastructure/repositories/timeline.repository.dart
@@ -214,6 +214,54 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
.get();
}
+ Stream<List<Bucket>> watchFavoriteBucket(
+ String userId, {
+ GroupAssetsBy groupBy = GroupAssetsBy.day,
+ }) {
+ if (groupBy == GroupAssetsBy.none) {
+ return _db.remoteAssetEntity
+ .count(
+ where: (row) =>
+ row.isFavorite.equals(true) & row.ownerId.equals(userId),
+ )
+ .map(_generateBuckets)
+ .watchSingle();
+ }
+
+ final assetCountExp = _db.remoteAssetEntity.id.count();
+ final dateExp = _db.remoteAssetEntity.createdAt.dateFmt(groupBy);
+
+ final query = _db.remoteAssetEntity.selectOnly()
+ ..addColumns([assetCountExp, dateExp])
+ ..where(
+ _db.remoteAssetEntity.ownerId.equals(userId) &
+ _db.remoteAssetEntity.isFavorite.equals(true),
+ )
+ ..groupBy([dateExp])
+ ..orderBy([OrderingTerm.desc(dateExp)]);
+
+ return query.map((row) {
+ final timeline = row.read(dateExp)!.dateFmt(groupBy);
+ final assetCount = row.read(assetCountExp)!;
+ return TimeBucket(date: timeline, assetCount: assetCount);
+ }).watch();
+ }
+
+ Future<List<BaseAsset>> getFavoriteBucketAssets(
+ String userId, {
+ required int offset,
+ required int count,
+ }) {
+ final query = _db.remoteAssetEntity.select()
+ ..where(
+ (row) => row.isFavorite.equals(true) & row.ownerId.equals(userId),
+ )
+ ..orderBy([(row) => OrderingTerm.desc(row.createdAt)])
+ ..limit(count, offset: offset);
+
+ return query.map((row) => row.toDto()).get();
+ }
+
Stream<List<Bucket>> watchTrashBucket(
String userId, {
GroupAssetsBy groupBy = GroupAssetsBy.day,
diff --git a/mobile/lib/presentation/pages/dev/drift_favorite.page.dart b/mobile/lib/presentation/pages/dev/drift_favorite.page.dart
new file mode 100644
index 0000000000..4055ad863b
--- /dev/null
+++ b/mobile/lib/presentation/pages/dev/drift_favorite.page.dart
@@ -0,0 +1,33 @@
+import 'package:auto_route/auto_route.dart';
+import 'package:flutter/widgets.dart';
+import 'package:hooks_riverpod/hooks_riverpod.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';
+
+@RoutePage()
+class DriftFavoritePage extends StatelessWidget {
+ const DriftFavoritePage({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return ProviderScope(
+ overrides: [
+ timelineServiceProvider.overrideWith(
+ (ref) {
+ final user = ref.watch(currentUserProvider);
+ if (user == null) {
+ throw Exception('User must be logged in to access favorite');
+ }
+
+ final timelineService =
+ ref.watch(timelineFactoryProvider).favorite(user.id);
+ ref.onDispose(timelineService.dispose);
+ return timelineService;
+ },
+ ),
+ ],
+ child: const Timeline(),
+ );
+ }
+}
diff --git a/mobile/lib/presentation/pages/dev/feat_in_development.page.dart b/mobile/lib/presentation/pages/dev/feat_in_development.page.dart
index e4c4f1c879..66f7be4f05 100644
--- a/mobile/lib/presentation/pages/dev/feat_in_development.page.dart
+++ b/mobile/lib/presentation/pages/dev/feat_in_development.page.dart
@@ -99,6 +99,11 @@ final _features = [
icon: Icons.timeline_rounded,
onTap: (ctx, _) => ctx.pushRoute(const TabShellRoute()),
),
+ _Feature(
+ name: 'Favorite',
+ icon: Icons.favorite_outline_rounded,
+ onTap: (ctx, _) => ctx.pushRoute(const DriftFavoriteRoute()),
+ ),
_Feature(
name: 'Trash',
icon: Icons.delete_outline_rounded,
diff --git a/mobile/lib/routing/router.dart b/mobile/lib/routing/router.dart
index 8513b0606c..1805aab2b3 100644
--- a/mobile/lib/routing/router.dart
+++ b/mobile/lib/routing/router.dart
@@ -66,6 +66,7 @@ import 'package:immich_mobile/pages/search/person_result.page.dart';
import 'package:immich_mobile/pages/search/recently_taken.page.dart';
import 'package:immich_mobile/pages/search/search.page.dart';
import 'package:immich_mobile/pages/share_intent/share_intent.page.dart';
+import 'package:immich_mobile/presentation/pages/dev/drift_favorite.page.dart';
import 'package:immich_mobile/presentation/pages/dev/drift_trash.page.dart';
import 'package:immich_mobile/presentation/pages/dev/drift_archive.page.dart';
import 'package:immich_mobile/presentation/pages/dev/drift_locked_folder.page.dart';
@@ -395,6 +396,10 @@ class AppRouter extends RootStackRouter {
page: DriftMemoryRoute.page,
guards: [_authGuard, _duplicateGuard],
),
+ AutoRoute(
+ page: DriftFavoriteRoute.page,
+ guards: [_authGuard, _duplicateGuard],
+ ),
AutoRoute(
page: DriftTrashRoute.page,
guards: [_authGuard, _duplicateGuard],
diff --git a/mobile/lib/routing/router.gr.dart b/mobile/lib/routing/router.gr.dart
index cf34bc0d50..68f78b93fa 100644
--- a/mobile/lib/routing/router.gr.dart
+++ b/mobile/lib/routing/router.gr.dart
@@ -634,6 +634,22 @@ class DriftArchiveRoute extends PageRouteInfo<void> {
);
}
+/// generated route for
+/// [DriftFavoritePage]
+class DriftFavoriteRoute extends PageRouteInfo<void> {
+ const DriftFavoriteRoute({List<PageRouteInfo>? children})
+ : super(DriftFavoriteRoute.name, initialChildren: children);
+
+ static const String name = 'DriftFavoriteRoute';
+
+ static PageInfo page = PageInfo(
+ name,
+ builder: (data) {
+ return const DriftFavoritePage();
+ },
+ );
+}
+
/// generated route for
/// [DriftLockedFolderPage]
class DriftLockedFolderRoute extends PageRouteInfo<void> {