Fix export bugs causing validation errors.

This commit is contained in:
Cody Henthorne
2024-11-25 16:46:24 -05:00
committed by Greyson Parrelli
parent 3e699a132b
commit 84cb0d357b
4 changed files with 38 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ import org.thoughtcrime.securesms.backup.v2.exporters.ChatItemArchiveExporter
import org.thoughtcrime.securesms.backup.v2.importer.ChatItemArchiveImporter
import org.thoughtcrime.securesms.database.GroupTable
import org.thoughtcrime.securesms.database.MessageTable
import org.thoughtcrime.securesms.database.MessageTypes
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.recipients.RecipientId
@@ -78,6 +79,16 @@ fun MessageTable.getMessagesForBackup(db: SignalDatabase, backupTime: Long, medi
"""
)
// If someone re-registers with a new phone number, previous outgoing messages will no longer be associated with self.
// This cleans it up by changing the from to be the current self id for all outgoing messages.
db.rawWritableDatabase.execSQL(
"""
UPDATE ${MessageTable.TABLE_NAME}
SET ${MessageTable.FROM_RECIPIENT_ID} = ${selfRecipientId.toLong()}
WHERE (${MessageTable.TYPE} & ${MessageTypes.BASE_TYPE_MASK}) IN (${MessageTypes.OUTGOING_MESSAGE_TYPES.joinToString(",")})
"""
)
return ChatItemArchiveExporter(
db = db,
backupStartTime = backupTime,

View File

@@ -237,7 +237,12 @@ class ChatItemArchiveExporter(
}
MessageTypes.isGroupV2(record.type) && MessageTypes.isGroupUpdate(record.type) -> {
builder.updateMessage = record.toRemoteGroupUpdate() ?: continue
val update = record.toRemoteGroupUpdate() ?: continue
if (update.groupChange!!.updates.isEmpty()) {
Log.w(TAG, "Group update record with ID ${record.id} missing updates. Skipping.")
continue
}
builder.updateMessage = update
}
MessageTypes.isGroupV1MigrationEvent(record.type) -> {
@@ -541,7 +546,10 @@ private fun CallTable.Call.toRemoteCallUpdate(db: SignalDatabase, messageRecord:
CallTable.Event.NOT_ACCEPTED -> IndividualCall.State.NOT_ACCEPTED
CallTable.Event.ONGOING -> IndividualCall.State.ACCEPTED
CallTable.Event.DELETE -> return null
else -> IndividualCall.State.UNKNOWN_STATE
else -> {
Log.w(TAG, "Unable to map 1:1 call state from event: ${this.event.name}")
IndividualCall.State.UNKNOWN_STATE
}
},
startedCallTimestamp = this.timestamp,
read = messageRecord.read