diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ArchiveErrorCases.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ArchiveErrorCases.kt index 3445a04dfe..1beb751e38 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ArchiveErrorCases.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ArchiveErrorCases.kt @@ -119,6 +119,10 @@ object ExportSkips { return log(sentTimestamp, "Failed to parse thread merge event.") } + fun individualChatUpdateInWrongTypeOfChat(sentTimestamp: Long): String { + return log(sentTimestamp, "A chat update that only makes sense for individual chats was found in a different kind of chat.") + } + private fun log(sentTimestamp: Long, message: String): String { return "[SKIP][$sentTimestamp] $message" } 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 f4fc7c4476..b729571ff1 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 @@ -398,7 +398,7 @@ class ChatItemArchiveExporter( if (record.latestRevisionId == null) { builder.revisions = revisionMap.remove(record.id)?.repairRevisions(builder) ?: emptyList() - val chatItem = builder.build().validateChatItem() ?: continue + val chatItem = builder.build().validateChatItem(exportState) ?: continue buffer += chatItem } else { var previousEdits = revisionMap[record.latestRevisionId] @@ -1513,7 +1513,7 @@ private fun ExecutorService.submitTyped(callable: Callable): Future { return this.submit(callable) } -fun ChatItem.validateChatItem(): ChatItem? { +private fun ChatItem.validateChatItem(exportState: ExportState): ChatItem? { if (this.standardMessage == null && this.contactMessage == null && this.stickerMessage == null && @@ -1527,10 +1527,24 @@ fun ChatItem.validateChatItem(): ChatItem? { Log.w(TAG, ExportSkips.emptyChatItem(this.dateSent)) return null } + + if (this.updateMessage != null && this.updateMessage.isOnlyForIndividualChats() && exportState.threadIdToRecipientId[this.chatId] !in exportState.contactRecipientIds) { + Log.w(TAG, ExportSkips.individualChatUpdateInWrongTypeOfChat(this.dateSent)) + return null + } + return this } -fun List.repairRevisions(current: ChatItem.Builder): List { +private fun ChatUpdateMessage.isOnlyForIndividualChats(): Boolean { + return this.simpleUpdate?.type == SimpleChatUpdate.Type.JOINED_SIGNAL || + this.simpleUpdate?.type == SimpleChatUpdate.Type.END_SESSION || + this.simpleUpdate?.type == SimpleChatUpdate.Type.CHAT_SESSION_REFRESH || + this.simpleUpdate?.type == SimpleChatUpdate.Type.PAYMENT_ACTIVATION_REQUEST || + this.simpleUpdate?.type == SimpleChatUpdate.Type.PAYMENTS_ACTIVATED +} + +private fun List.repairRevisions(current: ChatItem.Builder): List { return if (current.standardMessage != null) { val filtered = this .filter { it.standardMessage != null }