ab: unremember password in ab also unremember password in recent, and set alias also sync to recent

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2023-08-17 18:21:37 +08:00
parent 6045b5fead
commit d7f0acd96d
3 changed files with 35 additions and 24 deletions

View File

@ -659,6 +659,7 @@ abstract class BasePeerCard extends StatelessWidget {
if (newName != oldName) {
if (tab == PeerTabIndex.ab) {
gFFI.abModel.changeAlias(id: id, alias: newName);
await bind.mainSetPeerAlias(id: id, alias: newName);
gFFI.abModel.pushAb();
} else {
await bind.mainSetPeerAlias(id: id, alias: newName);
@ -713,16 +714,8 @@ abstract class BasePeerCard extends StatelessWidget {
case PeerTabIndex.ab:
gFFI.abModel.deletePeer(id);
final future = gFFI.abModel.pushAb();
if (shouldSyncAb() && await bind.mainPeerExists(id: peer.id)) {
Future.delayed(Duration.zero, () async {
final succ = await future;
if (succ) {
await Future.delayed(Duration(seconds: 2)); // success msg
BotToast.showText(
contentColor: Colors.lightBlue,
text: translate('synced_peer_readded_tip'));
}
});
if (await bind.mainPeerExists(id: peer.id)) {
gFFI.abModel.reSyncToast(future);
}
break;
case PeerTabIndex.group:
@ -748,9 +741,15 @@ abstract class BasePeerCard extends StatelessWidget {
translate('Unremember Password'),
style: style,
),
proc: () {
bind.mainForgetPassword(id: id);
showToast(translate('Successful'));
proc: () async {
if (tab == PeerTabIndex.ab) {
gFFI.abModel.unrememberPassword(id);
await bind.mainForgetPassword(id: id);
gFFI.abModel.pushAb();
} else {
bind.mainForgetPassword(id: id);
showToast(translate('Successful'));
}
},
padding: menuPadding,
dismissOnClicked: true,
@ -1046,7 +1045,7 @@ class AddressBookPeerCard extends BasePeerCard {
}
menuItems.add(MenuEntryDivider());
menuItems.add(_renameAction(peer.id));
if (await bind.mainPeerHasPassword(id: peer.id)) {
if (peer.hash.isNotEmpty) {
menuItems.add(_unrememberPasswordAction(peer.id));
}
if (gFFI.abModel.tags.isNotEmpty) {

View File

@ -345,16 +345,7 @@ class _PeerTabPageState extends State<PeerTabPage>
gFFI.abModel.deletePeers(peers.map((p) => p.id).toList());
final future = gFFI.abModel.pushAb();
if (hasSynced) {
Future.delayed(Duration.zero, () async {
final succ = await future;
if (succ) {
await Future.delayed(
Duration(seconds: 2)); // success msg
BotToast.showText(
contentColor: Colors.lightBlue,
text: translate('synced_peer_readded_tip'));
}
});
gFFI.abModel.reSyncToast(future);
}
}
break;

View File

@ -212,6 +212,14 @@ class AbModel {
it.first.alias = alias;
}
void unrememberPassword(String id) {
final it = peers.where((element) => element.id == id);
if (it.isEmpty) {
return;
}
it.first.hash = '';
}
Future<bool> pushAb(
{bool toastIfFail = true,
bool toastIfSucc = true,
@ -507,4 +515,17 @@ class AbModel {
throw err;
}
}
reSyncToast(Future<bool> future) {
if (!shouldSyncAb()) return;
Future.delayed(Duration.zero, () async {
final succ = await future;
if (succ) {
await Future.delayed(Duration(seconds: 2)); // success msg
BotToast.showText(
contentColor: Colors.lightBlue,
text: translate('synced_peer_readded_tip'));
}
});
}
}