Store group snapshot attributes in GroupAttributeBlobs.

This commit is contained in:
Clark
2024-04-30 11:23:35 -04:00
committed by Greyson Parrelli
parent d6f2039bd1
commit adef572abb
3 changed files with 40 additions and 16 deletions

View File

@@ -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)
)
)
)
)

View File

@@ -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() }
)

View File

@@ -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;
}