From 548da6a09d5b30021368740afa2df420ae5cbb31 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 3 Dec 2024 09:59:08 -0500 Subject: [PATCH] Update to the latest backup tests. --- ...em_standard_message_with_quote_00.binproto | Bin 581 -> 618 bytes ...em_standard_message_with_quote_01.binproto | Bin 635 -> 835 bytes ...em_standard_message_with_quote_02.binproto | Bin 1151 -> 1355 bytes ...em_standard_message_with_quote_03.binproto | Bin 660 -> 850 bytes ...em_standard_message_with_quote_04.binproto | Bin 555 -> 592 bytes ...em_standard_message_with_quote_05.binproto | Bin 761 -> 931 bytes ...em_standard_message_with_quote_06.binproto | Bin 748 -> 895 bytes ...em_standard_message_with_quote_07.binproto | Bin 708 -> 815 bytes ...em_standard_message_with_quote_08.binproto | Bin 768 -> 918 bytes ...em_standard_message_with_quote_09.binproto | Bin 712 -> 912 bytes ...em_standard_message_with_quote_10.binproto | Bin 674 -> 881 bytes ...em_standard_message_with_quote_11.binproto | Bin 746 -> 934 bytes ...em_standard_message_with_quote_12.binproto | Bin 655 -> 818 bytes ...em_standard_message_with_quote_13.binproto | Bin 860 -> 897 bytes ...em_standard_message_with_quote_14.binproto | Bin 622 -> 643 bytes .../v2/exporters/ChatItemArchiveExporter.kt | 27 +++++++--- .../v2/importer/ChatItemArchiveImporter.kt | 51 ++++++++++-------- .../v2/util/ArchiveConverterExtensions.kt | 7 +-- .../securesms/database/AttachmentTable.kt | 20 +++---- 19 files changed, 60 insertions(+), 45 deletions(-) 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 35dd4996f9f7b5e1162eca58832aecc1f5baaa8f..c7f2e71bc0fa35f69a3048c44fa2bc5ac456e141 100644 GIT binary patch delta 61 zcmV-D0K)&p1nLB^M*#_j0TP1&2m}&;lTHCzBXS`H>UD*yPi^6mI`##hX|)Q{Y*nu( TdE*=2Sl-CG7G4%klc)imqS_cr delta 23 fcmaFGa+GC*J0p9NPyz>wP|V~2#;D0>8Rr53R&@tK 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 bc98f8c817ada644a047e415f3f45244110bef19..fd7937a4914c31e373a497d53312c15126f16fa2 100644 GIT binary patch delta 301 zcmey(a+qy{J0oWsqfj#=2a8bsWIx6zXnbB z??v1@u}dsY%y04v#*X?oj7l#VIhX`kBvw3`x9y#o6CcODGye}CH56F%r{&^olc>{- zTx%IQ7zJ3Q*tl2{i&N5+<}h+`W#%TPr|M@Fq^3*tGIDh>Dj|tDw2FG1;*65wP|V~2#;D0>89SK0lsqO!G0Es?bMbL73b07Aaj_&8r=)2x f3ISPpnZ-Fqf?O;g=1*!6V3hd$`RTu91`3P-^YRrp 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 564dfcb0b3a01354d10e06b48513e569a8e95aed..bfe56d3d79fbb3ce7934bffd0456d350e7355aa1 100644 GIT binary patch delta 277 zcmey*ahhv`J0oWsqfj#=2a8bsWIx6zXnbB z??v1@u}dsY%y07wMoXr^!%RvCm^hdO7$sIdnYZnonHL)u3kQo7L)0oJt}Toli~=lD zK#|1alr*Kqj9grqxryni`dJ03=~7b|x%wHEkVG8buz9Q#n|zu{J|UJ%!N@e#EGf}4 z)i}vG)gsL>&B($$&Co2#B+=N?%*ZS)O@LWSK)FlgRrImm*Z4K{Of#zyccfohL{(stdqjc11(O8hWG7E1cPi{0-U^Eis RV)-zCVy^&;L@z{$2>|SBU5Nky delta 98 zcmX@j^`B#dJ0p9NPyz>wP|V~2#;DC_87-MK=P)YGWaMBHV3b(-WZt%SW?pPuEF3IS y3{lODTznji0xVKMfyCmJw8__4qNG26e)?~jfdZqEAQ#Jr`4f8uSR}qcgqQ$jMIO%p 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 a47b22f21ecf628bffd00cb756ebb7abd3a89cc3..951fb99bfbd63b67048f1a7b0f15a7eb0614217d 100644 GIT binary patch delta 235 zcmbQjdWmg=J0oWsqfj#=2a8bsWIx6zXnbB z??v1@u}dsY%y04v#s=1ACZz_Z$=Xb^^$!`jW;1dy3a}_mV&vk=%uP&B)z2zOO_yqB zWWvh6ygF?H(6pRAMpnOp(Cp-yiA delta 67 zcmV-J0KEUw29yP`M*#<75?}}f5?qr|0a}yI0e~lKB54Q$5CIsfUD*yPi^6mI`##hX|)Q{Y*nu( cdE*=2Sl-CG7G4%klc)iE2#mn*$+0yc0fjys2LJ#7 delta 32 ocmcb>vYKUsJ0p9NPyz>wP|V~2#;D0>8LK%ye}4LJnSlZ$0IXmOvj6}9 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 150d2bceb20929d1564ee31d8a9efe254b010fba..931adcfeec7827fc863357741e8568e008d38a98 100644 GIT binary patch delta 262 zcmey#x|n@~J0oWsqfj#=2a8bsWIx6zXnbB z??v1@u}dsY%y04v#$ENZn3Se7aWDxmO00P@Z`(UFFAgp?4i+sY4#ueej9i_J9E<`i zN)3!$T$#Cv>8biz1*z#$MO+0+NPLG@QIAucQ8GTBzE-tCP8RmMaXxw}Cb9l{dD-6a zMWvqh`6)tnTwGZ$1pyVgJ{}={0!$M3w$1xD$5cr}py~x{h=^)4>-RG0tL(xm;aUQ^ z{b$RCPHZYTd2z4&(U^}31~Z=YI81I~ijwX*@c!gRQw2sNK`xdL^C$KSut@YmgqQ%E CY+OMA delta 90 zcmZ3?{*!fsJ0p9NPyz>wP|V~2#;D0>8Fwj7WmKBP$iXDQD6!_rylwByyg0bnI9Rlp qI2faXnbB z??v1@u}dsY%y04v##{B*7?mzFaxe)nO00b{Z`(UFFJ3Ng4iFASJyk!eAT?bonk!rhiSO`+&10RIkTVybhm)hDw}(?mqGy3$wzmMY z#I!B<8@r5@1Qs^TdZ_lwP|V~2#;D0>8E-LXDy2_e!z9h_&BeySD8Mq=irEzaB?Akh 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 273da92115e2658ab60810a6b9d6ecee8ef5fca6..77a0d2527f6f15c32f02b990878235075ff80f75 100644 GIT binary patch delta 201 zcmX@Yx}I%=J0oWsqfj#=2a8bsWIx6zXnbB z??v1@u}dsY%y04v#vAn=j7qJH983a?66>DK+xE`Pi=T^^gGFHd+*36{Mz1nQ$2?A@LpFN_d=RkCO38^T{v^%TKiQ^9;8y_jA+D v&-c-_4tI>O$gh-Q&|nl|<6_CnEY2|!i&hUVtRNh!vbMu`?iCP}GD#>oNCL{wVJ$N+h|Okdh#c$1fvF{kT;iS$>d2)!O}ek-k;oP Ws=#O@$i?zu{={AZ7KvVn5EB5|XHC%n delta 88 zcmbQn-oUoOosm6BD1n1TC}wg1W7OocjE5B_Gb&AB27t4qF6MF?%B)&j|m;hfb8}0xA 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 ec5c815ff9c410836258fdbbe63a73746bfab1a7..423ad482ef4c461e80b37b71e12c6ed627afef23 100644 GIT binary patch delta 245 zcmX@XI)QzIJ0oWsqfj#=2a8bsWIx6zXnbB z??v1@u}dsY%y04v#x1P9OiEo$ljE6W>t8c+EoJ0j6kt)B!^p*znVXoNs-IPmnl9DL z$koNDge2n7D(Z2HGfKuM%_qYwEI-lG&okV<+|NxnKi@~!I@~eBBEOO=f=j{J$SBz$ z+0fWD$s*0zGRe%;(9GB{Db*r1F)78!FvVPeNlL)qb(zTG$*VZKHP2ss81?ov$nuiWRX$-M`B@eWlbe}b0Y0Hp=Kufz delta 67 zcmV-J0KET@2gn7mM*#<75?}}f5?qr|0a}yI0kkJ;B54Q$5CIslXnbB z??v1@u}dsY%y04v#vS#q7?qwgaxe)nN^E>GZ`(UFFJ3Ng4iAm0E^OMMlP<*+{E-${j7r2bg3zfT>XqnNFokz*gV#WMalTMyKANC=w|BW=;qtI ztJK*?m6#WJ_!-)kxEgcCaw!;@rkW)sTBaH&8K+w0rWvLgS(v98nkAVe8e5tfnWd!( zFiQz2cZs}8-#AU{`0U9FFB{E@lmt|t?V4w8*DtS8FScdzG`0U4zowpPW;NoD^h=AV s3QTg3DDbynl3>(e6k_9I$;&LxF%slr`7nP{1JG+d2i~9DXsW;n0K0Z%SpWb4 delta 68 zcmV-K0K5P32BHP9M*#<75?}}f5?qr|0a}yI0k{J}B0rOg0vjYF3I+%P5CkXz5(Wwc aZfSFDG7$;{@Sl=^5CItT^X2}gFdzYKOcQnh 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 1c468c85ae7d30eadb1d52841824165f5af7e3a9..858a8d8686246a6561fe6ce2a2c7b287b0ae229c 100644 GIT binary patch delta 278 zcmaFGx{Q5;J0oWsqfj#=2a8bsWIx6zXnbB z??v1@u}dsY%y04v#-Nb<|d}6>SqE$E9GNYHDn1Y-pL3YG`3(Y+#;ZWRPN!Y?NqhXk?sXk(g{Gz#t{CPUy$B zyIMs;8zU|rnkw<=mXbhSaIoY)31#+6yoVMG*>)Y$m^$_3Pu9t$Oi|K32i~9DXsWwP|V~2#;D0>8P_UIW>lKM$iXDQD6#3uylwByyx6!{I9Qw* qqN=&rI2Z+3CL1zGNq_$Q^xrZA1x6!5E|w4TC-w@kNPK|^F#!OFdK`2B 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 6882ec7e4ffc985aa9edfa95cc10098d91ba2923..7534d4dcd4ff3da580a575d5b6b811ebc27ca7ee 100644 GIT binary patch delta 230 zcmeBY-Nd%RosqMRQK*@bgGH!*vL9oVa*-nItJ2oh{<#k)T76@kpShLmQcmc4^~%T6 z_ag3{*d-Px<~Ml-V{QF2My1D$983a?5}TjQ+xE`PiyfTOi$I%Do9P2%Hm2>LgGis_;>~Bn3<*O)j3y`s`}*n_|^m)sTzle zd*&DC3R!XSc{n*bdV4s9BzhM3WqT_Lte0FCz|gC5gHxGduW-7{hlN@KqJk`j4M9pp Z0c%Rc{`v%T8l1VlvyWYZak3YaD*(dDO*{Yq delta 43 zcmdnQ*3Y`Zosm6BD1n1TC}wg1W7OocjJ3>}O6imRnWWjhx!5=u1z0A(WpV`o{v!(T 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 b22ce21ea08c3ffad15838f268b01f820102c736..27f36cc18f79fe55ffbbea9e81c165bf7f65f095 100644 GIT binary patch delta 71 zcmV-N0J#6$27w2#M*#_j0TP1&2m}&;lTHCzBXS`H>UD*yPi^6mI`##hX|)Q{Y*nu( ddE*=2Sl-CG7G4%kv#0^A0SJu1@5!+>AOV`Y96$g7 delta 33 pcmZoeaEuFosm6BD1n1TC}wg1W0aN^1BVnF2a^Cx0Hc(W1c)KQ=)}gsD8MMe7{wvP z#>J9YoRT(=QEB$%4~*hM&5T@pKuH!UsDuXNWC5lK>Cc~^{#$0Cz-T1M#qweP#9p8& IUm!wE086$Ur~m)} 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