Skip to content

Commit

Permalink
Don't request capabilities already enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mbax committed Mar 3, 2019
1 parent 4f4800e commit f056019
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public void cap(ClientReceiveCommandEvent event) {
private void fireAndCapReq(@NonNull CapabilityNegotiationResponseEventWithRequestBase responseEvent) {
Set<String> capabilities = this.getClient().getCapabilityManager().getSupportedCapabilities().stream().map(CapabilityState::getName).collect(Collectors.toCollection(HashSet::new));
capabilities.retainAll(CapabilityManager.Defaults.getDefaults());
capabilities.removeAll(this.getClient().getCapabilityManager().getCapabilities().stream().map(CapabilityState::getName).collect(Collectors.toList()));
List<String> currentCapabilities = this.getClient().getCapabilityManager().getCapabilities().stream().map(CapabilityState::getName).collect(Collectors.toList());
capabilities.removeAll(currentCapabilities);
if (!capabilities.isEmpty()) {
responseEvent.setEndingNegotiation(false);
capabilities.forEach(responseEvent::addRequest);
Expand All @@ -169,7 +170,7 @@ private void fireAndCapReq(@NonNull CapabilityNegotiationResponseEventWithReques
List<String> requests = responseEvent.getRequests();
if (!requests.isEmpty()) {
CapabilityRequestCommand capabilityRequestCommand = new CapabilityRequestCommand(this.getClient());
requests.stream().distinct().forEach(capabilityRequestCommand::enable);
requests.stream().distinct().filter(c -> !currentCapabilities.contains(c)).forEach(capabilityRequestCommand::enable);
capabilityRequestCommand.execute();
}
}
Expand Down

0 comments on commit f056019

Please sign in to comment.