mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-07-08 15:04:21 +01:00
Update to the latest backup tests.
This commit is contained in:
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+20
-7
@@ -80,6 +80,7 @@ import org.thoughtcrime.securesms.payments.FailureReason
|
||||
import org.thoughtcrime.securesms.payments.State
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.util.JsonUtils
|
||||
import org.thoughtcrime.securesms.util.MediaUtil
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil
|
||||
import org.whispersystems.signalservice.api.util.toByteArray
|
||||
@@ -787,7 +788,18 @@ private fun BackupMessageRecord.toRemoteQuote(mediaArchiveEnabled: Boolean, atta
|
||||
return null
|
||||
}
|
||||
|
||||
val type = QuoteModel.Type.fromCode(this.quoteType)
|
||||
val localType = QuoteModel.Type.fromCode(this.quoteType)
|
||||
val remoteType = when (localType) {
|
||||
QuoteModel.Type.NORMAL -> {
|
||||
if (attachments?.any { it.contentType == MediaUtil.VIEW_ONCE } == true) {
|
||||
Quote.Type.VIEW_ONCE
|
||||
} else {
|
||||
Quote.Type.NORMAL
|
||||
}
|
||||
}
|
||||
QuoteModel.Type.GIFT_BADGE -> Quote.Type.GIFT_BADGE
|
||||
}
|
||||
|
||||
return Quote(
|
||||
targetSentTimestamp = this.quoteTargetSentTimestamp.takeIf { !this.quoteMissing && it != MessageTable.QUOTE_TARGET_MISSING_ID },
|
||||
authorId = this.quoteAuthor,
|
||||
@@ -797,11 +809,12 @@ private fun BackupMessageRecord.toRemoteQuote(mediaArchiveEnabled: Boolean, atta
|
||||
bodyRanges = this.quoteBodyRanges?.toRemoteBodyRanges() ?: emptyList()
|
||||
)
|
||||
},
|
||||
attachments = attachments?.toRemoteQuoteAttachments(mediaArchiveEnabled) ?: emptyList(),
|
||||
type = when (type) {
|
||||
QuoteModel.Type.NORMAL -> Quote.Type.NORMAL
|
||||
QuoteModel.Type.GIFT_BADGE -> Quote.Type.GIFT_BADGE
|
||||
}
|
||||
attachments = if (remoteType == Quote.Type.VIEW_ONCE) {
|
||||
emptyList()
|
||||
} else {
|
||||
attachments?.toRemoteQuoteAttachments(mediaArchiveEnabled) ?: emptyList()
|
||||
},
|
||||
type = remoteType
|
||||
)
|
||||
}
|
||||
|
||||
@@ -847,7 +860,7 @@ private fun List<DatabaseAttachment>.toRemoteQuoteAttachments(mediaArchiveEnable
|
||||
mediaArchiveEnabled = mediaArchiveEnabled,
|
||||
flagOverride = MessageAttachment.Flag.NONE,
|
||||
contentTypeOverride = "image/jpeg"
|
||||
).takeUnless { it.pointer?.invalidAttachmentLocator != null }
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+28
-23
@@ -18,6 +18,7 @@ import org.signal.core.util.toInt
|
||||
import org.signal.core.util.update
|
||||
import org.thoughtcrime.securesms.attachments.Attachment
|
||||
import org.thoughtcrime.securesms.attachments.PointerAttachment
|
||||
import org.thoughtcrime.securesms.attachments.TombstoneAttachment
|
||||
import org.thoughtcrime.securesms.backup.v2.ImportState
|
||||
import org.thoughtcrime.securesms.backup.v2.proto.BodyRange
|
||||
import org.thoughtcrime.securesms.backup.v2.proto.ChatItem
|
||||
@@ -70,6 +71,7 @@ import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.stickers.StickerLocator
|
||||
import org.thoughtcrime.securesms.util.JsonUtils
|
||||
import org.thoughtcrime.securesms.util.MediaUtil
|
||||
import org.whispersystems.signalservice.api.payments.Money
|
||||
import org.whispersystems.signalservice.api.push.ServiceId
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil
|
||||
@@ -396,9 +398,7 @@ class ChatItemArchiveImporter(
|
||||
)
|
||||
}?.let { listOf(it) } ?: emptyList()
|
||||
|
||||
val quoteAttachments: List<Attachment> = this.standardMessage.quote?.attachments?.mapNotNull {
|
||||
it.toLocalAttachment()
|
||||
} ?: emptyList()
|
||||
val quoteAttachments: List<Attachment> = this.standardMessage.quote?.toLocalAttachments() ?: emptyList()
|
||||
|
||||
val hasAttachments = attachments.isNotEmpty() || linkPreviewAttachments.isNotEmpty() || quoteAttachments.isNotEmpty() || longTextAttachments.isNotEmpty()
|
||||
|
||||
@@ -980,26 +980,30 @@ class ChatItemArchiveImporter(
|
||||
?: false
|
||||
}
|
||||
|
||||
private fun Quote.QuotedAttachment.toLocalAttachment(): Attachment? {
|
||||
// TODO [backup] quote status not passed through?
|
||||
val thumbnail = this.thumbnail?.toLocalAttachment()
|
||||
|
||||
if (thumbnail != null) {
|
||||
return thumbnail
|
||||
private fun Quote.toLocalAttachments(): List<Attachment> {
|
||||
if (this.type == Quote.Type.VIEW_ONCE) {
|
||||
return listOf(TombstoneAttachment(contentType = MediaUtil.VIEW_ONCE, quote = true))
|
||||
}
|
||||
|
||||
if (this.contentType == null) {
|
||||
return null
|
||||
}
|
||||
return attachments.mapNotNull { attachment ->
|
||||
val thumbnail = attachment.thumbnail?.toLocalAttachment(quote = true)
|
||||
|
||||
// TODO [backup] Need to do the normal ArchiveAttachment thing -- not sure why the conversion to a pointer
|
||||
return PointerAttachment.forPointer(
|
||||
quotedAttachment = DataMessage.Quote.QuotedAttachment(
|
||||
contentType = this.contentType,
|
||||
fileName = this.fileName,
|
||||
thumbnail = null
|
||||
)
|
||||
).orNull()
|
||||
if (thumbnail != null) {
|
||||
return@mapNotNull thumbnail
|
||||
}
|
||||
|
||||
if (attachment.contentType == null) {
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
||||
return@mapNotNull PointerAttachment.forPointer(
|
||||
quotedAttachment = DataMessage.Quote.QuotedAttachment(
|
||||
contentType = attachment.contentType,
|
||||
fileName = attachment.fileName,
|
||||
thumbnail = null
|
||||
)
|
||||
).orNull()
|
||||
}
|
||||
}
|
||||
|
||||
private fun Sticker?.toLocalAttachment(): Attachment? {
|
||||
@@ -1030,16 +1034,17 @@ class ChatItemArchiveImporter(
|
||||
)
|
||||
}
|
||||
|
||||
private fun MessageAttachment.toLocalAttachment(): Attachment? {
|
||||
private fun MessageAttachment.toLocalAttachment(quote: Boolean = false, contentType: String? = pointer?.contentType): Attachment? {
|
||||
return pointer?.toLocalAttachment(
|
||||
importState = importState,
|
||||
voiceNote = flag == MessageAttachment.Flag.VOICE_MESSAGE,
|
||||
gif = flag == MessageAttachment.Flag.GIF,
|
||||
borderless = flag == MessageAttachment.Flag.BORDERLESS,
|
||||
wasDownloaded = wasDownloaded,
|
||||
contentType = pointer.contentType,
|
||||
contentType = contentType,
|
||||
fileName = pointer.fileName,
|
||||
uuid = clientUuid
|
||||
uuid = clientUuid,
|
||||
quote = quote
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -38,7 +38,8 @@ fun FilePointer?.toLocalAttachment(
|
||||
stickerLocator: StickerLocator? = null,
|
||||
contentType: String? = this?.contentType,
|
||||
fileName: String? = this?.fileName,
|
||||
uuid: ByteString? = null
|
||||
uuid: ByteString? = null,
|
||||
quote: Boolean = false
|
||||
): Attachment? {
|
||||
if (this == null) return null
|
||||
|
||||
@@ -82,7 +83,7 @@ fun FilePointer?.toLocalAttachment(
|
||||
voiceNote = voiceNote,
|
||||
borderless = borderless,
|
||||
gif = gif,
|
||||
quote = false,
|
||||
quote = quote,
|
||||
stickerLocator = stickerLocator,
|
||||
uuid = UuidUtil.fromByteStringOrNull(uuid)
|
||||
)
|
||||
@@ -108,7 +109,7 @@ fun FilePointer?.toLocalAttachment(
|
||||
voiceNote = voiceNote,
|
||||
borderless = borderless,
|
||||
gif = gif,
|
||||
quote = false,
|
||||
quote = quote,
|
||||
stickerLocator = stickerLocator,
|
||||
uuid = UuidUtil.fromByteStringOrNull(uuid),
|
||||
fileName = fileName
|
||||
|
||||
@@ -1519,14 +1519,10 @@ class AttachmentTable(
|
||||
|
||||
val insertedAttachments: MutableMap<Attachment, AttachmentId> = mutableMapOf()
|
||||
for (attachment in attachments) {
|
||||
val attachmentId = if (attachment.uri != null) {
|
||||
insertAttachmentWithData(mmsId, attachment, attachment.quote)
|
||||
} else {
|
||||
if (attachment is ArchivedAttachment) {
|
||||
insertArchivedAttachment(mmsId, attachment, attachment.quote)
|
||||
} else {
|
||||
insertUndownloadedAttachment(mmsId, attachment, attachment.quote)
|
||||
}
|
||||
val attachmentId = when {
|
||||
attachment.uri != null -> insertAttachmentWithData(mmsId, attachment, attachment.quote)
|
||||
attachment is ArchivedAttachment -> insertArchivedAttachment(mmsId, attachment, attachment.quote)
|
||||
else -> insertUndownloadedAttachment(mmsId, attachment, attachment.quote)
|
||||
}
|
||||
|
||||
insertedAttachments[attachment] = attachmentId
|
||||
@@ -1535,10 +1531,10 @@ class AttachmentTable(
|
||||
|
||||
try {
|
||||
for (attachment in quoteAttachment) {
|
||||
val attachmentId = if (attachment.uri != null) {
|
||||
insertAttachmentWithData(mmsId, attachment, true)
|
||||
} else {
|
||||
insertUndownloadedAttachment(mmsId, attachment, true)
|
||||
val attachmentId = when {
|
||||
attachment.uri != null -> insertAttachmentWithData(mmsId, attachment, true)
|
||||
attachment is ArchivedAttachment -> insertArchivedAttachment(mmsId, attachment, true)
|
||||
else -> insertUndownloadedAttachment(mmsId, attachment, true)
|
||||
}
|
||||
|
||||
insertedAttachments[attachment] = attachmentId
|
||||
|
||||
Reference in New Issue
Block a user