use of org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context in project Signal-Android by WhisperSystems.
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 WhisperSystems.
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);
}
}
use of org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context in project Signal-Android by WhisperSystems.
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 WhisperSystems.
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);
}
use of org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context in project Signal-Android by WhisperSystems.
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);
}
Aggregations