Various backup/restore bug fixes.

This commit is contained in:
Clark
2024-07-17 12:11:37 -04:00
committed by Greyson Parrelli
parent c622b7fdb1
commit 3184368fa7
4 changed files with 14 additions and 13 deletions

View File

@@ -31,11 +31,17 @@ fun CallLinkTable.getCallLinksForBackup(): BackupCallLinkIterator {
return BackupCallLinkIterator(cursor)
}
fun CallLinkTable.restoreFromBackup(callLink: CallLink): RecipientId {
fun CallLinkTable.restoreFromBackup(callLink: CallLink): RecipientId? {
val rootKey: CallLinkRootKey
try {
rootKey = CallLinkRootKey(callLink.rootKey.toByteArray())
} catch (e: Exception) {
return null
}
return SignalDatabase.callLinks.insertCallLink(
CallLinkTable.CallLink(
recipientId = RecipientId.UNKNOWN,
roomId = CallLinkRoomId.fromCallLinkRootKey(CallLinkRootKey(callLink.rootKey.toByteArray())),
roomId = CallLinkRoomId.fromCallLinkRootKey(rootKey),
credentials = CallLinkCredentials(callLink.rootKey.toByteArray(), callLink.adminKey?.toByteArray()),
state = SignalCallLinkState(
name = callLink.name,
@@ -67,7 +73,9 @@ class BackupCallLinkIterator(private val cursor: Cursor) : Iterator<BackupRecipi
rootKey = callLink.credentials?.linkKeyBytes?.toByteString() ?: ByteString.EMPTY,
adminKey = callLink.credentials?.adminPassBytes?.toByteString(),
name = callLink.state.name,
expirationMs = callLink.state.expiration.toEpochMilli(),
expirationMs = try {
callLink.state.expiration.toEpochMilli()
} catch (e: ArithmeticException) { Long.MAX_VALUE },
restrictions = callLink.state.restrictions.toBackup()
)
)

View File

@@ -180,6 +180,8 @@ class ChatItemImportInserter(
}
val messageInsert = chatItem.toMessageInsert(fromLocalRecipientId, chatLocalRecipientId, localThreadId)
if (chatItem.revisions.isNotEmpty()) {
// Flush to avoid having revisions cross batch boundaries, which will cause a foreign key failure
flush()
val originalId = messageId
val latestRevisionId = originalId + chatItem.revisions.size
val sortedRevisions = chatItem.revisions.sortedBy { it.dateSent }.map { it.toMessageInsert(fromLocalRecipientId, chatLocalRecipientId, localThreadId) }