feat: show stacks in asset viewer (#19935)

* feat: show stacks in asset viewer

* fix: global key issue and flash on stack asset change

* feat(mobile): stack and unstack action (#19941)

* feat(mobile): stack and unstack action

* add custom model

* use stackId from ActionSource

* Update mobile/lib/providers/infrastructure/action.provider.dart

Co-authored-by: shenlong <139912620+shenlong-tanwen@users.noreply.github.com>

---------

Co-authored-by: shenlong <139912620+shenlong-tanwen@users.noreply.github.com>

* fix: lint

* fix: bad merge

* fix: test

---------

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
Co-authored-by: Alex <alex.tran1502@gmail.com>
Co-authored-by: Daimolean <92239625+wuzihao051119@users.noreply.github.com>
Co-authored-by: wuzihao051119 <wuzihao051119@outlook.com>
This commit is contained in:
shenlong 2025-07-18 10:01:04 +05:30 committed by GitHub
parent 546f841b2c
commit f32cd74232
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 1568 additions and 802 deletions

View file

@ -50,7 +50,7 @@ class ActionNotifier extends Notifier<void> {
return _getIdsForSource<LocalAsset>(source).toIds().toList(growable: false);
}
List<String> _getOwnedRemoteForSource(ActionSource source) {
List<String> _getOwnedRemoteIdsForSource(ActionSource source) {
final ownerId = ref.read(currentUserProvider)?.id;
return _getIdsForSource<RemoteAsset>(source)
.ownedAssets(ownerId)
@ -58,6 +58,20 @@ class ActionNotifier extends Notifier<void> {
.toList(growable: false);
}
List<RemoteAsset> _getOwnedRemoteAssetsForSource(ActionSource source) {
final ownerId = ref.read(currentUserProvider)?.id;
return _getIdsForSource<RemoteAsset>(source).ownedAssets(ownerId).toList();
}
Iterable<T> _getIdsForSource<T extends BaseAsset>(ActionSource source) {
final Set<BaseAsset> assets = _getAssets(source);
return switch (T) {
const (RemoteAsset) => assets.whereType<RemoteAsset>(),
const (LocalAsset) => assets.whereType<LocalAsset>(),
_ => const [],
} as Iterable<T>;
}
Set<BaseAsset> _getAssets(ActionSource source) {
return switch (source) {
ActionSource.timeline => ref.read(multiSelectProvider).selectedAssets,
@ -68,15 +82,6 @@ class ActionNotifier extends Notifier<void> {
};
}
Iterable<T> _getIdsForSource<T extends BaseAsset>(ActionSource source) {
final Set<BaseAsset> assets = _getAssets(source);
return switch (T) {
const (RemoteAsset) => assets.whereType<RemoteAsset>(),
const (LocalAsset) => assets.whereType<LocalAsset>(),
_ => const [],
} as Iterable<T>;
}
Future<ActionResult> shareLink(
ActionSource source,
BuildContext context,
@ -96,7 +101,7 @@ class ActionNotifier extends Notifier<void> {
}
Future<ActionResult> favorite(ActionSource source) async {
final ids = _getOwnedRemoteForSource(source);
final ids = _getOwnedRemoteIdsForSource(source);
try {
await _service.favorite(ids);
return ActionResult(count: ids.length, success: true);
@ -111,7 +116,7 @@ class ActionNotifier extends Notifier<void> {
}
Future<ActionResult> unFavorite(ActionSource source) async {
final ids = _getOwnedRemoteForSource(source);
final ids = _getOwnedRemoteIdsForSource(source);
try {
await _service.unFavorite(ids);
return ActionResult(count: ids.length, success: true);
@ -126,7 +131,7 @@ class ActionNotifier extends Notifier<void> {
}
Future<ActionResult> archive(ActionSource source) async {
final ids = _getOwnedRemoteForSource(source);
final ids = _getOwnedRemoteIdsForSource(source);
try {
await _service.archive(ids);
return ActionResult(count: ids.length, success: true);
@ -141,7 +146,7 @@ class ActionNotifier extends Notifier<void> {
}
Future<ActionResult> unArchive(ActionSource source) async {
final ids = _getOwnedRemoteForSource(source);
final ids = _getOwnedRemoteIdsForSource(source);
try {
await _service.unArchive(ids);
return ActionResult(count: ids.length, success: true);
@ -156,7 +161,7 @@ class ActionNotifier extends Notifier<void> {
}
Future<ActionResult> moveToLockFolder(ActionSource source) async {
final ids = _getOwnedRemoteForSource(source);
final ids = _getOwnedRemoteIdsForSource(source);
try {
await _service.moveToLockFolder(ids);
return ActionResult(count: ids.length, success: true);
@ -171,7 +176,7 @@ class ActionNotifier extends Notifier<void> {
}
Future<ActionResult> removeFromLockFolder(ActionSource source) async {
final ids = _getOwnedRemoteForSource(source);
final ids = _getOwnedRemoteIdsForSource(source);
try {
await _service.removeFromLockFolder(ids);
return ActionResult(count: ids.length, success: true);
@ -186,7 +191,7 @@ class ActionNotifier extends Notifier<void> {
}
Future<ActionResult> trash(ActionSource source) async {
final ids = _getOwnedRemoteForSource(source);
final ids = _getOwnedRemoteIdsForSource(source);
try {
await _service.trash(ids);
return ActionResult(count: ids.length, success: true);
@ -201,7 +206,7 @@ class ActionNotifier extends Notifier<void> {
}
Future<ActionResult> delete(ActionSource source) async {
final ids = _getOwnedRemoteForSource(source);
final ids = _getOwnedRemoteIdsForSource(source);
try {
await _service.delete(ids);
return ActionResult(count: ids.length, success: true);
@ -234,7 +239,7 @@ class ActionNotifier extends Notifier<void> {
ActionSource source,
BuildContext context,
) async {
final ids = _getOwnedRemoteForSource(source);
final ids = _getOwnedRemoteIdsForSource(source);
try {
final isEdited = await _service.editLocation(ids, context);
if (!isEdited) {
@ -270,6 +275,35 @@ class ActionNotifier extends Notifier<void> {
}
}
Future<ActionResult> stack(String userId, ActionSource source) async {
final ids = _getOwnedRemoteIdsForSource(source);
try {
await _service.stack(userId, ids);
return ActionResult(count: ids.length, success: true);
} catch (error, stack) {
_logger.severe('Failed to stack assets', error, stack);
return ActionResult(
count: ids.length,
success: false,
error: error.toString(),
);
}
}
Future<ActionResult> unStack(ActionSource source) async {
final assets = _getOwnedRemoteAssetsForSource(source);
try {
await _service.unStack(assets.map((e) => e.stackId).nonNulls.toList());
return ActionResult(count: assets.length, success: true);
} catch (error, stack) {
_logger.severe('Failed to unstack assets', error, stack);
return ActionResult(
count: assets.length,
success: false,
);
}
}
Future<ActionResult> shareAssets(ActionSource source) async {
final ids = _getAssets(source).toList(growable: false);