Ensure that audio attachments with text aren't exported as voice notes.

This commit is contained in:
Greyson Parrelli
2025-02-13 15:58:50 -05:00
parent 27d084080c
commit c1ce4ba80d

View File

@@ -1003,7 +1003,7 @@ private fun BackupMessageRecord.toRemoteStandardMessage(exportState: ExportState
return StandardMessage(
quote = this.toRemoteQuote(mediaArchiveEnabled, quotedAttachments),
text = text.takeUnless { hasVoiceNote },
attachments = messageAttachments.toRemoteAttachments(mediaArchiveEnabled),
attachments = messageAttachments.toRemoteAttachments(mediaArchiveEnabled).withFixedVoiceNotes(textPresent = text != null || longTextAttachment != null),
linkPreview = linkPreviews.map { it.toRemoteLinkPreview(mediaArchiveEnabled) },
longText = longTextAttachment?.toRemoteFilePointer(mediaArchiveEnabled),
reactions = reactionRecords.toRemote()
@@ -1496,6 +1496,16 @@ private fun Text?.isNullOrBlank(): Boolean {
return this == null || this.body.isBlank()
}
private fun List<MessageAttachment>.withFixedVoiceNotes(textPresent: Boolean): List<MessageAttachment> {
return this.map {
if (textPresent && 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)) {