Ensure a GV2 update message mentioning you as a new member is first in the list.

master
Alan Evans 2020-08-13 15:34:05 -03:00 committed by Greyson Parrelli
parent ace1b8ee71
commit 3c90dfa660
2 changed files with 69 additions and 6 deletions

View File

@ -148,13 +148,13 @@ final class GroupsV2UpdateMessageProducer {
if (editorIsYou) {
if (newMemberIsYou) {
updates.add(updateDescription(context.getString(R.string.MessageRecord_you_joined_the_group)));
updates.add(0, updateDescription(context.getString(R.string.MessageRecord_you_joined_the_group)));
} else {
updates.add(updateDescription(member.getUuid(), added -> context.getString(R.string.MessageRecord_you_added_s, added)));
}
} else {
if (newMemberIsYou) {
updates.add(updateDescription(change.getEditor(), editor -> context.getString(R.string.MessageRecord_s_added_you, editor)));
updates.add(0, updateDescription(change.getEditor(), editor -> context.getString(R.string.MessageRecord_s_added_you, editor)));
} else {
if (member.getUuid().equals(change.getEditor())) {
updates.add(updateDescription(member.getUuid(), newMember -> context.getString(R.string.MessageRecord_s_joined_the_group, newMember)));
@ -171,7 +171,7 @@ final class GroupsV2UpdateMessageProducer {
boolean newMemberIsYou = member.getUuid().equals(selfUuidBytes);
if (newMemberIsYou) {
updates.add(updateDescription(context.getString(R.string.MessageRecord_you_joined_the_group)));
updates.add(0, updateDescription(context.getString(R.string.MessageRecord_you_joined_the_group)));
} else {
updates.add(updateDescription(member.getUuid(), newMember -> context.getString(R.string.MessageRecord_s_joined_the_group, newMember)));
}
@ -274,7 +274,7 @@ final class GroupsV2UpdateMessageProducer {
boolean newMemberIsYou = invitee.getUuid().equals(selfUuidBytes);
if (newMemberIsYou) {
updates.add(updateDescription(change.getEditor(), editor -> context.getString(R.string.MessageRecord_s_invited_you_to_the_group, editor)));
updates.add(0, updateDescription(change.getEditor(), editor -> context.getString(R.string.MessageRecord_s_invited_you_to_the_group, editor)));
} else {
if (editorIsYou) {
updates.add(updateDescription(invitee.getUuid(), newInvitee -> context.getString(R.string.MessageRecord_you_invited_s_to_the_group, newInvitee)));
@ -300,9 +300,9 @@ final class GroupsV2UpdateMessageProducer {
UUID uuid = UuidUtil.fromByteStringOrUnknown(invitee.getAddedByUuid());
if (UuidUtil.UNKNOWN_UUID.equals(uuid)) {
updates.add(updateDescription(context.getString(R.string.MessageRecord_you_were_invited_to_the_group)));
updates.add(0, updateDescription(context.getString(R.string.MessageRecord_you_were_invited_to_the_group)));
} else {
updates.add(updateDescription(invitee.getAddedByUuid(), editor -> context.getString(R.string.MessageRecord_s_invited_you_to_the_group, editor)));
updates.add(0, updateDescription(invitee.getAddedByUuid(), editor -> context.getString(R.string.MessageRecord_s_invited_you_to_the_group, editor)));
}
} else {
notYouInviteCount++;

View File

@ -182,6 +182,35 @@ public final class GroupsV2UpdateMessageProducerTest {
assertThat(describeChange(change), is(singletonList("Bob joined the group.")));
}
@Test
public void member_added_you_and_another_where_you_are_not_first() {
DecryptedGroupChange change = changeBy(bob)
.addMember(alice)
.addMember(you)
.build();
assertThat(describeChange(change), is(Arrays.asList("Bob added you to the group.", "Bob added Alice.")));
}
@Test
public void unknown_member_added_you_and_another_where_you_are_not_first() {
DecryptedGroupChange change = changeByUnknown()
.addMember(alice)
.addMember(you)
.build();
assertThat(describeChange(change), is(Arrays.asList("You joined the group.", "Alice joined the group.")));
}
@Test
public void you_added_you_and_another_where_you_are_not_first() {
DecryptedGroupChange change = changeBy(you)
.addMember(alice)
.addMember(you)
.build();
assertThat(describeChange(change), is(Arrays.asList("You joined the group.", "You added Alice.")));
}
// Member removals
@Test
@ -451,6 +480,38 @@ public final class GroupsV2UpdateMessageProducerTest {
assertThat(describeChange(change), is(Arrays.asList("Bob invited you to the group.", "3 people were invited to the group.")));
}
@Test
public void member_invited_3_persons_and_you_and_added_another_where_you_were_not_first() {
DecryptedGroupChange change = changeBy(bob)
.addMember(alice)
.invite(you)
.invite(UUID.randomUUID())
.invite(UUID.randomUUID())
.build();
assertThat(describeChange(change), is(Arrays.asList("Bob invited you to the group.", "Bob added Alice.", "Bob invited 2 people to the group.")));
}
@Test
public void unknown_editor_but_known_invitee_invited_you_and_added_another_where_you_were_not_first() {
DecryptedGroupChange change = changeByUnknown()
.addMember(bob)
.inviteBy(you, alice)
.build();
assertThat(describeChange(change), is(Arrays.asList("Alice invited you to the group.", "Bob joined the group.")));
}
@Test
public void unknown_editor_and_unknown_inviter_invited_you_and_added_another_where_you_were_not_first() {
DecryptedGroupChange change = changeByUnknown()
.addMember(alice)
.invite(you)
.build();
assertThat(describeChange(change), is(Arrays.asList("You were invited to the group.", "Alice joined the group.")));
}
// Member invitation revocation
@Test
@ -785,10 +846,12 @@ public final class GroupsV2UpdateMessageProducerTest {
.addMember(bob)
.membershipAccess(AccessControl.AccessRequired.MEMBER)
.title("Title")
.addMember(you)
.timer(300)
.build();
assertThat(describeChange(change), is(Arrays.asList(
"Alice added you to the group.",
"Alice added Bob.",
"Alice changed the group name to \"" + isolateBidi("Title") + "\".",
"Alice set the disappearing message timer to 5 minutes.",