Fix individual and adhoc call backup import/export.

This commit is contained in:
Greyson Parrelli
2024-09-25 11:23:11 -04:00
parent bf338a6835
commit b6906990bc
4 changed files with 26 additions and 44 deletions

View File

@@ -46,62 +46,51 @@ class ArchiveImportExportTests {
val MASTER_KEY = Base64.decode("sHuBMP4ToZk4tcNU+S8eBUeCt8Am5EZnvuqTBJIR4Do")
}
// @Test
@Test
fun all() {
runTests()
}
@Test
fun temp() {
runTests { it == "chat_item_standard_message_formatted_text_03.binproto" }
}
// Passing
// @Test
fun accountData() {
runTests { it.startsWith("account_data_") }
}
@Test
// @Test
fun adHocCall() {
runTests { it.startsWith("ad_hoc_call") }
runTests { it.startsWith("ad_hoc_call_") }
}
// Passing
// @Test
fun chat() {
runTests { it.startsWith("chat_") && !it.contains("_item") }
}
// Passing
// @Test
fun chatItemContactMessage() {
runTests { it.startsWith("chat_item_contact_message_") }
}
// Passing
// @Test
fun chatItemExpirationTimerUpdate() {
runTests { it.startsWith("chat_item_expiration_timer_") }
}
// Passing
// @Test
fun chatItemGiftBadge() {
runTests { it.startsWith("chat_item_gift_badge_") }
}
@Test
// @Test
fun chatItemGroupCallUpdate() {
runTests { it.startsWith("chat_item_group_call_update_") }
}
@Test
// @Test
fun chatItemIndividualCallUpdate() {
runTests { it.startsWith("chat_item_individual_call_update_") }
}
// Passing
// @Test
fun chatItemLearnedProfileUpdate() {
runTests { it.startsWith("chat_item_learned_profile_update_") }
@@ -112,19 +101,16 @@ class ArchiveImportExportTests {
runTests { it.startsWith("chat_item_payment_notification_") }
}
// Passing
// @Test
fun chatItemProfileChangeUpdate() {
runTests { it.startsWith("chat_item_profile_change_update_") }
}
// Passing
// @Test
fun chatItemRemoteDelete() {
runTests { it.startsWith("chat_item_remote_delete_") }
}
// Passing
// @Test
fun chatItemSessionSwitchoverUpdate() {
runTests { it.startsWith("chat_item_session_switchover_update_") }
@@ -135,7 +121,6 @@ class ArchiveImportExportTests {
runTests { it.startsWith("chat_item_simple_updates_") }
}
// Passing
// @Test
fun chatItemStandardMessageFormattedText() {
runTests { it.startsWith("chat_item_standard_message_formatted_text_") }
@@ -146,19 +131,16 @@ class ArchiveImportExportTests {
runTests { it.startsWith("chat_item_standard_message_long_text_") }
}
// Passing
// @Test
fun chatItemStandardMessageSpecialAttachments() {
runTests { it.startsWith("chat_item_standard_message_special_attachments_") }
}
// Passing
// @Test
fun chatItemStandardMessageStandardAttachments() {
runTests { it.startsWith("chat_item_standard_message_standard_attachments_") }
}
// Passing
// @Test
fun chatItemStandardMessageTextOnly() {
runTests { it.startsWith("chat_item_standard_message_text_only_") }
@@ -179,30 +161,26 @@ class ArchiveImportExportTests {
runTests { it.startsWith("chat_item_sticker_message_") }
}
// Passing
// @Test
fun chatItemThreadMergeUpdate() {
runTests { it.startsWith("chat_item_thread_merge_update_") }
}
@Test
// @Test
fun recipientCallLink() {
runTests { it.startsWith("recipient_call_link_") }
}
// Passing
// @Test
fun recipientContacts() {
runTests { it.startsWith("recipient_contacts_") }
}
// Passing
// @Test
fun recipientDistributionLists() {
runTests { it.startsWith("recipient_distribution_list_") }
}
// Passing
// @Test
fun recipientGroups() {
runTests { it.startsWith("recipient_groups_") }

View File

@@ -6,8 +6,7 @@
package org.thoughtcrime.securesms.backup.v2.database
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import androidx.core.content.contentValuesOf
import org.signal.core.util.insertInto
import org.signal.core.util.requireLong
import org.signal.core.util.select
import org.thoughtcrime.securesms.backup.v2.ImportState
@@ -21,7 +20,7 @@ fun CallTable.getAdhocCallsForBackup(): CallLogIterator {
readableDatabase
.select()
.from(CallTable.TABLE_NAME)
.where("${CallTable.TYPE}=?", CallTable.Type.AD_HOC_CALL)
.where("${CallTable.TYPE} = ?", CallTable.Type.serialize(CallTable.Type.AD_HOC_CALL))
.run()
)
}
@@ -32,16 +31,18 @@ fun CallTable.restoreCallLogFromBackup(call: AdHocCall, importState: ImportState
AdHocCall.State.UNKNOWN_STATE -> CallTable.Event.GENERIC_GROUP_CALL
}
val values = contentValuesOf(
CallTable.CALL_ID to call.callId,
CallTable.PEER to importState.remoteToLocalRecipientId[call.recipientId]!!.serialize(),
CallTable.TYPE to CallTable.Type.serialize(CallTable.Type.AD_HOC_CALL),
CallTable.DIRECTION to CallTable.Direction.serialize(CallTable.Direction.OUTGOING),
CallTable.EVENT to CallTable.Event.serialize(event),
CallTable.TIMESTAMP to call.callTimestamp
)
writableDatabase.insert(CallTable.TABLE_NAME, SQLiteDatabase.CONFLICT_IGNORE, values)
val result = writableDatabase
.insertInto(CallTable.TABLE_NAME)
.values(
CallTable.CALL_ID to call.callId,
CallTable.PEER to importState.remoteToLocalRecipientId[call.recipientId]!!.serialize(),
CallTable.TYPE to CallTable.Type.serialize(CallTable.Type.AD_HOC_CALL),
CallTable.DIRECTION to CallTable.Direction.serialize(CallTable.Direction.OUTGOING),
CallTable.EVENT to CallTable.Event.serialize(event),
CallTable.TIMESTAMP to call.callTimestamp
)
.run()
return Unit
}
/**

View File

@@ -460,7 +460,8 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize:
)
}
CallTable.Type.AD_HOC_CALL -> {
CallTable.Type.AUDIO_CALL,
CallTable.Type.VIDEO_CALL -> {
ChatUpdateMessage(
individualCall = IndividualCall(
callId = this.callId,
@@ -473,12 +474,13 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize:
CallTable.Event.NOT_ACCEPTED -> IndividualCall.State.NOT_ACCEPTED
else -> IndividualCall.State.UNKNOWN_STATE
},
startedCallTimestamp = this.timestamp
startedCallTimestamp = this.timestamp,
read = messageRecord.read
)
)
}
else -> null
CallTable.Type.AD_HOC_CALL -> throw IllegalArgumentException("AdHoc calls are not update messages!")
}
}

View File

@@ -696,6 +696,7 @@ class ChatItemImportInserter(
}
}
}
this.put(MessageTable.READ, updateMessage.individualCall.read.toInt())
}
updateMessage.groupCall != null -> {
val startedCallRecipientId = if (updateMessage.groupCall.startedCallRecipientId != null) {