fix: preserve stack primary asset selection (#31380)

* fix: preserve stack primary asset selection

* test: select stacked assets by id

* chore: limit dart formatting changes

* fix: address stack viewer review feedback

* fix: align stack ordering with server

* fix: keep stack primary asset first

---------

Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>
(cherry picked from commit 5a5d7be11084969c3c00a294ce6c0527042f88e7)
This commit is contained in:
Kairui Liu
2026-10-27 23:12:13 +03:00
committed by Codex
parent 75a1d7c5c8
commit c482c1e53e
7 changed files with 41 additions and 10 deletions
@@ -60,7 +60,6 @@ class AssetService {
}
final stack = await _remoteRepository.getStackChildren(asset);
// Include the primary asset in the stack as the first item
return [asset, ...stack];
}
@@ -76,7 +76,7 @@ class RemoteAssetRepository extends DatabaseAccessor<Drift> with $RemoteAssetRep
final query = _db.remoteAssetEntity.select()
..where((row) => row.stackId.equals(stackId) & row.id.equals(asset.id).not())
..orderBy([(row) => OrderingTerm.desc(row.createdAt)]);
..orderBy([(row) => OrderingTerm.asc(row.createdAt)]);
return query.map((row) => row.toDto()).get();
}
@@ -18,6 +18,37 @@ void main() {
await ctx.dispose();
});
group('getStackChildren', () {
test('returns stack children from oldest to newest', () async {
final user = await ctx.newUser();
const stackId = 'stack';
final primary = await ctx.newRemoteAsset(
id: 'primary',
ownerId: user.id,
stackId: stackId,
createdAt: DateTime(2026, 1, 2),
);
final beforePrimary = await ctx.newRemoteAsset(
id: 'before-primary',
ownerId: user.id,
stackId: stackId,
createdAt: DateTime(2026, 1, 1),
);
final afterPrimary = await ctx.newRemoteAsset(
id: 'after-primary',
ownerId: user.id,
stackId: stackId,
createdAt: DateTime(2026, 1, 3),
);
await ctx.newRemoteAsset(ownerId: user.id, stackId: 'other-stack');
final primaryAsset = await sut.get(primary.id);
final stack = await sut.getStackChildren(primaryAsset!);
expect(stack.map((asset) => asset.id), [beforePrimary.id, afterPrimary.id]);
});
});
group('getByChecksum', () {
late String userId;