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