diff --git a/flutter/lib/models/ab_model.dart b/flutter/lib/models/ab_model.dart index c36c14966..ba6c136ff 100644 --- a/flutter/lib/models/ab_model.dart +++ b/flutter/lib/models/ab_model.dart @@ -163,7 +163,7 @@ class AbModel { void addPeer(Peer peer) { final index = peers.indexWhere((e) => e.id == peer.id); if (index >= 0) { - peers[index] = merge(peer, peers[index]); + merge(peer, peers[index]); } else { peers.add(peer); } @@ -365,18 +365,14 @@ class AbModel { } } - Peer merge(Peer r, Peer p) { - return Peer( - id: p.id, - hash: r.hash.isEmpty ? p.hash : r.hash, - username: r.username.isEmpty ? p.username : r.username, - hostname: r.hostname.isEmpty ? p.hostname : r.hostname, - platform: r.platform.isEmpty ? p.platform : r.platform, - alias: p.alias.isEmpty ? r.alias : p.alias, - tags: p.tags, - forceAlwaysRelay: r.forceAlwaysRelay, - rdpPort: r.rdpPort, - rdpUsername: r.rdpUsername); + void merge(Peer r, Peer p) { + p.hash = r.hash.isEmpty ? p.hash : r.hash; + p.username = r.username.isEmpty ? p.username : r.username; + p.hostname = r.hostname.isEmpty ? p.hostname : r.hostname; + p.alias = p.alias.isEmpty ? r.alias : p.alias; + p.forceAlwaysRelay = r.forceAlwaysRelay; + p.rdpPort = r.rdpPort; + p.rdpUsername = r.rdpUsername; } Future syncFromRecent({bool push = true}) async { @@ -445,14 +441,14 @@ class AbModel { needSync = true; } } else { - if (!r.equal(peers[index])) { - uiChanged = true; - } Peer old = Peer.copy(peers[index]); - peers[index] = merge(r, peers[index]); + merge(r, peers[index]); if (!peerSyncEqual(peers[index], old)) { needSync = true; } + if (!old.equal(peers[index])) { + uiChanged = true; + } } } // Be careful with loop calls diff --git a/flutter/lib/models/peer_model.dart b/flutter/lib/models/peer_model.dart index 34afbfeaf..4d7ac3b28 100644 --- a/flutter/lib/models/peer_model.dart +++ b/flutter/lib/models/peer_model.dart @@ -7,9 +7,9 @@ import 'package:collection/collection.dart'; class Peer { final String id; String hash; - final String username; - final String hostname; - final String platform; + String username; + String hostname; + String platform; String alias; List tags; bool forceAlwaysRelay = false;