mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 02:39:55 +01:00
Avoid uploading story-only media to backups.
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user