mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-25 19:47:31 +00:00
Fix issue when single user leaves ParticipantCollection.
This commit is contained in:
@@ -62,7 +62,7 @@ public class ParticipantCollection {
|
||||
.indexOf(oldId);
|
||||
|
||||
if (newIndex != -1 && newIndex != i) {
|
||||
Collections.swap(newParticipants, newIndex, i);
|
||||
Collections.swap(newParticipants, newIndex, Math.min(i, newParticipants.size() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -87,6 +87,37 @@ public class ParticipantCollectionTest {
|
||||
assertThat(result.getGridParticipants(), Matchers.contains(id(1), id(2), id(3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACollection_whenSomeoneLeaves_thenIDoNotExpectToSeeThemInTheNewList() {
|
||||
// GIVEN
|
||||
List<CallParticipant> initial = Arrays.asList(participant(1, 1, 2), participant(2, 1, 3), participant(3, 1, 4));
|
||||
ParticipantCollection initialCollection = testSubject.getNext(initial);
|
||||
List<CallParticipant> next = Arrays.asList(participant(2, 2, 3), participant(3, 1, 4));
|
||||
|
||||
// WHEN
|
||||
ParticipantCollection result = initialCollection.getNext(next);
|
||||
|
||||
// THEN
|
||||
assertThat(result.getGridParticipants(), Matchers.contains(id(2), id(3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACollection_whenMultipleLeave_thenIDoNotExpectToSeeThemInTheNewList() {
|
||||
// GIVEN
|
||||
ParticipantCollection testSubject = new ParticipantCollection(4);
|
||||
List<CallParticipant> initial = Arrays.asList(participant(1, 1, 2), participant(2, 1, 3), participant(3, 1, 4), participant(4, 1, 5));
|
||||
ParticipantCollection initialCollection = testSubject.getNext(initial);
|
||||
List<CallParticipant> next = Arrays.asList(participant(3, 1, 4), participant(2, 1, 3));
|
||||
|
||||
// WHEN
|
||||
ParticipantCollection result = initialCollection.getNext(next);
|
||||
|
||||
// THEN
|
||||
assertThat(result.getGridParticipants(), Matchers.contains(id(2), id(3)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void bigTest() {
|
||||
|
||||
|
Reference in New Issue
Block a user