Fix potential archive export issue around voice notes in revisions.

This commit is contained in:
Greyson Parrelli
2025-03-21 13:58:46 -04:00
parent f145c20508
commit edf5ecf2d6

View File

@@ -1475,10 +1475,14 @@ fun ChatItem.validateChatItem(): ChatItem? {
fun List<ChatItem>.repairRevisions(current: ChatItem.Builder): List<ChatItem> {
return if (current.standardMessage != null) {
val filtered = this.filter { it.standardMessage != null }
val filtered = this
.filter { it.standardMessage != null }
.map { it.withDowngradeVoiceNotes() }
if (this.size != filtered.size) {
Log.w(TAG, ExportOddities.mismatchedRevisionHistory(current.dateSent))
}
filtered
} else if (current.directStoryReplyMessage != null) {
val filtered = this.filter { it.directStoryReplyMessage != null }
@@ -1506,6 +1510,28 @@ private fun List<MessageAttachment>.withFixedVoiceNotes(textPresent: Boolean): L
}
}
private fun ChatItem.withDowngradeVoiceNotes(): ChatItem {
if (this.standardMessage == null) {
return this
}
if (this.standardMessage.attachments.none { it.flag == MessageAttachment.Flag.VOICE_MESSAGE }) {
return this
}
return this.copy(
standardMessage = this.standardMessage.copy(
attachments = this.standardMessage.attachments.map {
if (it.flag == MessageAttachment.Flag.VOICE_MESSAGE) {
it.copy(flag = MessageAttachment.Flag.NONE)
} else {
it
}
}
)
)
}
private fun Cursor.toBackupMessageRecord(pastIds: Set<Long>, backupStartTime: Long): BackupMessageRecord? {
val id = this.requireLong(MessageTable.ID)
if (pastIds.contains(id)) {