mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-21 18:26:57 +00:00
Fix potential thread conflict in backup import.
This commit is contained in:
committed by
jeffrey-signal
parent
fd902159ee
commit
ec76372e4d
@@ -235,6 +235,14 @@ object ImportSkips {
|
||||
return log(0, "Failed to parse notificationProfileId for the provided notification profile.")
|
||||
}
|
||||
|
||||
fun failedToCreateChat(): String {
|
||||
return log(0, "Failed to create a Chat. Likely a duplicate recipient was found. Keeping pre-existing data and skipping data in this frame.")
|
||||
}
|
||||
|
||||
fun missingChatRecipient(chatId: Long): String {
|
||||
return log(0, "Missing recipient for chat $chatId")
|
||||
}
|
||||
|
||||
private fun log(sentTimestamp: Long, message: String): String {
|
||||
return "[SKIP][$sentTimestamp] $message"
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ import kotlin.time.Duration.Companion.milliseconds
|
||||
* Handles the importing of [Chat] models into the local database.
|
||||
*/
|
||||
object ChatArchiveImporter {
|
||||
fun import(chat: Chat, recipientId: RecipientId, importState: ImportState): Long {
|
||||
|
||||
fun import(chat: Chat, recipientId: RecipientId, importState: ImportState): Long? {
|
||||
val chatColor = chat.style?.toLocal(importState)
|
||||
|
||||
val wallpaperAttachmentId: AttachmentId? = chat.style?.wallpaperPhoto?.let { filePointer ->
|
||||
@@ -49,6 +50,11 @@ object ChatArchiveImporter {
|
||||
ThreadTable.ACTIVE to 1
|
||||
)
|
||||
.run()
|
||||
.takeIf { it > 0L }
|
||||
|
||||
if (threadId == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
SignalDatabase.writableDatabase
|
||||
.update(
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.thoughtcrime.securesms.backup.v2.processor
|
||||
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.backup.v2.ExportState
|
||||
import org.thoughtcrime.securesms.backup.v2.ImportSkips
|
||||
import org.thoughtcrime.securesms.backup.v2.ImportState
|
||||
import org.thoughtcrime.securesms.backup.v2.database.getThreadsForBackup
|
||||
import org.thoughtcrime.securesms.backup.v2.importer.ChatArchiveImporter
|
||||
@@ -39,11 +40,16 @@ object ChatArchiveProcessor {
|
||||
fun import(chat: Chat, importState: ImportState) {
|
||||
val recipientId: RecipientId? = importState.remoteToLocalRecipientId[chat.recipientId]
|
||||
if (recipientId == null) {
|
||||
Log.w(TAG, "Missing recipient for chat ${chat.id}")
|
||||
Log.w(TAG, ImportSkips.missingChatRecipient(chat.id))
|
||||
return
|
||||
}
|
||||
|
||||
val threadId = ChatArchiveImporter.import(chat, recipientId, importState)
|
||||
if (threadId == null) {
|
||||
Log.w(TAG, ImportSkips.failedToCreateChat())
|
||||
return
|
||||
}
|
||||
|
||||
importState.chatIdToLocalRecipientId[chat.id] = recipientId
|
||||
importState.chatIdToLocalThreadId[chat.id] = threadId
|
||||
importState.chatIdToBackupRecipientId[chat.id] = chat.recipientId
|
||||
|
||||
Reference in New Issue
Block a user