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);
}
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);
}
}
}
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();
}
Aggregations