mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 02:39:55 +01:00
Various backup/restore bug fixes.
This commit is contained in:
@@ -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()
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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) }
|
||||
|
||||
Reference in New Issue
Block a user