From adef572abb7308eb76fc6fb9d4ce7818dec47e86 Mon Sep 17 00:00:00 2001 From: Clark Date: Tue, 30 Apr 2024 11:23:35 -0400 Subject: [PATCH] Store group snapshot attributes in GroupAttributeBlobs. --- .../securesms/backup/v2/ImportExportTest.kt | 16 ++++++++++++-- .../RecipientTableBackupExtensions.kt | 21 +++++++++++-------- app/src/main/protowire/Backup.proto | 19 ++++++++++++----- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/app/src/androidTest/java/org/thoughtcrime/securesms/backup/v2/ImportExportTest.kt b/app/src/androidTest/java/org/thoughtcrime/securesms/backup/v2/ImportExportTest.kt index f7615b9a4e..689afeeeed 100644 --- a/app/src/androidTest/java/org/thoughtcrime/securesms/backup/v2/ImportExportTest.kt +++ b/app/src/androidTest/java/org/thoughtcrime/securesms/backup/v2/ImportExportTest.kt @@ -430,7 +430,13 @@ class ImportExportTest { masterKey = TestRecipientUtils.generateGroupMasterKey().toByteString(), whitelisted = true, hideStory = true, - storySendMode = Group.StorySendMode.ENABLED + storySendMode = Group.StorySendMode.ENABLED, + snapshot = Group.GroupSnapshot( + title = Group.GroupAttributeBlob(title = "Group Cool"), + description = Group.GroupAttributeBlob(descriptionText = "Description"), + version = 10, + disappearingMessagesTimer = Group.GroupAttributeBlob(disappearingMessagesDuration = 1500000) + ) ) ), Recipient( @@ -439,7 +445,13 @@ class ImportExportTest { masterKey = TestRecipientUtils.generateGroupMasterKey().toByteString(), whitelisted = false, hideStory = false, - storySendMode = Group.StorySendMode.DEFAULT + storySendMode = Group.StorySendMode.DEFAULT, + snapshot = Group.GroupSnapshot( + title = Group.GroupAttributeBlob(title = "Group Cool"), + description = Group.GroupAttributeBlob(descriptionText = "Description"), + version = 10, + disappearingMessagesTimer = Group.GroupAttributeBlob(disappearingMessagesDuration = 1500000) + ) ) ) ) diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/RecipientTableBackupExtensions.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/RecipientTableBackupExtensions.kt index f685563864..6b1a110148 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/RecipientTableBackupExtensions.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/RecipientTableBackupExtensions.kt @@ -232,7 +232,10 @@ fun RecipientTable.restoreGroupFromBackup(group: Group): RecipientId { } val recipientId = writableDatabase.insert(RecipientTable.TABLE_NAME, null, values) - SignalDatabase.groups.create(masterKey, decryptedState) + val restoredId = SignalDatabase.groups.create(masterKey, decryptedState) + if (restoredId != null) { + SignalDatabase.groups.setShowAsStoryState(restoredId, group.storySendMode.toGroupShowAsStoryState()) + } return RecipientId.from(recipientId) } @@ -286,16 +289,16 @@ private fun DecryptedGroup.toSnapshot(): Group.GroupSnapshot? { return null } return Group.GroupSnapshot( - title = title, - avatar = avatar, - disappearingMessagesTimer = disappearingMessagesTimer?.duration ?: 0, + title = Group.GroupAttributeBlob(title = title), + avatarUrl = avatar, + disappearingMessagesTimer = Group.GroupAttributeBlob(disappearingMessagesDuration = disappearingMessagesTimer?.duration ?: 0), accessControl = accessControl?.toSnapshot(), version = revision, members = members.map { it.toSnapshot() }, membersPendingProfileKey = pendingMembers.map { it.toSnapshot() }, membersPendingAdminApproval = requestingMembers.map { it.toSnapshot() }, inviteLinkPassword = inviteLinkPassword, - description = description, + description = Group.GroupAttributeBlob(descriptionText = description), announcements_only = isAnnouncementGroup == EnabledState.ENABLED, members_banned = bannedMembers.map { it.toSnapshot() } ) @@ -362,16 +365,16 @@ private fun DecryptedBannedMember.toSnapshot(): Group.MemberBanned { private fun Group.GroupSnapshot.toDecryptedGroup(operations: GroupsV2Operations.GroupOperations): DecryptedGroup { return DecryptedGroup( - title = title, - avatar = avatar, - disappearingMessagesTimer = DecryptedTimer(duration = disappearingMessagesTimer), + title = title?.title ?: "", + avatar = avatarUrl, + disappearingMessagesTimer = DecryptedTimer(duration = disappearingMessagesTimer?.disappearingMessagesDuration ?: 0), accessControl = accessControl?.toLocal(), revision = version, members = members.map { member -> member.toLocal() }, pendingMembers = membersPendingProfileKey.map { pending -> pending.toLocal(operations) }, requestingMembers = membersPendingAdminApproval.map { requesting -> requesting.toLocal() }, inviteLinkPassword = inviteLinkPassword, - description = description, + description = description?.descriptionText ?: "", isAnnouncementGroup = if (announcements_only) EnabledState.ENABLED else EnabledState.DISABLED, bannedMembers = members_banned.map { it.toLocal() } ) diff --git a/app/src/main/protowire/Backup.proto b/app/src/main/protowire/Backup.proto index 4386f398cf..91d60648a3 100644 --- a/app/src/main/protowire/Backup.proto +++ b/app/src/main/protowire/Backup.proto @@ -142,10 +142,10 @@ message Group { // For documentation, defer to Groups.proto. The only name change is Group -> GroupSnapshot to avoid the naming conflict. message GroupSnapshot { bytes publicKey = 1; - string title = 2; - string description = 11; - string avatar = 3; - uint32 disappearingMessagesTimer = 4; + GroupAttributeBlob title = 2; + GroupAttributeBlob description = 11; + string avatarUrl = 3; + GroupAttributeBlob disappearingMessagesTimer = 4; AccessControl accessControl = 5; uint32 version = 6; repeated Member members = 7; @@ -156,6 +156,15 @@ message Group { repeated MemberBanned members_banned = 13; } + message GroupAttributeBlob { + oneof content { + string title = 1; + bytes avatar = 2; + uint32 disappearingMessagesDuration = 3; + string descriptionText = 4; + } + } + message Member { enum Role { UNKNOWN = 0; @@ -179,7 +188,7 @@ message Group { message MemberPendingAdminApproval { bytes userId = 1; bytes profileKey = 2; - bytes presentation = 3; + reserved /*presentation*/ 3; // The field is deprecated in the context of static group state uint64 timestamp = 4; }