Avoid uploading story-only media to backups.

This commit is contained in:
Michelle Tang
2025-07-16 13:10:32 -04:00
committed by GitHub
parent 559539dc3b
commit 141faf3fb6
8 changed files with 104 additions and 19 deletions

View File

@@ -49,6 +49,7 @@ import org.signal.libsignal.zkgroup.backups.BackupLevel
import org.signal.libsignal.zkgroup.profiles.ProfileKey
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.attachments.Attachment
import org.thoughtcrime.securesms.attachments.AttachmentId
import org.thoughtcrime.securesms.attachments.Cdn
import org.thoughtcrime.securesms.attachments.DatabaseAttachment
import org.thoughtcrime.securesms.backup.ArchiveUploadProgress
@@ -1370,6 +1371,28 @@ object BackupRepository {
}
}
/**
* Returns if an attachment should be copied to the archive if it meets certain requirements eg
* not a story, not already uploaded to the archive cdn, not a preuploaded attachment, etc.
*/
@JvmStatic
fun shouldCopyAttachmentToArchive(attachmentId: AttachmentId, messageId: Long): Boolean {
if (!SignalStore.backup.backsUpMedia) {
return false
}
val attachment = SignalDatabase.attachments.getAttachment(attachmentId)
return when {
attachment == null -> false
attachment.archiveTransferState == AttachmentTable.ArchiveTransferState.FINISHED -> false
!DatabaseAttachmentArchiveUtil.hadIntegrityCheckPerformed(attachment) -> false
messageId == AttachmentTable.PREUPLOAD_MESSAGE_ID -> false
SignalDatabase.messages.isStory(messageId) -> false
else -> true
}
}
/**
* Copies a thumbnail that has been uploaded to the transit cdn to the archive cdn.
*/

View File

@@ -59,7 +59,10 @@ object DatabaseAttachmentArchiveUtil {
return MediaName.fromPlaintextHashAndRemoteKeyForThumbnail(attachment.dataHash!!.decodeBase64OrThrow(), attachment.remoteKey!!.decodeBase64OrThrow())
}
private fun hadIntegrityCheckPerformed(attachment: DatabaseAttachment): Boolean {
/**
* Returns whether an integrity check has been performed at some point by checking against its transfer state
*/
fun hadIntegrityCheckPerformed(attachment: DatabaseAttachment): Boolean {
if (attachment.archiveTransferState == AttachmentTable.ArchiveTransferState.FINISHED) {
return true
}