mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-22 03:58:48 +00:00
Add support for long text backup.
This commit is contained in:
@@ -685,16 +685,18 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize:
|
|||||||
val linkPreviews = parseLinkPreviews(attachments)
|
val linkPreviews = parseLinkPreviews(attachments)
|
||||||
val linkPreviewAttachments = linkPreviews.mapNotNull { it.thumbnail.orElse(null) }.toSet()
|
val linkPreviewAttachments = linkPreviews.mapNotNull { it.thumbnail.orElse(null) }.toSet()
|
||||||
val quotedAttachments = attachments?.filter { it.quote } ?: emptyList()
|
val quotedAttachments = attachments?.filter { it.quote } ?: emptyList()
|
||||||
|
val longTextAttachment = attachments?.firstOrNull { it.contentType == "text/x-signal-plain" }
|
||||||
val messageAttachments = attachments
|
val messageAttachments = attachments
|
||||||
?.filterNot { it.quote }
|
?.filterNot { it.quote }
|
||||||
?.filterNot { linkPreviewAttachments.contains(it) }
|
?.filterNot { linkPreviewAttachments.contains(it) }
|
||||||
|
?.filterNot { it == longTextAttachment }
|
||||||
?: emptyList()
|
?: emptyList()
|
||||||
return StandardMessage(
|
return StandardMessage(
|
||||||
quote = this.toQuote(quotedAttachments),
|
quote = this.toQuote(quotedAttachments),
|
||||||
text = text,
|
text = text,
|
||||||
attachments = messageAttachments.toBackupAttachments(),
|
attachments = messageAttachments.toBackupAttachments(),
|
||||||
linkPreview = linkPreviews.map { it.toBackupLinkPreview() },
|
linkPreview = linkPreviews.map { it.toBackupLinkPreview() },
|
||||||
longText = null,
|
longText = longTextAttachment?.toRemoteFilePointer(mediaArchiveEnabled),
|
||||||
reactions = reactionRecords.toBackupReactions()
|
reactions = reactionRecords.toBackupReactions()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -381,18 +381,25 @@ class ChatItemImportInserter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val linkPreviews = this.standardMessage.linkPreview.map { it.toLocalLinkPreview() }
|
val linkPreviews = this.standardMessage.linkPreview.map { it.toLocalLinkPreview() }
|
||||||
val linkPreviewAttachments = linkPreviews.mapNotNull { it.thumbnail.orNull() }
|
val linkPreviewAttachments: List<Attachment> = linkPreviews.mapNotNull { it.thumbnail.orNull() }
|
||||||
val attachments = this.standardMessage.attachments.mapNotNull { attachment ->
|
val attachments: List<Attachment> = this.standardMessage.attachments.mapNotNull { attachment ->
|
||||||
attachment.toLocalAttachment()
|
attachment.toLocalAttachment()
|
||||||
}
|
}
|
||||||
|
|
||||||
val quoteAttachments = this.standardMessage.quote?.attachments?.mapNotNull {
|
val longTextAttachments: List<Attachment> = this.standardMessage.longText?.let { longTextPointer ->
|
||||||
|
longTextPointer.toLocalAttachment(
|
||||||
|
importState = importState,
|
||||||
|
contentType = "text/x-signal-plain"
|
||||||
|
)
|
||||||
|
}?.let { listOf(it) } ?: emptyList()
|
||||||
|
|
||||||
|
val quoteAttachments: List<Attachment> = this.standardMessage.quote?.attachments?.mapNotNull {
|
||||||
it.toLocalAttachment()
|
it.toLocalAttachment()
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
|
|
||||||
if (attachments.isNotEmpty() || linkPreviewAttachments.isNotEmpty() || quoteAttachments.isNotEmpty()) {
|
if (attachments.isNotEmpty() || linkPreviewAttachments.isNotEmpty() || quoteAttachments.isNotEmpty() || longTextAttachments.isNotEmpty()) {
|
||||||
followUp = { messageRowId ->
|
followUp = { messageRowId ->
|
||||||
val attachmentMap = SignalDatabase.attachments.insertAttachmentsForMessage(messageRowId, attachments + linkPreviewAttachments, quoteAttachments)
|
val attachmentMap = SignalDatabase.attachments.insertAttachmentsForMessage(messageRowId, attachments + linkPreviewAttachments + longTextAttachments, quoteAttachments)
|
||||||
if (linkPreviews.isNotEmpty()) {
|
if (linkPreviews.isNotEmpty()) {
|
||||||
db.update(
|
db.update(
|
||||||
MessageTable.TABLE_NAME,
|
MessageTable.TABLE_NAME,
|
||||||
@@ -981,13 +988,13 @@ class ChatItemImportInserter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun MessageAttachment.toLocalAttachment(): Attachment? {
|
private fun MessageAttachment.toLocalAttachment(): Attachment? {
|
||||||
return pointer?.toLocalAttachment(
|
return this.pointer?.toLocalAttachment(
|
||||||
importState = importState,
|
importState = importState,
|
||||||
voiceNote = flag == MessageAttachment.Flag.VOICE_MESSAGE,
|
voiceNote = this.flag == MessageAttachment.Flag.VOICE_MESSAGE,
|
||||||
gif = flag == MessageAttachment.Flag.GIF,
|
gif = this.flag == MessageAttachment.Flag.GIF,
|
||||||
borderless = flag == MessageAttachment.Flag.BORDERLESS,
|
borderless = this.flag == MessageAttachment.Flag.BORDERLESS,
|
||||||
wasDownloaded = wasDownloaded,
|
wasDownloaded = this.wasDownloaded,
|
||||||
uuid = clientUuid
|
uuid = this.clientUuid
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user