mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-20 17:57:29 +00:00
Sort call participants by raised hand.
This commit is contained in:
committed by
Clark Chen
parent
e5652197eb
commit
f93a9a0f22
@@ -206,9 +206,7 @@ public class GroupConnectedActionProcessor extends GroupActionProcessor {
|
||||
protected @NonNull WebRtcServiceState handleSelfRaiseHand(@NonNull WebRtcServiceState currentState, boolean raised) {
|
||||
Log.i(tag, "handleSelfRaiseHand():");
|
||||
try {
|
||||
final CallInfoState callInfoState = currentState.getCallInfoState();
|
||||
|
||||
callInfoState.requireGroupCall().raiseHand(raised);
|
||||
currentState.getCallInfoState().requireGroupCall().raiseHand(raised);
|
||||
|
||||
return currentState;
|
||||
} catch (CallException e) {
|
||||
@@ -268,11 +266,11 @@ public class GroupConnectedActionProcessor extends GroupActionProcessor {
|
||||
List<CallParticipant> participants = currentState.getCallInfoState().getRemoteCallParticipants();
|
||||
|
||||
for (CallParticipant updatedParticipant : participants) {
|
||||
boolean isHandCurrentlyRaised = raisedHands.contains(updatedParticipant.getCallParticipantId().getDemuxId());
|
||||
int raisedHandIndex = raisedHands.indexOf(updatedParticipant.getCallParticipantId().getDemuxId());
|
||||
boolean wasHandAlreadyRaised = updatedParticipant.isHandRaised();
|
||||
if (isHandCurrentlyRaised && !wasHandAlreadyRaised) {
|
||||
builder.putParticipant(updatedParticipant.getCallParticipantId(), updatedParticipant.withHandRaisedTimestamp(now));
|
||||
} else if (!isHandCurrentlyRaised && wasHandAlreadyRaised) {
|
||||
if (raisedHandIndex >= 0 && !wasHandAlreadyRaised) {
|
||||
builder.putParticipant(updatedParticipant.getCallParticipantId(), updatedParticipant.withHandRaisedTimestamp(now + raisedHandIndex));
|
||||
} else if (raisedHandIndex < 0 && wasHandAlreadyRaised) {
|
||||
builder.putParticipant(updatedParticipant.getCallParticipantId(), updatedParticipant.withHandRaisedTimestamp(CallParticipant.HAND_LOWERED));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,22 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class ParticipantCollection {
|
||||
|
||||
private static final Comparator<CallParticipant> LEAST_RECENTLY_ADDED = (a, b) -> Long.compare(a.getAddedToCallTime(), b.getAddedToCallTime());
|
||||
private static final Comparator<CallParticipant> MOST_RECENTLY_SPOKEN = (a, b) -> Long.compare(b.getLastSpoke(), a.getLastSpoke());
|
||||
private static final Comparator<CallParticipant> MOST_RECENTLY_SPOKEN_THEN_LEAST_RECENTLY_ADDED = ComparatorCompat.chain(MOST_RECENTLY_SPOKEN).thenComparing(LEAST_RECENTLY_ADDED);
|
||||
private static final Comparator<CallParticipant> LEAST_RECENTLY_ADDED = (a, b) -> Long.compare(a.getAddedToCallTime(), b.getAddedToCallTime());
|
||||
private static final Comparator<CallParticipant> MOST_RECENTLY_SPOKEN = (a, b) -> Long.compare(b.getLastSpoke(), a.getLastSpoke());
|
||||
private static final Comparator<CallParticipant> HAND_RAISED = (a, b) -> {
|
||||
if (a.isHandRaised() && b.isHandRaised()) {
|
||||
return Long.compare(a.getHandRaisedTimestamp(), b.getHandRaisedTimestamp());
|
||||
} else if (a.isHandRaised()) {
|
||||
return -1;
|
||||
} else if (b.isHandRaised()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
private static final Comparator<CallParticipant> COMPLEX_COMPARATOR_CHAIN = ComparatorCompat.chain(HAND_RAISED)
|
||||
.thenComparing(MOST_RECENTLY_SPOKEN)
|
||||
.thenComparing(LEAST_RECENTLY_ADDED);
|
||||
|
||||
private final int maxGridCellCount;
|
||||
private final List<CallParticipant> participants;
|
||||
@@ -43,12 +56,12 @@ public class ParticipantCollection {
|
||||
return new ParticipantCollection(maxGridCellCount);
|
||||
} else if (this.participants.isEmpty()) {
|
||||
List<CallParticipant> newParticipants = new ArrayList<>(participants);
|
||||
Collections.sort(newParticipants, participants.size() <= maxGridCellCount ? LEAST_RECENTLY_ADDED : MOST_RECENTLY_SPOKEN_THEN_LEAST_RECENTLY_ADDED);
|
||||
Collections.sort(newParticipants, participants.size() <= maxGridCellCount ? LEAST_RECENTLY_ADDED : COMPLEX_COMPARATOR_CHAIN);
|
||||
|
||||
return new ParticipantCollection(maxGridCellCount, newParticipants);
|
||||
} else {
|
||||
List<CallParticipant> newParticipants = new ArrayList<>(participants);
|
||||
Collections.sort(newParticipants, MOST_RECENTLY_SPOKEN_THEN_LEAST_RECENTLY_ADDED);
|
||||
Collections.sort(newParticipants, COMPLEX_COMPARATOR_CHAIN);
|
||||
|
||||
List<CallParticipantId> oldGridParticipantIds = Stream.of(getGridParticipants())
|
||||
.map(CallParticipant::getCallParticipantId)
|
||||
|
||||
Reference in New Issue
Block a user