From 2533493c66f17477d0bc69ccef3c260b3db1dc34 Mon Sep 17 00:00:00 2001 From: 21pages Date: Fri, 13 Jun 2025 14:34:27 +0800 Subject: [PATCH] Remove non-existent tags when importing ab peers from another ab (#12062) Signed-off-by: 21pages --- flutter/lib/models/ab_model.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/flutter/lib/models/ab_model.dart b/flutter/lib/models/ab_model.dart index 390150505..790bc62fe 100644 --- a/flutter/lib/models/ab_model.dart +++ b/flutter/lib/models/ab_model.dart @@ -347,6 +347,9 @@ class AbModel { if (ab == null) { return 'no such addressbook: $name'; } + for (var p in ps) { + ab.removeNonExistentTags(p); + } String? errMsg = await ab.addPeers(ps); await pullNonLegacyAfterChange(name: name); if (name == _currentName.value) { @@ -822,6 +825,18 @@ abstract class BaseAb { p.remove('password'); } + removeNonExistentTags(Map p) { + try { + final oldTags = p.remove('tags'); + if (oldTags is List) { + final newTags = oldTags.where((e) => tagContainBy(e)).toList(); + p['tags'] = newTags; + } + } catch (e) { + print("removeNonExistentTags: $e"); + } + } + Future changeTagForPeers(List ids, List tags); Future changeAlias({required String id, required String alias});