sync ab alias

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2023-08-15 09:23:55 +08:00
parent b2f5e2f927
commit 57b8ec178c
4 changed files with 33 additions and 6 deletions

View File

@ -159,7 +159,6 @@ class _PeerCardState extends State<_PeerCard>
final greyStyle = TextStyle(
fontSize: 11,
color: Theme.of(context).textTheme.titleLarge?.color?.withOpacity(0.6));
final alias = bind.mainGetPeerOptionSync(id: peer.id, key: 'alias');
final child = Obx(
() => Container(
foregroundDecoration: deco.value,
@ -196,7 +195,9 @@ class _PeerCardState extends State<_PeerCard>
getOnline(8, peer.online),
Expanded(
child: Text(
alias.isEmpty ? formatID(peer.id) : alias,
peer.alias.isEmpty
? formatID(peer.id)
: peer.alias,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.titleSmall,
)),
@ -651,8 +652,13 @@ abstract class BasePeerCard extends StatelessWidget {
oldName: oldName,
onSubmit: (String newName) async {
if (newName != oldName) {
await bind.mainSetPeerAlias(id: id, alias: newName);
_update();
if (tab == PeerTabIndex.ab) {
gFFI.abModel.changeAlias(id: id, alias: newName);
gFFI.abModel.pushAb();
} else {
await bind.mainSetPeerAlias(id: id, alias: newName);
_update();
}
}
});
},
@ -1050,6 +1056,11 @@ class AddressBookPeerCard extends BasePeerCard {
dismissOnClicked: true,
);
}
@protected
@override
Future<String> _getAlias(String id) async =>
gFFI.abModel.find(id)?.alias ?? '';
}
class MyGroupPeerCard extends BasePeerCard {

View File

@ -197,6 +197,14 @@ class AbModel {
}).toList();
}
void changeAlias({required String id, required String alias}) {
final it = peers.where((element) => element.id == id);
if (it.isEmpty) {
return;
}
it.first.alias = alias;
}
Future<void> pushAb({bool toast = true}) async {
debugPrint("pushAb");
pushError.value = '';
@ -332,7 +340,7 @@ class AbModel {
username: r.username.isEmpty ? p.username : r.username,
hostname: r.hostname.isEmpty ? p.hostname : r.hostname,
platform: r.platform.isEmpty ? p.platform : r.platform,
alias: r.alias,
alias: p.alias.isEmpty ? r.alias : p.alias,
tags: p.tags,
forceAlwaysRelay: r.forceAlwaysRelay,
rdpPort: r.rdpPort,
@ -352,7 +360,8 @@ class AbModel {
return a.hash != b.hash ||
a.username != b.username ||
a.platform != b.platform ||
a.hostname != b.hostname;
a.hostname != b.hostname ||
a.alias != b.alias;
}
Future<List<Peer>> getRecentPeers() async {

View File

@ -56,6 +56,7 @@ class Peer {
"username": username,
"hostname": hostname,
"platform": platform,
"alias": alias,
"tags": tags,
};
}

View File

@ -1499,6 +1499,12 @@ pub struct AbPeer {
skip_serializing_if = "String::is_empty"
)]
pub platform: String,
#[serde(
default,
deserialize_with = "deserialize_string",
skip_serializing_if = "String::is_empty"
)]
pub alias: String,
#[serde(default, deserialize_with = "deserialize_vec_string")]
pub tags: Vec<String>,
}