Search in sources :

Example 26 with DecryptedPendingMember

use of org.signal.storageservice.protos.groups.local.DecryptedPendingMember in project Signal-Android by signalapp.

the class GroupsV2UpdateMessageProducer method describeNewGroup.

/**
 * Describes a group that is new to you, use this when there is no available change record.
 * <p>
 * Invitation and revision 0 groups are the most common use cases for this.
 * <p>
 * When invited, it's possible there's no change available.
 * <p>
 * When the revision of the group is 0, the change is very noisy and only the editor is useful.
 */
UpdateDescription describeNewGroup(@NonNull DecryptedGroup group, @NonNull DecryptedGroupChange decryptedGroupChange) {
    Optional<DecryptedPendingMember> selfPending = DecryptedGroupUtil.findPendingByUuid(group.getPendingMembersList(), selfUuid);
    if (selfPending.isPresent()) {
        return updateDescription(selfPending.get().getAddedByUuid(), inviteBy -> context.getString(R.string.MessageRecord_s_invited_you_to_the_group, inviteBy), R.drawable.ic_update_group_add_16);
    }
    ByteString foundingMemberUuid = decryptedGroupChange.getEditor();
    if (!foundingMemberUuid.isEmpty()) {
        if (selfUuidBytes.equals(foundingMemberUuid)) {
            return updateDescription(context.getString(R.string.MessageRecord_you_created_the_group), R.drawable.ic_update_group_16);
        } else {
            return updateDescription(foundingMemberUuid, creator -> context.getString(R.string.MessageRecord_s_added_you, creator), R.drawable.ic_update_group_add_16);
        }
    }
    if (DecryptedGroupUtil.findMemberByUuid(group.getMembersList(), selfUuid).isPresent()) {
        return updateDescription(context.getString(R.string.MessageRecord_you_joined_the_group), R.drawable.ic_update_group_add_16);
    } else {
        return updateDescription(context.getString(R.string.MessageRecord_group_updated), R.drawable.ic_update_group_16);
    }
}
Also used : ByteString(com.google.protobuf.ByteString) DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember)

Example 27 with DecryptedPendingMember

use of org.signal.storageservice.protos.groups.local.DecryptedPendingMember in project Signal-Android by signalapp.

the class GroupsV2UpdateMessageProducer method describeInvitations.

private void describeInvitations(@NonNull DecryptedGroupChange change, @NonNull List<UpdateDescription> updates) {
    boolean editorIsYou = change.getEditor().equals(selfUuidBytes);
    int notYouInviteCount = 0;
    for (DecryptedPendingMember invitee : change.getNewPendingMembersList()) {
        boolean newMemberIsYou = invitee.getUuid().equals(selfUuidBytes);
        if (newMemberIsYou) {
            updates.add(0, updateDescription(change.getEditor(), editor -> context.getString(R.string.MessageRecord_s_invited_you_to_the_group, editor), R.drawable.ic_update_group_add_16));
        } else {
            if (editorIsYou) {
                updates.add(updateDescription(invitee.getUuid(), newInvitee -> context.getString(R.string.MessageRecord_you_invited_s_to_the_group, newInvitee), R.drawable.ic_update_group_add_16));
            } else {
                notYouInviteCount++;
            }
        }
    }
    if (notYouInviteCount > 0) {
        final int notYouInviteCountFinalCopy = notYouInviteCount;
        updates.add(updateDescription(change.getEditor(), editor -> context.getResources().getQuantityString(R.plurals.MessageRecord_s_invited_members, notYouInviteCountFinalCopy, editor, notYouInviteCountFinalCopy), R.drawable.ic_update_group_add_16));
    }
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) NonNull(androidx.annotation.NonNull) StringUtil(org.thoughtcrime.securesms.util.StringUtil) WorkerThread(androidx.annotation.WorkerThread) GV2AccessLevelUtil(org.thoughtcrime.securesms.groups.GV2AccessLevelUtil) ExpirationUtil(org.thoughtcrime.securesms.util.ExpirationUtil) DrawableRes(androidx.annotation.DrawableRes) AccessControl(org.signal.storageservice.protos.groups.AccessControl) R(org.thoughtcrime.securesms.R) Member(org.signal.storageservice.protos.groups.Member) DecryptedModifyMemberRole(org.signal.storageservice.protos.groups.local.DecryptedModifyMemberRole) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) DecryptedApproveMember(org.signal.storageservice.protos.groups.local.DecryptedApproveMember) LinkedList(java.util.LinkedList) DecryptedRequestingMember(org.signal.storageservice.protos.groups.local.DecryptedRequestingMember) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) ACI(org.whispersystems.signalservice.api.push.ACI) DecryptedGroupUtil(org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil) EnabledState(org.signal.storageservice.protos.groups.local.EnabledState) UuidUtil(org.whispersystems.signalservice.api.util.UuidUtil) DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) UUID(java.util.UUID) Optional(org.whispersystems.libsignal.util.guava.Optional) ByteString(com.google.protobuf.ByteString) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) DecryptedPendingMemberRemoval(org.signal.storageservice.protos.groups.local.DecryptedPendingMemberRemoval) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) Collections(java.util.Collections) DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember)

