From aa252b1733ec8845ab658ca94e53bb904b1a1443 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Fri, 27 Sep 2024 16:52:12 -0400 Subject: [PATCH] Add support for Contact.nickname in backup import/export. --- .../database/CallLinkTableBackupExtensions.kt | 4 +-- .../v2/database/ChatItemExportIterator.kt | 31 ++++++++++--------- .../v2/database/ChatItemImportInserter.kt | 2 +- app/src/main/protowire/Backup.proto | 3 +- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/CallLinkTableBackupExtensions.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/CallLinkTableBackupExtensions.kt index fdf2dbe61d..62c9c8fe61 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/CallLinkTableBackupExtensions.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/CallLinkTableBackupExtensions.kt @@ -79,7 +79,7 @@ class BackupCallLinkIterator(private val cursor: Cursor) : Iterator CallLink.Restrictions.ADMIN_APPROVAL CallLinkState.Restrictions.NONE -> CallLink.Restrictions.NONE diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/ChatItemExportIterator.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/ChatItemExportIterator.kt index 14ccd07e05..abdbecf801 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/ChatItemExportIterator.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/ChatItemExportIterator.kt @@ -595,13 +595,13 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize: val contacts = sharedContacts.map { ContactAttachment( - name = it.name.toBackup(), + name = it.name.toRemote(), avatar = (it.avatar?.attachment as? DatabaseAttachment)?.toRemoteMessageAttachment()?.pointer, organization = it.organization, number = it.phoneNumbers.map { phone -> ContactAttachment.Phone( value_ = phone.number, - type = phone.type.toBackup(), + type = phone.type.toRemote(), label = phone.label ) }, @@ -609,12 +609,12 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize: ContactAttachment.Email( value_ = email.email, label = email.label, - type = email.type.toBackup() + type = email.type.toRemote() ) }, address = it.postalAddresses.map { address -> ContactAttachment.PostalAddress( - type = address.type.toBackup(), + type = address.type.toRemote(), label = address.label, street = address.street, pobox = address.poBox, @@ -629,21 +629,22 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize: } return ContactMessage( contact = contacts, - reactions = reactionRecords.toBackupReactions() + reactions = reactionRecords.toRemoteReactions() ) } - private fun Contact.Name.toBackup(): ContactAttachment.Name { + private fun Contact.Name.toRemote(): ContactAttachment.Name { return ContactAttachment.Name( givenName = givenName, familyName = familyName, prefix = prefix, suffix = suffix, - middleName = middleName + middleName = middleName, + nickname = nickname ) } - private fun Contact.Phone.Type.toBackup(): ContactAttachment.Phone.Type { + private fun Contact.Phone.Type.toRemote(): ContactAttachment.Phone.Type { return when (this) { Contact.Phone.Type.HOME -> ContactAttachment.Phone.Type.HOME Contact.Phone.Type.MOBILE -> ContactAttachment.Phone.Type.MOBILE @@ -652,7 +653,7 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize: } } - private fun Contact.Email.Type.toBackup(): ContactAttachment.Email.Type { + private fun Contact.Email.Type.toRemote(): ContactAttachment.Email.Type { return when (this) { Contact.Email.Type.HOME -> ContactAttachment.Email.Type.HOME Contact.Email.Type.MOBILE -> ContactAttachment.Email.Type.MOBILE @@ -661,7 +662,7 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize: } } - private fun Contact.PostalAddress.Type.toBackup(): ContactAttachment.PostalAddress.Type { + private fun Contact.PostalAddress.Type.toRemote(): ContactAttachment.PostalAddress.Type { return when (this) { Contact.PostalAddress.Type.HOME -> ContactAttachment.PostalAddress.Type.HOME Contact.PostalAddress.Type.WORK -> ContactAttachment.PostalAddress.Type.WORK @@ -693,7 +694,7 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize: attachments = messageAttachments.toBackupAttachments(), linkPreview = linkPreviews.map { it.toRemoteLinkPreview() }, longText = longTextAttachment?.toRemoteFilePointer(mediaArchiveEnabled), - reactions = reactionRecords.toBackupReactions() + reactions = reactionRecords.toRemoteReactions() ) } @@ -749,7 +750,7 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize: emoji = stickerLocator.emoji, data_ = this.toRemoteMessageAttachment().pointer ), - reactions = reactions.toBackupReactions() + reactions = reactions.toRemoteReactions() ) } @@ -796,14 +797,14 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize: timestamp = this.timestamp, blockIndex = this.blockIndex, blockTimestamp = this.blockTimestamp, - mobileCoinIdentification = this.paymentMetaData.mobileCoinTxoIdentification?.toBackup(), + mobileCoinIdentification = this.paymentMetaData.mobileCoinTxoIdentification?.toRemote(), transaction = this.transaction?.toByteString(), receipt = this.receipt?.toByteString() ) ) } - private fun PaymentMetaData.MobileCoinTxoIdentification.toBackup(): PaymentNotification.TransactionDetails.MobileCoinTxoIdentification { + private fun PaymentMetaData.MobileCoinTxoIdentification.toRemote(): PaymentNotification.TransactionDetails.MobileCoinTxoIdentification { return PaymentNotification.TransactionDetails.MobileCoinTxoIdentification( publicKey = this.publicKey, keyImages = this.keyImages @@ -873,7 +874,7 @@ class ChatItemExportIterator(private val cursor: Cursor, private val batchSize: } } - private fun List?.toBackupReactions(): List { + private fun List?.toRemoteReactions(): List { return this ?.map { Reaction( diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/ChatItemImportInserter.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/ChatItemImportInserter.kt index d6c9f28907..119f96510c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/ChatItemImportInserter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/ChatItemImportInserter.kt @@ -1020,7 +1020,7 @@ class ChatItemImportInserter( } private fun ContactAttachment.Name?.toLocal(): Contact.Name { - return Contact.Name(this?.givenName, this?.familyName, this?.prefix, this?.suffix, this?.middleName, null) + return Contact.Name(this?.givenName, this?.familyName, this?.prefix, this?.suffix, this?.middleName, this?.nickname) } private fun ContactAttachment.Phone.Type?.toLocal(): Contact.Phone.Type { diff --git a/app/src/main/protowire/Backup.proto b/app/src/main/protowire/Backup.proto index aaa1aab0dd..624433d16a 100644 --- a/app/src/main/protowire/Backup.proto +++ b/app/src/main/protowire/Backup.proto @@ -476,6 +476,7 @@ message ContactAttachment { optional string prefix = 3; optional string suffix = 4; optional string middleName = 5; + optional string nickname = 6; } message Phone { @@ -621,7 +622,7 @@ message FilePointer { oneof locator { BackupLocator backupLocator = 1; - AttachmentLocator attachmentLocator = 2; + AttachmentLocator attachmentLocator= 2; InvalidAttachmentLocator invalidAttachmentLocator = 3; }