deleteFile method
Future<Attachment>
deleteFile({
- required String attachmentId,
- required Future<
void> updateHook(- SqliteWriteContext context,
- Attachment attachment
Queues an attachment for delete. The default implementation assumes the attachment record already exists locally.
Implementation
Future<Attachment> deleteFile({
required String attachmentId,
required Future<void> Function(
SqliteWriteContext context, Attachment attachment)
updateHook,
}) async {
return await _attachmentsService.withContext((attachmentContext) async {
final attachment = await attachmentContext.getAttachment(attachmentId);
if (attachment == null) {
throw Exception(
'Attachment record with id $attachmentId was not found.',
);
}
return await _db.writeTransaction((tx) async {
await updateHook(tx, attachment);
return await attachmentContext.upsertAttachment(
attachment.copyWith(
state: AttachmentState.queuedDelete,
hasSynced: false,
),
tx,
);
});
});
}