mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Fix issue where backfilled dupes may get different mediaIds.
This commit is contained in:
committed by
Alex Hart
parent
17d338f7af
commit
c723b2c6bf
@@ -273,6 +273,41 @@ class AttachmentTableTest_createRemoteKeyForAttachmentsThatNeedArchiveUpload {
|
||||
assertThat(SignalDatabase.attachments.getAttachment(targetAttachmentId)?.remoteKey).isNotNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenTwoAttachmentsShareDataFileAndBothNeedNewKey_bothGetSameKey() {
|
||||
val sharedDataFile = "/shared/path/attachment.jpg"
|
||||
|
||||
// Create two attachments sharing the same data file, neither with a remote key
|
||||
val attachmentId1 = insertAttachmentDirectly(
|
||||
dataFile = sharedDataFile,
|
||||
transferState = AttachmentTable.TRANSFER_PROGRESS_DONE,
|
||||
archiveTransferState = AttachmentTable.ArchiveTransferState.NONE.value,
|
||||
remoteKey = null
|
||||
)
|
||||
|
||||
val attachmentId2 = insertAttachmentDirectly(
|
||||
dataFile = sharedDataFile,
|
||||
transferState = AttachmentTable.TRANSFER_PROGRESS_DONE,
|
||||
archiveTransferState = AttachmentTable.ArchiveTransferState.NONE.value,
|
||||
remoteKey = null
|
||||
)
|
||||
|
||||
// Verify neither has a remote key initially
|
||||
assertThat(SignalDatabase.attachments.getAttachment(attachmentId1)?.remoteKey).isNull()
|
||||
assertThat(SignalDatabase.attachments.getAttachment(attachmentId2)?.remoteKey).isNull()
|
||||
|
||||
val result = SignalDatabase.attachments.createRemoteKeyForAttachmentsThatNeedArchiveUpload()
|
||||
assertThat(result.totalCount).isEqualTo(2)
|
||||
|
||||
// Verify both attachments got the SAME remote key
|
||||
val attachment1 = SignalDatabase.attachments.getAttachment(attachmentId1)!!
|
||||
val attachment2 = SignalDatabase.attachments.getAttachment(attachmentId2)!!
|
||||
|
||||
assertThat(attachment1.remoteKey).isNotNull()
|
||||
assertThat(attachment2.remoteKey).isNotNull()
|
||||
assertThat(attachment1.remoteKey).isEqualTo(attachment2.remoteKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an attachment that meets all criteria for archive upload:
|
||||
* - ARCHIVE_TRANSFER_STATE = NONE (0)
|
||||
|
||||
Reference in New Issue
Block a user