From ca78bc91b671d17186cb2e8d1f61ca61727a7e63 Mon Sep 17 00:00:00 2001 From: Min Idzelis Date: Wed, 2 Jul 2025 09:31:20 -0400 Subject: [PATCH 1/5] feat: fully qualified path in error msg (#19674) * feat: fully qualified path in error msg * import style --- server/src/services/storage.service.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/src/services/storage.service.ts b/server/src/services/storage.service.ts index 99d89df099..3861f84815 100644 --- a/server/src/services/storage.service.ts +++ b/server/src/services/storage.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { join } from 'node:path'; +import { join, resolve } from 'node:path'; import { StorageCore } from 'src/cores/storage.core'; import { OnEvent, OnJob } from 'src/decorators'; import { DatabaseLock, JobName, JobStatus, QueueName, StorageFolder, SystemMetadataKey } from 'src/enum'; @@ -87,8 +87,9 @@ export class StorageService extends BaseService { try { await this.storageRepository.readFile(internalPath); } catch (error) { - this.logger.error(`Failed to read ${internalPath}: ${error}`); - throw new ImmichStartupError(`Failed to read "${externalPath} - ${docsMessage}"`); + const fullyQualifiedPath = resolve(process.cwd(), internalPath); + this.logger.error(`Failed to read ${fullyQualifiedPath} (${internalPath}): ${error}`); + throw new ImmichStartupError(`Failed to read: "${externalPath} (${fullyQualifiedPath}) - ${docsMessage}"`); } } From b8e67d0ef9ac58a10fed36fd53a2106b9e68556b Mon Sep 17 00:00:00 2001 From: Daimolean <92239625+wuzihao051119@users.noreply.github.com> Date: Thu, 3 Jul 2025 01:25:14 +0800 Subject: [PATCH 2/5] fix(mobile): filter deleted assets (#19683) --- mobile/lib/infrastructure/entities/merged_asset.drift | 10 +++++----- .../infrastructure/entities/merged_asset.drift.dart | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mobile/lib/infrastructure/entities/merged_asset.drift b/mobile/lib/infrastructure/entities/merged_asset.drift index 51f731f0ff..825484503b 100644 --- a/mobile/lib/infrastructure/entities/merged_asset.drift +++ b/mobile/lib/infrastructure/entities/merged_asset.drift @@ -1,7 +1,7 @@ import 'remote_asset.entity.dart'; import 'local_asset.entity.dart'; -mergedAsset: SELECT * FROM +mergedAsset: SELECT * FROM ( SELECT rae.id as remote_id, @@ -22,7 +22,7 @@ mergedAsset: SELECT * FROM LEFT JOIN local_asset_entity lae ON rae.checksum = lae.checksum WHERE - rae.visibility = 0 AND rae.owner_id in ? + rae.deleted_at IS NULL AND rae.visibility = 0 AND rae.owner_id in ? UNION ALL SELECT NULL as remote_id, @@ -48,8 +48,8 @@ mergedAsset: SELECT * FROM ORDER BY created_at DESC LIMIT $limit; -mergedBucket(:group_by AS INTEGER): -SELECT +mergedBucket(:group_by AS INTEGER): +SELECT COUNT(*) as asset_count, CASE WHEN :group_by = 0 THEN STRFTIME('%Y-%m-%d', created_at) -- day @@ -65,7 +65,7 @@ FROM LEFT JOIN local_asset_entity lae ON rae.checksum = lae.checksum WHERE - rae.visibility = 0 AND rae.owner_id in ? + rae.deleted_at IS NULL AND rae.visibility = 0 AND rae.owner_id in ? UNION ALL SELECT lae.name, diff --git a/mobile/lib/infrastructure/entities/merged_asset.drift.dart b/mobile/lib/infrastructure/entities/merged_asset.drift.dart index be9d8b521e..19fb9e3dac 100644 --- a/mobile/lib/infrastructure/entities/merged_asset.drift.dart +++ b/mobile/lib/infrastructure/entities/merged_asset.drift.dart @@ -18,7 +18,7 @@ class MergedAssetDrift extends i1.ModularAccessor { final generatedlimit = $write(limit, startIndex: $arrayStartIndex); $arrayStartIndex += generatedlimit.amountOfVariables; return customSelect( - 'SELECT * FROM (SELECT rae.id AS remote_id, lae.id AS local_id, rae.name, rae.type, rae.created_at, rae.updated_at, rae.width, rae.height, rae.duration_in_seconds, rae.is_favorite, rae.thumb_hash, rae.checksum, rae.owner_id FROM remote_asset_entity AS rae LEFT JOIN local_asset_entity AS lae ON rae.checksum = lae.checksum WHERE rae.visibility = 0 AND rae.owner_id IN ($expandedvar1) UNION ALL SELECT NULL AS remote_id, lae.id AS local_id, lae.name, lae.type, lae.created_at, lae.updated_at, lae.width, lae.height, lae.duration_in_seconds, lae.is_favorite, NULL AS thumb_hash, lae.checksum, NULL AS owner_id FROM local_asset_entity AS lae LEFT JOIN remote_asset_entity AS rae ON rae.checksum = lae.checksum WHERE rae.id IS NULL) ORDER BY created_at DESC ${generatedlimit.sql}', + 'SELECT * FROM (SELECT rae.id AS remote_id, lae.id AS local_id, rae.name, rae.type, rae.created_at, rae.updated_at, rae.width, rae.height, rae.duration_in_seconds, rae.is_favorite, rae.thumb_hash, rae.checksum, rae.owner_id FROM remote_asset_entity AS rae LEFT JOIN local_asset_entity AS lae ON rae.checksum = lae.checksum WHERE rae.deleted_at IS NULL AND rae.visibility = 0 AND rae.owner_id IN ($expandedvar1) UNION ALL SELECT NULL AS remote_id, lae.id AS local_id, lae.name, lae.type, lae.created_at, lae.updated_at, lae.width, lae.height, lae.duration_in_seconds, lae.is_favorite, NULL AS thumb_hash, lae.checksum, NULL AS owner_id FROM local_asset_entity AS lae LEFT JOIN remote_asset_entity AS rae ON rae.checksum = lae.checksum WHERE rae.id IS NULL) ORDER BY created_at DESC ${generatedlimit.sql}', variables: [ for (var $ in var1) i0.Variable($), ...generatedlimit.introducedVariables @@ -51,7 +51,7 @@ class MergedAssetDrift extends i1.ModularAccessor { final expandedvar2 = $expandVar($arrayStartIndex, var2.length); $arrayStartIndex += var2.length; return customSelect( - 'SELECT COUNT(*) AS asset_count, CASE WHEN ?1 = 0 THEN STRFTIME(\'%Y-%m-%d\', created_at) WHEN ?1 = 1 THEN STRFTIME(\'%Y-%m\', created_at) END AS bucket_date FROM (SELECT rae.name, rae.created_at FROM remote_asset_entity AS rae LEFT JOIN local_asset_entity AS lae ON rae.checksum = lae.checksum WHERE rae.visibility = 0 AND rae.owner_id IN ($expandedvar2) UNION ALL SELECT lae.name, lae.created_at FROM local_asset_entity AS lae LEFT JOIN remote_asset_entity AS rae ON rae.checksum = lae.checksum WHERE rae.id IS NULL) GROUP BY bucket_date ORDER BY bucket_date DESC', + 'SELECT COUNT(*) AS asset_count, CASE WHEN ?1 = 0 THEN STRFTIME(\'%Y-%m-%d\', created_at) WHEN ?1 = 1 THEN STRFTIME(\'%Y-%m\', created_at) END AS bucket_date FROM (SELECT rae.name, rae.created_at FROM remote_asset_entity AS rae LEFT JOIN local_asset_entity AS lae ON rae.checksum = lae.checksum WHERE rae.deleted_at IS NULL AND rae.visibility = 0 AND rae.owner_id IN ($expandedvar2) UNION ALL SELECT lae.name, lae.created_at FROM local_asset_entity AS lae LEFT JOIN remote_asset_entity AS rae ON rae.checksum = lae.checksum WHERE rae.id IS NULL) GROUP BY bucket_date ORDER BY bucket_date DESC', variables: [ i0.Variable(groupBy), for (var $ in var2) i0.Variable($) From a644cabab6e117323211ca76b0e5ef01f232eb1a Mon Sep 17 00:00:00 2001 From: Daimolean <92239625+wuzihao051119@users.noreply.github.com> Date: Thu, 3 Jul 2025 01:26:07 +0800 Subject: [PATCH 3/5] feat(mobile): trash and delete action (#19681) * feat(mobile): trash and delete action * fix lint --- i18n/en.json | 2 + .../repositories/remote_asset.repository.dart | 16 ++++++++ .../delete_action_button.widget.dart | 37 ++++++++++++++++++- .../trash_action_buton.widget.dart | 37 ++++++++++++++++++- .../home_bottom_app_bar.widget.dart | 6 ++- .../infrastructure/action.provider.dart | 30 +++++++++++++++ .../repositories/asset_api.repository.dart | 4 ++ mobile/lib/services/action.service.dart | 10 +++++ 8 files changed, 138 insertions(+), 4 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index d81a6270ad..97d4457427 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -719,6 +719,7 @@ "default_locale": "Default Locale", "default_locale_description": "Format dates and numbers based on your browser locale", "delete": "Delete", + "delete_action_prompt": "{count} deleted permanently", "delete_album": "Delete album", "delete_api_key_prompt": "Are you sure you want to delete this API key?", "delete_dialog_alert": "These items will be permanently deleted from Immich and from your device", @@ -1842,6 +1843,7 @@ "total": "Total", "total_usage": "Total usage", "trash": "Trash", + "trash_action_prompt": "{count} moved to trash", "trash_all": "Trash All", "trash_count": "Trash {count, number}", "trash_delete_asset": "Trash/Delete Asset", diff --git a/mobile/lib/infrastructure/repositories/remote_asset.repository.dart b/mobile/lib/infrastructure/repositories/remote_asset.repository.dart index a9e0811104..4ac2073dda 100644 --- a/mobile/lib/infrastructure/repositories/remote_asset.repository.dart +++ b/mobile/lib/infrastructure/repositories/remote_asset.repository.dart @@ -33,6 +33,22 @@ class DriftRemoteAssetRepository extends DriftDatabaseRepository { }); } + Future trash(List ids) { + return _db.batch((batch) async { + for (final id in ids) { + batch.update( + _db.remoteAssetEntity, + RemoteAssetEntityCompanion(deletedAt: Value(DateTime.now())), + where: (e) => e.id.equals(id), + ); + } + }); + } + + Future delete(List ids) { + return _db.remoteAssetEntity.deleteWhere((row) => row.id.isIn(ids)); + } + Future updateLocation(List ids, LatLng location) { return _db.batch((batch) async { for (final id in ids) { diff --git a/mobile/lib/presentation/widgets/action_buttons/delete_action_button.widget.dart b/mobile/lib/presentation/widgets/action_buttons/delete_action_button.widget.dart index ff77e99041..6f8c0f5227 100644 --- a/mobile/lib/presentation/widgets/action_buttons/delete_action_button.widget.dart +++ b/mobile/lib/presentation/widgets/action_buttons/delete_action_button.widget.dart @@ -1,10 +1,44 @@ import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:immich_mobile/constants/enums.dart'; import 'package:immich_mobile/extensions/translate_extensions.dart'; import 'package:immich_mobile/presentation/widgets/action_buttons/base_action_button.widget.dart'; +import 'package:immich_mobile/providers/infrastructure/action.provider.dart'; +import 'package:immich_mobile/providers/infrastructure/timeline.provider.dart'; +import 'package:immich_mobile/providers/timeline/multiselect.provider.dart'; +import 'package:immich_mobile/widgets/common/immich_toast.dart'; class DeletePermanentActionButton extends ConsumerWidget { - const DeletePermanentActionButton({super.key}); + final ActionSource source; + + const DeletePermanentActionButton({super.key, required this.source}); + + void _onTap(BuildContext context, WidgetRef ref) async { + if (!context.mounted) { + return; + } + + final result = await ref.read(actionProvider.notifier).delete(source); + await ref.read(timelineServiceProvider).reloadBucket(); + ref.read(multiSelectProvider.notifier).reset(); + + final successMessage = 'delete_action_prompt'.t( + context: context, + args: {'count': result.count.toString()}, + ); + + if (context.mounted) { + ImmichToast.show( + context: context, + msg: result.success + ? successMessage + : 'scaffold_body_error_occurred'.t(context: context), + gravity: ToastGravity.BOTTOM, + toastType: result.success ? ToastType.success : ToastType.error, + ); + } + } @override Widget build(BuildContext context, WidgetRef ref) { @@ -12,6 +46,7 @@ class DeletePermanentActionButton extends ConsumerWidget { maxWidth: 110.0, iconData: Icons.delete_forever, label: "delete_dialog_title".t(context: context), + onPressed: () => _onTap(context, ref), ); } } diff --git a/mobile/lib/presentation/widgets/action_buttons/trash_action_buton.widget.dart b/mobile/lib/presentation/widgets/action_buttons/trash_action_buton.widget.dart index ccaaf314fc..1d287e34e2 100644 --- a/mobile/lib/presentation/widgets/action_buttons/trash_action_buton.widget.dart +++ b/mobile/lib/presentation/widgets/action_buttons/trash_action_buton.widget.dart @@ -1,10 +1,44 @@ import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:immich_mobile/constants/enums.dart'; import 'package:immich_mobile/extensions/translate_extensions.dart'; import 'package:immich_mobile/presentation/widgets/action_buttons/base_action_button.widget.dart'; +import 'package:immich_mobile/providers/infrastructure/action.provider.dart'; +import 'package:immich_mobile/providers/infrastructure/timeline.provider.dart'; +import 'package:immich_mobile/providers/timeline/multiselect.provider.dart'; +import 'package:immich_mobile/widgets/common/immich_toast.dart'; class TrashActionButton extends ConsumerWidget { - const TrashActionButton({super.key}); + final ActionSource source; + + const TrashActionButton({super.key, required this.source}); + + void _onTap(BuildContext context, WidgetRef ref) async { + if (!context.mounted) { + return; + } + + final result = await ref.read(actionProvider.notifier).trash(source); + await ref.read(timelineServiceProvider).reloadBucket(); + ref.read(multiSelectProvider.notifier).reset(); + + final successMessage = 'trash_action_prompt'.t( + context: context, + args: {'count': result.count.toString()}, + ); + + if (context.mounted) { + ImmichToast.show( + context: context, + msg: result.success + ? successMessage + : 'scaffold_body_error_occurred'.t(context: context), + gravity: ToastGravity.BOTTOM, + toastType: result.success ? ToastType.success : ToastType.error, + ); + } + } @override Widget build(BuildContext context, WidgetRef ref) { @@ -12,6 +46,7 @@ class TrashActionButton extends ConsumerWidget { maxWidth: 85.0, iconData: Icons.delete_outline_rounded, label: "control_bottom_app_bar_trash_from_immich".t(context: context), + onPressed: () => _onTap(context, ref), ); } } diff --git a/mobile/lib/presentation/widgets/bottom_app_bar/home_bottom_app_bar.widget.dart b/mobile/lib/presentation/widgets/bottom_app_bar/home_bottom_app_bar.widget.dart index d122d188ff..7f870bfdff 100644 --- a/mobile/lib/presentation/widgets/bottom_app_bar/home_bottom_app_bar.widget.dart +++ b/mobile/lib/presentation/widgets/bottom_app_bar/home_bottom_app_bar.widget.dart @@ -39,8 +39,10 @@ class HomeBottomAppBar extends ConsumerWidget { const FavoriteActionButton(source: ActionSource.timeline), const DownloadActionButton(), isTrashEnable - ? const TrashActionButton() - : const DeletePermanentActionButton(), + ? const TrashActionButton(source: ActionSource.timeline) + : const DeletePermanentActionButton( + source: ActionSource.timeline, + ), const EditDateTimeActionButton(), const EditLocationActionButton(source: ActionSource.timeline), const MoveToLockFolderActionButton( diff --git a/mobile/lib/providers/infrastructure/action.provider.dart b/mobile/lib/providers/infrastructure/action.provider.dart index 57dde6456e..4f92d4e325 100644 --- a/mobile/lib/providers/infrastructure/action.provider.dart +++ b/mobile/lib/providers/infrastructure/action.provider.dart @@ -173,6 +173,36 @@ class ActionNotifier extends Notifier { } } + Future trash(ActionSource source) async { + final ids = _getOwnedRemoteForSource(source); + try { + await _service.trash(ids); + return ActionResult(count: ids.length, success: true); + } catch (error, stack) { + _logger.severe('Failed to trash assets', error, stack); + return ActionResult( + count: ids.length, + success: false, + error: error.toString(), + ); + } + } + + Future delete(ActionSource source) async { + final ids = _getOwnedRemoteForSource(source); + try { + await _service.delete(ids); + return ActionResult(count: ids.length, success: true); + } catch (error, stack) { + _logger.severe('Failed to delete assets', error, stack); + return ActionResult( + count: ids.length, + success: false, + error: error.toString(), + ); + } + } + Future editLocation( ActionSource source, BuildContext context, diff --git a/mobile/lib/repositories/asset_api.repository.dart b/mobile/lib/repositories/asset_api.repository.dart index 9631428409..0dff309172 100644 --- a/mobile/lib/repositories/asset_api.repository.dart +++ b/mobile/lib/repositories/asset_api.repository.dart @@ -48,6 +48,10 @@ class AssetApiRepository extends ApiRepository { return result; } + Future delete(List ids, bool force) async { + return _api.deleteAssets(AssetBulkDeleteDto(ids: ids, force: force)); + } + Future updateVisibility( List ids, AssetVisibilityEnum visibility, diff --git a/mobile/lib/services/action.service.dart b/mobile/lib/services/action.service.dart index b5ddbac270..d1aabf3fb6 100644 --- a/mobile/lib/services/action.service.dart +++ b/mobile/lib/services/action.service.dart @@ -93,6 +93,16 @@ class ActionService { ); } + Future trash(List remoteIds) async { + await _assetApiRepository.delete(remoteIds, false); + await _remoteAssetRepository.trash(remoteIds); + } + + Future delete(List remoteIds) async { + await _assetApiRepository.delete(remoteIds, true); + await _remoteAssetRepository.delete(remoteIds); + } + Future editLocation( List remoteIds, BuildContext context, From 14276f41d85a5a0a2be6d0df6e159a706bea2818 Mon Sep 17 00:00:00 2001 From: shenlong <139912620+shenlong-tanwen@users.noreply.github.com> Date: Wed, 2 Jul 2025 22:56:42 +0530 Subject: [PATCH 4/5] fix: handle null bucket name during android sync (#19685) Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> --- .../main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt b/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt index 9ec0d763f7..5183c274b3 100644 --- a/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt +++ b/mobile/android/app/src/main/kotlin/app/alextran/immich/sync/MessagesImplBase.kt @@ -5,6 +5,7 @@ import android.content.Context import android.database.Cursor import android.provider.MediaStore import android.util.Log +import androidx.core.database.getStringOrNull import java.io.File import java.io.FileInputStream import java.security.MessageDigest @@ -152,7 +153,8 @@ open class NativeSyncApiImplBase(context: Context) { continue } - val name = cursor.getString(bucketNameColumn) + // MediaStore might return null for bucket name (commonly for the Root Directory), so default to "Internal Storage" + val name = cursor.getStringOrNull(bucketNameColumn) ?: "Internal Storage" val updatedAt = cursor.getLong(dateModified) albums.add(PlatformAlbum(id, name, updatedAt, false, 0)) albumsCount[id] = 1 From ec603a008ce4b037c8a4ee8bf494399069e8ca5f Mon Sep 17 00:00:00 2001 From: Daimolean <92239625+wuzihao051119@users.noreply.github.com> Date: Thu, 3 Jul 2025 01:27:30 +0800 Subject: [PATCH 5/5] feat(mobile): unarchive and unfavorite action (#19678) --- i18n/en.json | 2 + .../unarchive_action_button.widget.dart | 37 ++++++++++++++++++- .../unfavorite_action_button.widget.dart | 37 ++++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 97d4457427..91a55cc85f 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1861,9 +1861,11 @@ "unable_to_change_pin_code": "Unable to change PIN code", "unable_to_setup_pin_code": "Unable to setup PIN code", "unarchive": "Unarchive", + "unarchive_action_prompt": "{count} removed from Archive", "unarchived_count": "{count, plural, other {Unarchived #}}", "undo": "Undo", "unfavorite": "Unfavorite", + "unfavorite_action_prompt": "{count} removed from Favorites", "unhide_person": "Unhide person", "unknown": "Unknown", "unknown_country": "Unknown Country", diff --git a/mobile/lib/presentation/widgets/action_buttons/unarchive_action_button.widget.dart b/mobile/lib/presentation/widgets/action_buttons/unarchive_action_button.widget.dart index 7fa0f8513a..b5e210eb3b 100644 --- a/mobile/lib/presentation/widgets/action_buttons/unarchive_action_button.widget.dart +++ b/mobile/lib/presentation/widgets/action_buttons/unarchive_action_button.widget.dart @@ -1,16 +1,51 @@ import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:immich_mobile/constants/enums.dart'; import 'package:immich_mobile/extensions/translate_extensions.dart'; import 'package:immich_mobile/presentation/widgets/action_buttons/base_action_button.widget.dart'; +import 'package:immich_mobile/providers/infrastructure/action.provider.dart'; +import 'package:immich_mobile/providers/infrastructure/timeline.provider.dart'; +import 'package:immich_mobile/providers/timeline/multiselect.provider.dart'; +import 'package:immich_mobile/widgets/common/immich_toast.dart'; class UnarchiveActionButton extends ConsumerWidget { - const UnarchiveActionButton({super.key}); + final ActionSource source; + + const UnarchiveActionButton({super.key, required this.source}); + + void _onTap(BuildContext context, WidgetRef ref) async { + if (!context.mounted) { + return; + } + + final result = await ref.read(actionProvider.notifier).unArchive(source); + await ref.read(timelineServiceProvider).reloadBucket(); + ref.read(multiSelectProvider.notifier).reset(); + + final successMessage = 'unarchive_action_prompt'.t( + context: context, + args: {'count': result.count.toString()}, + ); + + if (context.mounted) { + ImmichToast.show( + context: context, + msg: result.success + ? successMessage + : 'scaffold_body_error_occurred'.t(context: context), + gravity: ToastGravity.BOTTOM, + toastType: result.success ? ToastType.success : ToastType.error, + ); + } + } @override Widget build(BuildContext context, WidgetRef ref) { return BaseActionButton( iconData: Icons.unarchive_outlined, label: "unarchive".t(context: context), + onPressed: () => _onTap(context, ref), ); } } diff --git a/mobile/lib/presentation/widgets/action_buttons/unfavorite_action_button.widget.dart b/mobile/lib/presentation/widgets/action_buttons/unfavorite_action_button.widget.dart index 420821ef3f..2d485f3418 100644 --- a/mobile/lib/presentation/widgets/action_buttons/unfavorite_action_button.widget.dart +++ b/mobile/lib/presentation/widgets/action_buttons/unfavorite_action_button.widget.dart @@ -1,16 +1,51 @@ import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:immich_mobile/constants/enums.dart'; import 'package:immich_mobile/extensions/translate_extensions.dart'; import 'package:immich_mobile/presentation/widgets/action_buttons/base_action_button.widget.dart'; +import 'package:immich_mobile/providers/infrastructure/action.provider.dart'; +import 'package:immich_mobile/providers/infrastructure/timeline.provider.dart'; +import 'package:immich_mobile/providers/timeline/multiselect.provider.dart'; +import 'package:immich_mobile/widgets/common/immich_toast.dart'; class UnFavoriteActionButton extends ConsumerWidget { - const UnFavoriteActionButton({super.key}); + final ActionSource source; + + const UnFavoriteActionButton({super.key, required this.source}); + + void _onTap(BuildContext context, WidgetRef ref) async { + if (!context.mounted) { + return; + } + + final result = await ref.read(actionProvider.notifier).unFavorite(source); + await ref.read(timelineServiceProvider).reloadBucket(); + ref.read(multiSelectProvider.notifier).reset(); + + final successMessage = 'unfavorite_action_prompt'.t( + context: context, + args: {'count': result.count.toString()}, + ); + + if (context.mounted) { + ImmichToast.show( + context: context, + msg: result.success + ? successMessage + : 'scaffold_body_error_occurred'.t(context: context), + gravity: ToastGravity.BOTTOM, + toastType: result.success ? ToastType.success : ToastType.error, + ); + } + } @override Widget build(BuildContext context, WidgetRef ref) { return BaseActionButton( iconData: Icons.favorite_rounded, label: "unfavorite".t(context: context), + onPressed: () => _onTap(context, ref), ); } }