Search in sources :

Example 11 with DecryptedGroupV2Context

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

the class MessageRecord method getGv2AddInviteState.

@Nullable
public InviteAddState getGv2AddInviteState() {
    DecryptedGroupV2Context decryptedGroupV2Context = getDecryptedGroupV2Context();
    if (decryptedGroupV2Context == null) {
        return null;
    }
    DecryptedGroup groupState = decryptedGroupV2Context.getGroupState();
    boolean invited = DecryptedGroupUtil.findPendingByUuid(groupState.getPendingMembersList(), Recipient.self().requireServiceId().uuid()).isPresent();
    if (decryptedGroupV2Context.hasChange()) {
        UUID changeEditor = UuidUtil.fromByteStringOrNull(decryptedGroupV2Context.getChange().getEditor());
        if (changeEditor != null) {
            return new InviteAddState(invited, changeEditor);
        }
    }
    Log.w(TAG, "GV2 Message editor could not be determined");
    return null;
}
Also used : UUID(java.util.UUID) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context) Nullable(androidx.annotation.Nullable)

Example 12 with DecryptedGroupV2Context

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

the class MessageRecord method getDecryptedGroupV2Context.

@Nullable
private DecryptedGroupV2Context getDecryptedGroupV2Context() {
    if (!isGroupUpdate() || !isGroupV2()) {
        return null;
    }
    DecryptedGroupV2Context decryptedGroupV2Context;
    try {
        byte[] decoded = Base64.decode(getBody());
        decryptedGroupV2Context = DecryptedGroupV2Context.parseFrom(decoded);
    } catch (IOException e) {
        Log.w(TAG, "GV2 Message update detail could not be read", e);
        decryptedGroupV2Context = null;
    }
    return decryptedGroupV2Context;
}
Also used : IOException(java.io.IOException) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context) Nullable(androidx.annotation.Nullable)

Example 13 with DecryptedGroupV2Context

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

the class MessageRecord method getGv2AddInviteState.

@Nullable
public InviteAddState getGv2AddInviteState() {
    DecryptedGroupV2Context decryptedGroupV2Context = getDecryptedGroupV2Context();
    if (decryptedGroupV2Context == null) {
        return null;
    }
    DecryptedGroup groupState = decryptedGroupV2Context.getGroupState();
    boolean invited = DecryptedGroupUtil.findPendingByUuid(groupState.getPendingMembersList(), Recipient.self().requireServiceId().uuid()).isPresent();
    if (decryptedGroupV2Context.hasChange()) {
        UUID changeEditor = UuidUtil.fromByteStringOrNull(decryptedGroupV2Context.getChange().getEditor());
        if (changeEditor != null) {
            return new InviteAddState(invited, changeEditor);
        }
    }
    Log.w(TAG, "GV2 Message editor could not be determined");
    return null;
}
Also used : UUID(java.util.UUID) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context) Nullable(androidx.annotation.Nullable)

Example 14 with DecryptedGroupV2Context

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

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 15 with DecryptedGroupV2Context

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

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)

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