feat: delete actions (#20034)

* chore: show delete local

* pr feedback

* restore and perm delete action
This commit is contained in:
Alex 2025-07-22 11:36:00 -05:00 committed by GitHub
parent 2efca67217
commit aa344a3989
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 285 additions and 18 deletions

View file

@ -171,6 +171,18 @@ class RemoteAssetRepository extends DriftDatabaseRepository {
});
}
Future<void> restoreTrash(List<String> ids) {
return _db.batch((batch) async {
for (final id in ids) {
batch.update(
_db.remoteAssetEntity,
const RemoteAssetEntityCompanion(deletedAt: Value(null)),
where: (e) => e.id.equals(id),
);
}
});
}
Future<void> delete(List<String> ids) {
return _db.remoteAssetEntity.deleteWhere((row) => row.id.isIn(ids));
}

View file

@ -332,6 +332,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
_remoteQueryBuilder(
filter: (row) => row.deletedAt.isNotNull() & row.ownerId.equals(userId),
groupBy: groupBy,
joinLocal: true,
);
TimelineQuery archived(String userId, GroupAssetsBy groupBy) =>
@ -443,11 +444,16 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
TimelineQuery _remoteQueryBuilder({
required Expression<bool> Function($RemoteAssetEntityTable row) filter,
GroupAssetsBy groupBy = GroupAssetsBy.day,
bool joinLocal = false,
}) {
return (
bucketSource: () => _watchRemoteBucket(filter: filter, groupBy: groupBy),
assetSource: (offset, count) =>
_getRemoteAssets(filter: filter, offset: offset, count: count),
assetSource: (offset, count) => _getRemoteAssets(
filter: filter,
offset: offset,
count: count,
joinLocal: joinLocal,
),
);
}
@ -480,13 +486,35 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
required Expression<bool> Function($RemoteAssetEntityTable row) filter,
required int offset,
required int count,
bool joinLocal = false,
}) {
final query = _db.remoteAssetEntity.select()
..where(filter)
..orderBy([(row) => OrderingTerm.desc(row.createdAt)])
..limit(count, offset: offset);
if (joinLocal) {
final query = _db.remoteAssetEntity.select().join([
leftOuterJoin(
_db.localAssetEntity,
_db.remoteAssetEntity.checksum
.equalsExp(_db.localAssetEntity.checksum),
useColumns: false,
),
])
..addColumns([_db.localAssetEntity.id])
..where(filter(_db.remoteAssetEntity))
..orderBy([OrderingTerm.desc(_db.remoteAssetEntity.createdAt)])
..limit(count, offset: offset);
return query.map((row) => row.toDto()).get();
return query.map((row) {
final asset = row.readTable(_db.remoteAssetEntity).toDto();
final localId = row.read(_db.localAssetEntity.id);
return asset.copyWith(localId: localId);
}).get();
} else {
final query = _db.remoteAssetEntity.select()
..where(filter)
..orderBy([(row) => OrderingTerm.desc(row.createdAt)])
..limit(count, offset: offset);
return query.map((row) => row.toDto()).get();
}
}
}