Fix any potentially stuck thumbnail uploads.

This commit is contained in:
Greyson Parrelli
2025-12-08 11:17:55 -05:00
committed by Michelle Tang
parent 293dcb93d6
commit 6d32e534dc
2 changed files with 28 additions and 0 deletions

View File

@@ -1105,6 +1105,17 @@ class AttachmentTable(
.run()
}
/**
* Resets the [ARCHIVE_THUMBNAIL_TRANSFER_STATE] of any attachments that are currently in-progress of uploading.
*/
fun clearArchiveThumbnailTransferStateForInProgressItems(): Int {
return writableDatabase
.update(TABLE_NAME)
.values(ARCHIVE_THUMBNAIL_TRANSFER_STATE to ArchiveTransferState.NONE.value)
.where("$ARCHIVE_THUMBNAIL_TRANSFER_STATE = ?", ArchiveTransferState.UPLOAD_IN_PROGRESS.value)
.run()
}
/**
* Marks eligible attachments as offloaded based on their received at timestamp, their last restore time,
* presence of thumbnail if media, and the full file being available in the archive.
@@ -1177,6 +1188,13 @@ class AttachmentTable(
.readToSingleLong()
}
fun areAnyThumbnailsPendingUpload(): Boolean {
return readableDatabase
.exists(TABLE_NAME)
.where("$ARCHIVE_THUMBNAIL_TRANSFER_STATE = ?", ArchiveTransferState.UPLOAD_IN_PROGRESS.value)
.run()
}
/**
* Clears out the incrementalMac for the specified [attachmentId], as well as any other attachments that share the same ([remoteKey], [plaintextHash]) pair (if present).
*/