From 6f8483aecd09fa5d41cc4a48438fab5047dedfef Mon Sep 17 00:00:00 2001 From: 21pages Date: Wed, 16 Aug 2023 13:30:38 +0800 Subject: [PATCH] ab: full check for adding peers from recent/batch operation Signed-off-by: 21pages --- flutter/lib/common/widgets/peer_tab_page.dart | 10 +++++++++- flutter/lib/models/ab_model.dart | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/flutter/lib/common/widgets/peer_tab_page.dart b/flutter/lib/common/widgets/peer_tab_page.dart index 0937f6f5f..047d95f11 100644 --- a/flutter/lib/common/widgets/peer_tab_page.dart +++ b/flutter/lib/common/widgets/peer_tab_page.dart @@ -405,10 +405,18 @@ class _PeerTabPageState extends State !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'), diff --git a/flutter/lib/models/ab_model.dart b/flutter/lib/models/ab_model.dart index 9426b0571..1c07582d4 100644 --- a/flutter/lib/models/ab_model.dart +++ b/flutter/lib/models/ab_model.dart @@ -163,10 +163,16 @@ class AbModel { } } - void addPeers(List ps) { + bool addPeers(List 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;