Merge pull request #5415 from 21pages/ab

fix ab sync judge
This commit is contained in:
RustDesk 2023-08-17 11:20:47 +08:00 committed by GitHub
commit be55926cfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 12 deletions

View File

@ -380,12 +380,12 @@ class AbModel {
}
Future<void> _syncFromRecentWithoutLock({bool push = true}) async {
bool shouldSync(Peer r, Peer p) {
return r.hash != p.hash ||
r.username != p.username ||
r.platform != p.platform ||
r.hostname != p.hostname ||
(p.alias.isEmpty && r.alias.isNotEmpty);
bool peerSyncEqual(Peer a, Peer b) {
return a.hash == b.hash &&
a.username == b.username &&
a.platform == b.platform &&
a.hostname == b.hostname &&
a.alias == b.alias;
}
Future<List<Peer>> getRecentPeers() async {
@ -425,29 +425,30 @@ class AbModel {
if (!shouldSyncAb()) return;
final recents = await getRecentPeers();
if (recents.isEmpty) return;
bool syncChanged = false;
bool uiChanged = false;
bool needSync = false;
for (var i = 0; i < recents.length; i++) {
var r = recents[i];
var index = peers.indexWhere((e) => e.id == r.id);
if (index < 0) {
if (!isFull(false)) {
peers.add(r);
syncChanged = true;
uiChanged = true;
needSync = true;
}
} else {
if (!r.equal(peers[index])) {
uiChanged = true;
}
if (shouldSync(r, peers[index])) {
syncChanged = true;
}
Peer old = Peer.copy(peers[index]);
peers[index] = merge(r, peers[index]);
if (!peerSyncEqual(peers[index], old)) {
needSync = true;
}
}
}
// Be careful with loop calls
if (syncChanged && push) {
if (needSync && push) {
pushAb(toastIfSucc: false, toastIfFail: false);
} else if (uiChanged) {
peers.refresh();

View File

@ -101,6 +101,19 @@ class Peer {
rdpPort == other.rdpPort &&
rdpUsername == other.rdpUsername;
}
Peer.copy(Peer other)
: this(
id: other.id,
hash: other.hash,
username: other.username,
hostname: other.hostname,
platform: other.platform,
alias: other.alias,
tags: other.tags.toList(),
forceAlwaysRelay: other.forceAlwaysRelay,
rdpPort: other.rdpPort,
rdpUsername: other.rdpUsername);
}
enum UpdateEvent { online, load }