diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_00.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_00.binproto index 35dd4996f9..c7f2e71bc0 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_00.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_00.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_01.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_01.binproto index bc98f8c817..fd7937a491 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_01.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_01.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_02.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_02.binproto index 564dfcb0b3..bfe56d3d79 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_02.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_02.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_03.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_03.binproto index a47b22f21e..951fb99bfb 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_03.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_03.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_04.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_04.binproto index 3c702fd562..49325ea8e4 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_04.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_04.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_05.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_05.binproto index 150d2bceb2..931adcfeec 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_05.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_05.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_06.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_06.binproto index fc7683d563..e68d6d936c 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_06.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_06.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_07.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_07.binproto index 273da92115..77a0d2527f 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_07.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_07.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_08.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_08.binproto index b230c03aa5..b43a891141 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_08.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_08.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_09.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_09.binproto index ec5c815ff9..423ad482ef 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_09.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_09.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_10.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_10.binproto index 597870a9d3..836cfabeb0 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_10.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_10.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_11.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_11.binproto index 1c468c85ae..858a8d8686 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_11.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_11.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_12.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_12.binproto index 6882ec7e4f..7534d4dcd4 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_12.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_12.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_13.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_13.binproto index b22ce21ea0..27f36cc18f 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_13.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_13.binproto differ diff --git a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_14.binproto b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_14.binproto index 7cee0ca2c9..414a35f7b4 100644 Binary files a/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_14.binproto and b/app/src/androidTest/assets/backupTests/chat_item_standard_message_with_quote_14.binproto differ diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/exporters/ChatItemArchiveExporter.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/exporters/ChatItemArchiveExporter.kt index 645a6c86da..500d55a381 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/exporters/ChatItemArchiveExporter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/exporters/ChatItemArchiveExporter.kt @@ -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.toRemoteQuoteAttachments(mediaArchiveEnable mediaArchiveEnabled = mediaArchiveEnabled, flagOverride = MessageAttachment.Flag.NONE, contentTypeOverride = "image/jpeg" - ).takeUnless { it.pointer?.invalidAttachmentLocator != null } + ) ) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/importer/ChatItemArchiveImporter.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/importer/ChatItemArchiveImporter.kt index 8b4c1e8b87..3c430baa45 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/importer/ChatItemArchiveImporter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/importer/ChatItemArchiveImporter.kt @@ -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 = this.standardMessage.quote?.attachments?.mapNotNull { - it.toLocalAttachment() - } ?: emptyList() + val quoteAttachments: List = 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 { + 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 ) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/util/ArchiveConverterExtensions.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/util/ArchiveConverterExtensions.kt index 725113b815..62350038bf 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/util/ArchiveConverterExtensions.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/util/ArchiveConverterExtensions.kt @@ -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 diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.kt b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.kt index 317d98a2e0..06cff833ce 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.kt @@ -1519,14 +1519,10 @@ class AttachmentTable( val insertedAttachments: MutableMap = 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