Add backup support for direct story reply revisions.

This commit is contained in:
Greyson Parrelli 2025-01-17 15:07:43 -05:00
parent 960bab4f94
commit a74ccdf25e
17 changed files with 31 additions and 10 deletions

View file

@ -81,6 +81,11 @@ class ArchiveImportExportTests {
runTests { it.startsWith("chat_item_direct_story_reply_") }
}
// @Test
fun chatItemDirectStoryReplyMessageWithEdits() {
runTests { it.startsWith("chat_item_direct_story_reply_with_edits_") }
}
// @Test
fun chatItemExpirationTimerUpdate() {
runTests { it.startsWith("chat_item_expiration_timer_update_") }

View file

@ -58,8 +58,12 @@ object ExportSkips {
*/
object ExportOddities {
fun revisionsOnNonStandardMessage(sentTimestamp: Long): String {
return log(sentTimestamp, "Attempted to set revisions on a non-standard message. Ignoring revisions.")
fun revisionsOnUnexpectedMessageType(sentTimestamp: Long): String {
return log(sentTimestamp, "Attempted to set revisions on message that doesn't support it. Ignoring revisions.")
}
fun mismatchedRevisionHistory(sentTimestamp: Long): String {
return log(sentTimestamp, "Revisions for this message contained items of a different type than the parent item. Ignoring mismatched revisions.")
}
fun outgoingMessageWasSentButTimerNotStarted(sentTimestamp: Long): String {

View file

@ -325,14 +325,7 @@ class ChatItemArchiveExporter(
}
if (record.latestRevisionId == null) {
val previousEdits = revisionMap.remove(record.id)
if (previousEdits != null) {
if (builder.standardMessage != null) {
builder.revisions = previousEdits
} else {
Log.w(TAG, ExportOddities.revisionsOnNonStandardMessage(record.dateSent))
}
}
builder.revisions = revisionMap.remove(record.id)?.repairRevisions(builder) ?: emptyList()
buffer += builder.build()
} else {
var previousEdits = revisionMap[record.latestRevisionId]
@ -1331,6 +1324,25 @@ private fun <T> ExecutorService.submitTyped(callable: Callable<T>): Future<T> {
return this.submit(callable)
}
fun List<ChatItem>.repairRevisions(current: ChatItem.Builder): List<ChatItem> {
return if (current.standardMessage != null) {
val filtered = this.filter { it.standardMessage != null }
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 }
if (this.size != filtered.size) {
Log.w(TAG, ExportOddities.mismatchedRevisionHistory(current.dateSent))
}
filtered
} else {
Log.w(TAG, ExportOddities.revisionsOnUnexpectedMessageType(current.dateSent))
emptyList()
}
}
private fun Cursor.toBackupMessageRecord(pastIds: Set<Long>, backupStartTime: Long): BackupMessageRecord? {
val id = this.requireLong(MessageTable.ID)
if (pastIds.contains(id)) {