Search in sources :

Example 66 with DecryptedGroup

use of org.signal.storageservice.protos.groups.local.DecryptedGroup in project Signal-Android by WhisperSystems.

the class GroupChangeUtil_resolveConflict_decryptedOnly_Test method field_18__promote_requesting_members.

@Test
public void field_18__promote_requesting_members() {
    UUID member1 = UUID.randomUUID();
    UUID member2 = UUID.randomUUID();
    UUID member3 = UUID.randomUUID();
    DecryptedGroup groupState = DecryptedGroup.newBuilder().addMembers(member(member1)).addRequestingMembers(requestingMember(member2)).build();
    DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder().addPromoteRequestingMembers(approveMember(member1)).addPromoteRequestingMembers(approveMember(member2)).addPromoteRequestingMembers(approveMember(member3)).build();
    DecryptedGroupChange resolvedChanges = GroupChangeUtil.resolveConflict(groupState, decryptedChange).build();
    DecryptedGroupChange expected = DecryptedGroupChange.newBuilder().addPromoteRequestingMembers(approveMember(member2)).build();
    assertEquals(expected, resolvedChanges);
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) UUID(java.util.UUID) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 67 with DecryptedGroup

use of org.signal.storageservice.protos.groups.local.DecryptedGroup in project Signal-Android by WhisperSystems.

the class GroupChangeUtil_resolveConflict_decryptedOnly_Test method field_14__no_membership_access_change_is_removed.

@Test
public void field_14__no_membership_access_change_is_removed() {
    DecryptedGroup groupState = DecryptedGroup.newBuilder().setAccessControl(AccessControl.newBuilder().setMembers(AccessControl.AccessRequired.ADMINISTRATOR)).build();
    DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder().setNewMemberAccess(AccessControl.AccessRequired.ADMINISTRATOR).build();
    DecryptedGroupChange resolvedChanges = GroupChangeUtil.resolveConflict(groupState, decryptedChange).build();
    assertTrue(DecryptedGroupUtil.changeIsEmpty(resolvedChanges));
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 68 with DecryptedGroup

use of org.signal.storageservice.protos.groups.local.DecryptedGroup in project Signal-Android by WhisperSystems.

the class GroupChangeUtil_resolveConflict_decryptedOnly_Test method field_7__add_pending_members.

@Test
public void field_7__add_pending_members() {
    UUID member1 = UUID.randomUUID();
    UUID member2 = UUID.randomUUID();
    UUID member3 = UUID.randomUUID();
    DecryptedGroup groupState = DecryptedGroup.newBuilder().addMembers(member(member1)).addPendingMembers(pendingMember(member3)).build();
    DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder().addNewPendingMembers(pendingMember(member1)).addNewPendingMembers(pendingMember(member2)).addNewPendingMembers(pendingMember(member3)).build();
    DecryptedGroupChange resolvedChanges = GroupChangeUtil.resolveConflict(groupState, decryptedChange).build();
    DecryptedGroupChange expected = DecryptedGroupChange.newBuilder().addNewPendingMembers(pendingMember(member2)).build();
    assertEquals(expected, resolvedChanges);
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) UUID(java.util.UUID) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 69 with DecryptedGroup

use of org.signal.storageservice.protos.groups.local.DecryptedGroup in project Signal-Android by WhisperSystems.

the class GroupChangeUtil_resolveConflict_decryptedOnly_Test method field_12__no_timer_change_is_removed.

@Test
public void field_12__no_timer_change_is_removed() {
    DecryptedGroup groupState = DecryptedGroup.newBuilder().setDisappearingMessagesTimer(DecryptedTimer.newBuilder().setDuration(123)).build();
    DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder().setNewTimer(DecryptedTimer.newBuilder().setDuration(123)).build();
    DecryptedGroupChange resolvedChanges = GroupChangeUtil.resolveConflict(groupState, decryptedChange).build();
    assertTrue(DecryptedGroupUtil.changeIsEmpty(resolvedChanges));
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 70 with DecryptedGroup

use of org.signal.storageservice.protos.groups.local.DecryptedGroup in project Signal-Android by WhisperSystems.

the class MessageRequestRepository method getGroupInfo.

void getGroupInfo(@NonNull RecipientId recipientId, @NonNull Consumer<GroupInfo> onGroupInfoLoaded) {
    executor.execute(() -> {
        GroupDatabase groupDatabase = SignalDatabase.groups();
        Optional<GroupDatabase.GroupRecord> groupRecord = groupDatabase.getGroup(recipientId);
        onGroupInfoLoaded.accept(groupRecord.transform(record -> {
            if (record.isV2Group()) {
                DecryptedGroup decryptedGroup = record.requireV2GroupProperties().getDecryptedGroup();
                return new GroupInfo(decryptedGroup.getMembersCount(), decryptedGroup.getPendingMembersCount(), decryptedGroup.getDescription());
            } else {
                return new GroupInfo(record.getMembers().size(), 0, "");
            }
        }).or(GroupInfo.ZERO));
    });
}
Also used : GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup)

Aggregations

DecryptedGroup (org.signal.storageservice.protos.groups.local.DecryptedGroup)328 Test (org.junit.Test)306 DecryptedGroupChange (org.signal.storageservice.protos.groups.local.DecryptedGroupChange)182 UUID (java.util.UUID)110 GroupChange (org.signal.storageservice.protos.groups.GroupChange)58 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)50 ProtoTestUtils.randomProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey)46 DecryptedMember (org.signal.storageservice.protos.groups.local.DecryptedMember)44 ProtoTestUtils.newProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.newProfileKey)24 ProtoTestUtils.withProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.withProfileKey)24 Group (org.signal.storageservice.protos.groups.Group)22 ByteString (com.google.protobuf.ByteString)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 DecryptedPendingMember (org.signal.storageservice.protos.groups.local.DecryptedPendingMember)12 DecryptedRequestingMember (org.signal.storageservice.protos.groups.local.DecryptedRequestingMember)8 NonNull (androidx.annotation.NonNull)6 ArrayList (java.util.ArrayList)6 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)6 Nullable (androidx.annotation.Nullable)4 WorkerThread (androidx.annotation.WorkerThread)4