Example 28 with DecryptedPendingMember

use of org.signal.storageservice.protos.groups.local.DecryptedPendingMember in project Signal-Android by signalapp.

the class DecryptedGroupUtil_apply_Test method remove_pending_member.

@Test
public void remove_pending_member() throws NotAbleToApplyGroupV2ChangeException {
    DecryptedMember member1 = member(UUID.randomUUID());
    UUID pendingUuid = UUID.randomUUID();
    DecryptedPendingMember pending = pendingMember(pendingUuid);
    DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(10).addMembers(member1).addPendingMembers(pending).build(), DecryptedGroupChange.newBuilder().setRevision(11).addDeletePendingMembers(DecryptedPendingMemberRemoval.newBuilder().setUuidCipherText(ProtoTestUtils.encrypt(pendingUuid)).build()).build());
    assertEquals(DecryptedGroup.newBuilder().setRevision(11).addMembers(member1).build(), newGroup);
}
Also used : DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) UUID(java.util.UUID) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) Test(org.junit.Test)

Example 29 with DecryptedPendingMember

use of org.signal.storageservice.protos.groups.local.DecryptedPendingMember in project Signal-Android by signalapp.

the class DecryptedGroupUtil_apply_Test method promote_pending_member.

@Test
public void promote_pending_member() throws NotAbleToApplyGroupV2ChangeException {
    ProfileKey profileKey2 = randomProfileKey();
    DecryptedMember member1 = member(UUID.randomUUID());
    UUID pending2Uuid = UUID.randomUUID();
    DecryptedPendingMember pending2 = pendingMember(pending2Uuid);
    DecryptedMember member2 = member(pending2Uuid, profileKey2);
    DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(10).addMembers(member1).addPendingMembers(pending2).build(), DecryptedGroupChange.newBuilder().setRevision(11).addPromotePendingMembers(member2).build());
    assertEquals(DecryptedGroup.newBuilder().setRevision(11).addMembers(member1).addMembers(member2).build(), newGroup);
}
Also used : DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) UUID(java.util.UUID) ProtoTestUtils.withProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.withProfileKey) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) ProtoTestUtils.randomProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey) ProtoTestUtils.newProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.newProfileKey) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) Test(org.junit.Test)

Example 30 with DecryptedPendingMember

use of org.signal.storageservice.protos.groups.local.DecryptedPendingMember in project Signal-Android by signalapp.

the class DecryptedGroupUtil_apply_Test method apply_new_pending_member_already_pending.

@Test
public void apply_new_pending_member_already_pending() throws NotAbleToApplyGroupV2ChangeException {
    DecryptedMember member1 = member(UUID.randomUUID());
    DecryptedPendingMember pending = pendingMember(UUID.randomUUID());
    DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(10).addMembers(member1).addPendingMembers(pending).build(), DecryptedGroupChange.newBuilder().setRevision(11).addNewPendingMembers(pending).build());
    assertEquals(DecryptedGroup.newBuilder().setRevision(11).addMembers(member1).addPendingMembers(pending).build(), newGroup);
}
Also used : DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) Test(org.junit.Test)

Aggregations

DecryptedPendingMember (org.signal.storageservice.protos.groups.local.DecryptedPendingMember)30 Test (org.junit.Test)18 DecryptedMember (org.signal.storageservice.protos.groups.local.DecryptedMember)18 UUID (java.util.UUID)16 DecryptedGroup (org.signal.storageservice.protos.groups.local.DecryptedGroup)14 ByteString (com.google.protobuf.ByteString)12 DecryptedGroupChange (org.signal.storageservice.protos.groups.local.DecryptedGroupChange)6 DecryptedRequestingMember (org.signal.storageservice.protos.groups.local.DecryptedRequestingMember)6 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)4 ProtoTestUtils.newProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.newProfileKey)4 ProtoTestUtils.randomProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey)4 ProtoTestUtils.withProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.withProfileKey)4 Context (android.content.Context)2 DrawableRes (androidx.annotation.DrawableRes)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 WorkerThread (androidx.annotation.WorkerThread)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2