Search in sources :

Example 6 with DecryptedGroupV2Context

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

the class GroupProtoUtil method createDecryptedGroupV2Context.

public static DecryptedGroupV2Context createDecryptedGroupV2Context(@NonNull GroupMasterKey masterKey, @NonNull GroupMutation groupMutation, @Nullable GroupChange signedServerChange) {
    DecryptedGroupChange plainGroupChange = groupMutation.getGroupChange();
    DecryptedGroup decryptedGroup = groupMutation.getNewGroupState();
    int revision = plainGroupChange != null ? plainGroupChange.getRevision() : decryptedGroup.getRevision();
    SignalServiceProtos.GroupContextV2.Builder contextBuilder = SignalServiceProtos.GroupContextV2.newBuilder().setMasterKey(ByteString.copyFrom(masterKey.serialize())).setRevision(revision);
    if (signedServerChange != null) {
        contextBuilder.setGroupChange(signedServerChange.toByteString());
    }
    DecryptedGroupV2Context.Builder builder = DecryptedGroupV2Context.newBuilder().setContext(contextBuilder.build()).setGroupState(decryptedGroup);
    if (groupMutation.getPreviousGroupState() != null) {
        builder.setPreviousGroupState(groupMutation.getPreviousGroupState());
    }
    if (plainGroupChange != null) {
        builder.setChange(plainGroupChange);
    }
    return builder.build();
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) PartialDecryptedGroup(org.whispersystems.signalservice.api.groupsv2.PartialDecryptedGroup) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context)

Example 7 with DecryptedGroupV2Context

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

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

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

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

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

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)

Example 10 with DecryptedGroupV2Context

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

the class GroupManagerV2 method sendGroupUpdate.

@NonNull
private RecipientAndThread sendGroupUpdate(@NonNull GroupMasterKey masterKey, @NonNull GroupMutation groupMutation, @Nullable GroupChange signedGroupChange, boolean sendToMembers) {
    GroupId.V2 groupId = GroupId.v2(masterKey);
    Recipient groupRecipient = Recipient.externalGroupExact(context, groupId);
    DecryptedGroupV2Context decryptedGroupV2Context = GroupProtoUtil.createDecryptedGroupV2Context(masterKey, groupMutation, signedGroupChange);
    OutgoingGroupUpdateMessage outgoingMessage = new OutgoingGroupUpdateMessage(groupRecipient, decryptedGroupV2Context, null, System.currentTimeMillis(), 0, false, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    DecryptedGroupChange plainGroupChange = groupMutation.getGroupChange();
    if (plainGroupChange != null && DecryptedGroupUtil.changeIsEmptyExceptForProfileKeyChanges(plainGroupChange)) {
        if (sendToMembers) {
            ApplicationDependencies.getJobManager().add(PushGroupSilentUpdateSendJob.create(context, groupId, groupMutation.getNewGroupState(), outgoingMessage));
        }
        return new RecipientAndThread(groupRecipient, -1);
    } else {
        if (sendToMembers) {
            long threadId = MessageSender.send(context, outgoingMessage, -1, false, null, null);
            return new RecipientAndThread(groupRecipient, threadId);
        } else {
            long threadId = SignalDatabase.threads().getOrCreateValidThreadId(outgoingMessage.getRecipient(), -1, outgoingMessage.getDistributionType());
            try {
                long messageId = SignalDatabase.mms().insertMessageOutbox(outgoingMessage, threadId, false, null);
                SignalDatabase.mms().markAsSent(messageId, true);
                SignalDatabase.threads().update(threadId, true);
            } catch (MmsException e) {
                throw new AssertionError(e);
            }
            return new RecipientAndThread(groupRecipient, threadId);
        }
    }
}
Also used : MmsException(org.thoughtcrime.securesms.mms.MmsException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) OutgoingGroupUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingGroupUpdateMessage) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context) NonNull(androidx.annotation.NonNull)

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