Fix missing update for arbitrator, fix incorrect removal of arbitrators

This commit is contained in:
Manfred Karrer 2016-07-03 04:02:20 +02:00
parent 03a58d9702
commit 74b54d14ab
2 changed files with 20 additions and 9 deletions

View File

@ -95,6 +95,7 @@ public class ArbitratorManager {
private final ArbitratorService arbitratorService;
private final User user;
private final ObservableMap<NodeAddress, Arbitrator> arbitratorsObservableMap = FXCollections.observableHashMap();
private final List<Arbitrator> persistedAcceptedArbitrators;
private Timer republishArbitratorTimer, retryRepublishArbitratorTimer;
@ -108,6 +109,9 @@ public class ArbitratorManager {
this.arbitratorService = arbitratorService;
this.user = user;
persistedAcceptedArbitrators = new ArrayList<>(user.getAcceptedArbitrators());
user.clearAcceptedArbitrators();
arbitratorService.addHashSetChangedListener(new HashMapChangedListener() {
@Override
public void onAdded(ProtectedStorageEntry data) {
@ -167,17 +171,20 @@ public class ArbitratorManager {
arbitratorsObservableMap.putAll(filtered);
// we need to remove accepted arbitrators which are not available anymore
if (user.getAcceptedArbitrators() != null) {
List<Arbitrator> removeList = user.getAcceptedArbitrators().stream()
.filter(e -> !arbitratorsObservableMap.containsValue(e))
.collect(Collectors.toList());
removeList.stream().forEach(user::removeAcceptedArbitrator);
arbitratorsObservableMap.values().stream()
.filter(arbitrator -> persistedAcceptedArbitrators.contains(arbitrator))
.forEach(user::addAcceptedArbitrator);
// if we don't have any arbitrator anymore we set all matching
if (user.getAcceptedArbitrators().isEmpty()) {
arbitratorsObservableMap.values().stream()
.filter(user::hasMatchingLanguage)
.forEach(user::addAcceptedArbitrator);
}
// we use a delay as we might get our matching arbitrator a bit delayed
UserThread.runAfter(() -> {
if (user.getAcceptedArbitrators().isEmpty()) {
arbitratorsObservableMap.values().stream()
.filter(user::hasMatchingLanguage)
.forEach(user::addAcceptedArbitrator);
}
}, 1);
}
}

View File

@ -42,6 +42,7 @@ import java.util.Date;
class ArbitratorRegistrationViewModel extends ActivatableViewModel {
private final ArbitratorManager arbitratorManager;
private User user;
private final P2PService p2PService;
private final WalletService walletService;
private final KeyRing keyRing;
@ -69,6 +70,7 @@ class ArbitratorRegistrationViewModel extends ActivatableViewModel {
WalletService walletService,
KeyRing keyRing) {
this.arbitratorManager = arbitratorManager;
this.user = user;
this.p2PService = p2PService;
this.walletService = walletService;
this.keyRing = keyRing;
@ -92,6 +94,8 @@ class ArbitratorRegistrationViewModel extends ActivatableViewModel {
@Override
protected void activate() {
arbitratorManager.getArbitratorsObservableMap().addListener(arbitratorMapChangeListener);
Arbitrator myRegisteredArbitrator = user.getRegisteredArbitrator();
myArbitratorProperty.set(myRegisteredArbitrator);
updateDisableStates();
}