ab: full check for adding peers from recent/batch operation

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2023-08-16 13:30:38 +08:00
parent 1e75b172d6
commit 6f8483aecd
2 changed files with 22 additions and 6 deletions

View File

@ -405,10 +405,18 @@ class _PeerTabPageState extends State<PeerTabPage>
!gFFI.userModel.isLogin || model.currentTab == PeerTabIndex.ab.index,
child: InkWell(
onTap: () {
if (gFFI.abModel.isFull(true)) {
return;
}
final peers = model.selectedPeers;
gFFI.abModel.addPeers(peers);
gFFI.abModel.pushAb();
final future = gFFI.abModel.pushAb();
model.setMultiSelectionMode(false);
Future.delayed(Duration.zero, () async {
await future;
await Future.delayed(Duration(seconds: 2)); // toast
gFFI.abModel.isFull(true);
});
},
child: Tooltip(
message: translate('Add to Address Book'),

View File

@ -163,10 +163,16 @@ class AbModel {
}
}
void addPeers(List<Peer> ps) {
bool addPeers(List<Peer> ps) {
bool allAdded = true;
for (var p in ps) {
addPeer(p);
if (!isFull(false)) {
addPeer(p);
} else {
allAdded = false;
}
}
return allAdded;
}
void addTag(String tag) async {
@ -419,9 +425,11 @@ class AbModel {
var r = recents[i];
var index = peers.indexWhere((e) => e.id == r.id);
if (index < 0) {
peers.add(r);
syncChanged = true;
uiChanged = true;
if (!isFull(false)) {
peers.add(r);
syncChanged = true;
uiChanged = true;
}
} else {
if (!r.equal(peers[index])) {
uiChanged = true;