Search in sources :

Example 16 with DecryptedGroupV2Context

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

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

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

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)

Example 18 with DecryptedGroupV2Context

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

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)

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