Fix thumbnail rendering and refreshing on full download.

This commit is contained in:
Cody Henthorne
2024-09-18 10:09:59 -04:00
committed by Greyson Parrelli
parent b74f04495e
commit a1bf4d62ab
11 changed files with 43 additions and 25 deletions

View File

@@ -131,7 +131,6 @@ class ArchiveThumbnailUploadJob private constructor(
val archiveMediaId = attachment.archiveMediaId ?: backupKey.deriveMediaId(attachment.getMediaName()).encode()
SignalDatabase.attachments.finalizeAttachmentThumbnailAfterUpload(attachmentId, archiveMediaId, mediaSecrets.id, thumbnailResult.data)
Log.i(RestoreAttachmentJob.TAG, "Restore: Thumbnail mediaId=${mediaSecrets.id.encode()} backupDir=${backupDirectories.backupDir} mediaDir=${backupDirectories.mediaDir}")
Log.d(TAG, "Successfully archived thumbnail for $attachmentId mediaName=${attachment.getThumbnailMediaName()}")
Result.success()
}

View File

@@ -84,6 +84,8 @@ class AttachmentDownloadJob private constructor(
@JvmStatic
fun downloadAttachmentIfNeeded(databaseAttachment: DatabaseAttachment): String? {
return when (val transferState = databaseAttachment.transferState) {
AttachmentTable.TRANSFER_PROGRESS_DONE -> null
AttachmentTable.TRANSFER_RESTORE_OFFLOADED,
AttachmentTable.TRANSFER_NEEDS_RESTORE -> RestoreAttachmentJob.restoreAttachment(databaseAttachment)
@@ -109,10 +111,9 @@ class AttachmentDownloadJob private constructor(
}
AttachmentTable.TRANSFER_RESTORE_IN_PROGRESS,
AttachmentTable.TRANSFER_PROGRESS_DONE,
AttachmentTable.TRANSFER_PROGRESS_STARTED,
AttachmentTable.TRANSFER_PROGRESS_PERMANENT_FAILURE -> {
Log.d(TAG, "$databaseAttachment is downloading, downloaded already or permanently failed, transferState: $transferState")
Log.d(TAG, "${databaseAttachment.attachmentId} is downloading or permanently failed, transferState: $transferState")
null
}
@@ -215,6 +216,7 @@ class AttachmentDownloadJob private constructor(
retrieveAttachmentForReleaseChannel(messageId, attachmentId, attachment)
false
}
else -> {
retrieveAttachment(messageId, attachmentId, attachment)
}
@@ -225,14 +227,17 @@ class AttachmentDownloadJob private constructor(
attachment.archiveTransferState == AttachmentTable.ArchiveTransferState.FINISHED -> {
Log.i(TAG, "[$attachmentId] Already archived. Skipping.")
}
digestChanged -> {
Log.i(TAG, "[$attachmentId] Digest for attachment changed after download. Re-uploading to archive.")
AppDependencies.jobManager.add(UploadAttachmentToArchiveJob(attachmentId))
}
attachment.cdn !in CopyAttachmentToArchiveJob.ALLOWED_SOURCE_CDNS -> {
Log.i(TAG, "[$attachmentId] Attachment CDN doesn't support copying to archive. Re-uploading to archive.")
AppDependencies.jobManager.add(UploadAttachmentToArchiveJob(attachmentId))
}
else -> {
Log.i(TAG, "[$attachmentId] Enqueuing job to copy to archive.")
AppDependencies.jobManager.add(CopyAttachmentToArchiveJob(attachmentId))

View File

@@ -48,7 +48,7 @@ class RestoreAttachmentJob private constructor(
companion object {
const val KEY = "RestoreAttachmentJob"
val TAG = Log.tag(RestoreAttachmentJob::class.java)
private val TAG = Log.tag(RestoreAttachmentJob::class.java)
@JvmStatic
fun constructQueueString(): String {

View File

@@ -22,6 +22,7 @@ import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.util.RemoteConfig
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException
import java.io.File
import java.io.IOException
import java.util.concurrent.TimeUnit
@@ -142,6 +143,12 @@ class RestoreAttachmentThumbnailJob private constructor(
}
override fun onShouldRetry(exception: Exception): Boolean {
if (exception is NonSuccessfulResponseCodeException) {
if (exception.code == 404) {
Log.w(TAG, "[$attachmentId-thumbnail] Unable to find file")
return false
}
}
return exception is IOException
}