Search in sources :

Example 1 with DecryptedGroupV2Context

use of org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context in project Signal-Android by WhisperSystems.

the class MessageRecord method isSelfCreatedGroup.

public boolean isSelfCreatedGroup() {
    DecryptedGroupV2Context decryptedGroupV2Context = getDecryptedGroupV2Context();
    if (decryptedGroupV2Context == null) {
        return false;
    }
    DecryptedGroupChange change = decryptedGroupV2Context.getChange();
    return selfCreatedGroup(change);
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context)

Example 2 with DecryptedGroupV2Context

use of org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context in project Signal-Android by WhisperSystems.

the class MessageRecord method getGv2ChangeDescription.

@NonNull
public static UpdateDescription getGv2ChangeDescription(@NonNull Context context, @NonNull String body) {
    try {
        ShortStringDescriptionStrategy descriptionStrategy = new ShortStringDescriptionStrategy(context);
        byte[] decoded = Base64.decode(body);
        DecryptedGroupV2Context decryptedGroupV2Context = DecryptedGroupV2Context.parseFrom(decoded);
        GroupsV2UpdateMessageProducer updateMessageProducer = new GroupsV2UpdateMessageProducer(context, descriptionStrategy, Recipient.self().requireServiceId().uuid());
        if (decryptedGroupV2Context.hasChange() && (decryptedGroupV2Context.getGroupState().getRevision() != 0 || decryptedGroupV2Context.hasPreviousGroupState())) {
            return UpdateDescription.concatWithNewLines(updateMessageProducer.describeChanges(decryptedGroupV2Context.getPreviousGroupState(), decryptedGroupV2Context.getChange()));
        } else {
            List<UpdateDescription> newGroupDescriptions = new ArrayList<>();
            newGroupDescriptions.add(updateMessageProducer.describeNewGroup(decryptedGroupV2Context.getGroupState(), decryptedGroupV2Context.getChange()));
            if (decryptedGroupV2Context.getChange().hasNewTimer()) {
                updateMessageProducer.describeNewTimer(decryptedGroupV2Context.getChange(), newGroupDescriptions);
            }
            if (selfCreatedGroup(decryptedGroupV2Context.getChange())) {
                newGroupDescriptions.add(staticUpdateDescription(context.getString(R.string.MessageRecord_invite_friends_to_this_group), 0));
            }
            return UpdateDescription.concatWithNewLines(newGroupDescriptions);
        }
    } catch (IOException | IllegalArgumentException e) {
        Log.w(TAG, "GV2 Message update detail could not be read", e);
        return staticUpdateDescription(context.getString(R.string.MessageRecord_group_updated), R.drawable.ic_update_group_16);
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context) NonNull(androidx.annotation.NonNull)

Example 3 with DecryptedGroupV2Context

use of org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context in project Signal-Android by WhisperSystems.

the class GroupV2UpdateMessageUtilTest method isJustAGroupLeave_whenOtherIsRemoved_shouldReturnFalse.

@Test
public void isJustAGroupLeave_whenOtherIsRemoved_shouldReturnFalse() {
    // GIVEN
    UUID alice = UUID.randomUUID();
    UUID bob = UUID.randomUUID();
    DecryptedGroupChange change = ChangeBuilder.changeBy(alice).deleteMember(bob).build();
    DecryptedGroupV2Context context = DecryptedGroupV2Context.newBuilder().setContext(SignalServiceProtos.GroupContextV2.newBuilder().setMasterKey(ByteString.copyFrom(randomBytes()))).setChange(change).build();
    MessageGroupContext messageGroupContext = new MessageGroupContext(context);
    // WHEN
    boolean isJustAGroupLeave = GroupV2UpdateMessageUtil.isJustAGroupLeave(messageGroupContext);
    // THEN
    assertFalse(isJustAGroupLeave);
}
Also used : MessageGroupContext(org.thoughtcrime.securesms.mms.MessageGroupContext) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) UUID(java.util.UUID) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context) Test(org.junit.Test)

Example 4 with DecryptedGroupV2Context

use of org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context in project Signal-Android by WhisperSystems.

the class GroupV2UpdateMessageUtilTest method isJustAGroupLeave_whenEditorIsRemovedAndOtherChanges_shouldReturnFalse.

@Test
public void isJustAGroupLeave_whenEditorIsRemovedAndOtherChanges_shouldReturnFalse() {
    // GIVEN
    UUID alice = UUID.randomUUID();
    UUID bob = UUID.randomUUID();
    DecryptedGroupChange change = ChangeBuilder.changeBy(alice).deleteMember(alice).addMember(bob).build();
    DecryptedGroupV2Context context = DecryptedGroupV2Context.newBuilder().setContext(SignalServiceProtos.GroupContextV2.newBuilder().setMasterKey(ByteString.copyFrom(randomBytes()))).setChange(change).build();
    MessageGroupContext messageGroupContext = new MessageGroupContext(context);
    // WHEN
    boolean isJustAGroupLeave = GroupV2UpdateMessageUtil.isJustAGroupLeave(messageGroupContext);
    // THEN
    assertFalse(isJustAGroupLeave);
}
Also used : MessageGroupContext(org.thoughtcrime.securesms.mms.MessageGroupContext) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) UUID(java.util.UUID) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context) Test(org.junit.Test)

Example 5 with DecryptedGroupV2Context

use of org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context in project Signal-Android by WhisperSystems.

the class GroupV2UpdateMessageUtilTest method isJustAGroupLeave_whenEditorIsRemoved_shouldReturnTrue.

@Test
public void isJustAGroupLeave_whenEditorIsRemoved_shouldReturnTrue() {
    // GIVEN
    UUID alice = UUID.randomUUID();
    DecryptedGroupChange change = ChangeBuilder.changeBy(alice).deleteMember(alice).build();
    DecryptedGroupV2Context context = DecryptedGroupV2Context.newBuilder().setContext(SignalServiceProtos.GroupContextV2.newBuilder().setMasterKey(ByteString.copyFrom(randomBytes()))).setChange(change).build();
    MessageGroupContext messageGroupContext = new MessageGroupContext(context);
    // WHEN
    boolean isJustAGroupLeave = GroupV2UpdateMessageUtil.isJustAGroupLeave(messageGroupContext);
    // THEN
    assertTrue(isJustAGroupLeave);
}
Also used : MessageGroupContext(org.thoughtcrime.securesms.mms.MessageGroupContext) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) UUID(java.util.UUID) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context) Test(org.junit.Test)

Aggregations

DecryptedGroupV2Context (org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context)18 DecryptedGroupChange (org.signal.storageservice.protos.groups.local.DecryptedGroupChange)12 UUID (java.util.UUID)8 Test (org.junit.Test)6 MessageGroupContext (org.thoughtcrime.securesms.mms.MessageGroupContext)6 NonNull (androidx.annotation.NonNull)4 Nullable (androidx.annotation.Nullable)4 IOException (java.io.IOException)4 DecryptedGroup (org.signal.storageservice.protos.groups.local.DecryptedGroup)4 ArrayList (java.util.ArrayList)2 MmsException (org.thoughtcrime.securesms.mms.MmsException)2 OutgoingGroupUpdateMessage (org.thoughtcrime.securesms.mms.OutgoingGroupUpdateMessage)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 PartialDecryptedGroup (org.whispersystems.signalservice.api.groupsv2.PartialDecryptedGroup)2