show peer note (#13140)

Signed-off-by: 21pages <sunboeasy@gmail.com>
Co-authored-by: RustDesk <71636191+rustdesk@users.noreply.github.com>
This commit is contained in:
21pages
2025-10-12 14:59:42 +08:00
committed by GitHub
parent 9826c4e943
commit 30552fd202
56 changed files with 394 additions and 90 deletions

View File

@@ -319,8 +319,8 @@ class AbModel {
// #endregion
// #region peer
Future<String?> addIdToCurrent(
String id, String alias, String password, List<dynamic> tags) async {
Future<String?> addIdToCurrent(String id, String alias, String password,
List<dynamic> tags, String note) async {
if (currentAbPeers.where((element) => element.id == id).isNotEmpty) {
return "$id already exists in address book $_currentName";
}
@@ -333,6 +333,9 @@ class AbModel {
if (password.isNotEmpty) {
peer['password'] = password;
}
if (note.isNotEmpty) {
peer['note'] = note;
}
final ret = await addPeersTo([peer], _currentName.value);
_syncAllFromRecent = true;
return ret;
@@ -376,6 +379,14 @@ class AbModel {
return res;
}
Future<bool> changeNote({required String id, required String note}) async {
bool res = await current.changeNote(id: id, note: note);
await pullNonLegacyAfterChange();
currentAbPeers.refresh();
// no need to save cache
return res;
}
Future<bool> changePersonalHashPassword(String id, String hash) async {
var ret = false;
final personalAb = addressbooks[_personalAddressBookName];
@@ -658,6 +669,15 @@ class AbModel {
}
}
String getPeerNote(String id) {
final it = currentAbPeers.where((p0) => p0.id == id);
if (it.isEmpty) {
return '';
} else {
return it.first.note;
}
}
Color getCurrentAbTagColor(String tag) {
if (tag == kUntagged) {
return MyTheme.accent;
@@ -863,6 +883,8 @@ abstract class BaseAb {
Future<bool> changeAlias({required String id, required String alias});
Future<bool> changeNote({required String id, required String note});
Future<bool> changePersonalHashPassword(String id, String hash);
Future<bool> changeSharedPassword(String id, String password);
@@ -1090,6 +1112,12 @@ class LegacyAb extends BaseAb {
return await pushAb();
}
@override
Future<bool> changeNote({required String id, required String note}) async {
// no need to implement
return false;
}
@override
Future<bool> changeSharedPassword(String id, String password) async {
// no need to implement
@@ -1549,6 +1577,27 @@ class Ab extends BaseAb {
}
}
@override
Future<bool> changeNote({required String id, required String note}) async {
try {
final api =
"${await bind.mainGetApiServer()}/api/ab/peer/update/${profile.guid}";
var headers = getHttpHeaders();
headers['Content-Type'] = "application/json";
final body = jsonEncode({"id": id, "note": note});
final resp = await http.put(Uri.parse(api), headers: headers, body: body);
final errMsg = _jsonDecodeActionResp(resp);
if (errMsg.isNotEmpty) {
BotToast.showText(contentColor: Colors.red, text: errMsg);
return false;
}
return true;
} catch (err) {
debugPrint('changeNote err: ${err.toString()}');
return false;
}
}
Future<bool> _setPassword(Object bodyContent) async {
try {
final api =
@@ -1815,6 +1864,11 @@ class DummyAb extends BaseAb {
return false;
}
@override
Future<bool> changeNote({required String id, required String note}) async {
return false;
}
@override
Future<bool> changePersonalHashPassword(String id, String hash) async {
return false;

View File

@@ -20,6 +20,7 @@ class Peer {
bool online = false;
String loginName; //login username
String device_group_name;
String note;
bool? sameServer;
String getId() {
@@ -43,6 +44,7 @@ class Peer {
rdpUsername = json['rdpUsername'] ?? '',
loginName = json['loginName'] ?? '',
device_group_name = json['device_group_name'] ?? '',
note = json['note'] is String ? json['note'] : '',
sameServer = json['same_server'];
Map<String, dynamic> toJson() {
@@ -60,6 +62,7 @@ class Peer {
"rdpUsername": rdpUsername,
'loginName': loginName,
'device_group_name': device_group_name,
'note': note,
'same_server': sameServer,
};
}
@@ -104,6 +107,7 @@ class Peer {
required this.rdpUsername,
required this.loginName,
required this.device_group_name,
required this.note,
this.sameServer,
});
@@ -122,6 +126,7 @@ class Peer {
rdpUsername: '',
loginName: '',
device_group_name: '',
note: '',
);
bool equal(Peer other) {
return id == other.id &&
@@ -136,7 +141,8 @@ class Peer {
rdpPort == other.rdpPort &&
rdpUsername == other.rdpUsername &&
device_group_name == other.device_group_name &&
loginName == other.loginName;
loginName == other.loginName &&
note == other.note;
}
Peer.copy(Peer other)
@@ -154,6 +160,7 @@ class Peer {
rdpUsername: other.rdpUsername,
loginName: other.loginName,
device_group_name: other.device_group_name,
note: other.note,
sameServer: other.sameServer);
}