enable group, show accessible users and peers

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-09-14 10:17:03 +08:00
parent 09d380ba8f
commit b2a4f11e0b
53 changed files with 568 additions and 273 deletions

View File

@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'platform_model.dart';
// ignore: depend_on_referenced_packages
import 'package:collection/collection.dart';
@ -7,7 +8,7 @@ import 'package:collection/collection.dart';
class Peer {
final String id;
String hash;
String username;
String username; // pc username
String hostname;
String platform;
String alias;
@ -16,6 +17,7 @@ class Peer {
String rdpPort;
String rdpUsername;
bool online = false;
String loginName; //login username
String getId() {
if (alias != '') {
@ -34,7 +36,8 @@ class Peer {
tags = json['tags'] ?? [],
forceAlwaysRelay = json['forceAlwaysRelay'] == 'true',
rdpPort = json['rdpPort'] ?? '',
rdpUsername = json['rdpUsername'] ?? '';
rdpUsername = json['rdpUsername'] ?? '',
loginName = json['loginName'] ?? '';
Map<String, dynamic> toJson() {
return <String, dynamic>{
@ -48,6 +51,7 @@ class Peer {
"forceAlwaysRelay": forceAlwaysRelay.toString(),
"rdpPort": rdpPort,
"rdpUsername": rdpUsername,
'loginName': loginName,
};
}
@ -63,6 +67,16 @@ class Peer {
};
}
Map<String, dynamic> toGroupCacheJson() {
return <String, dynamic>{
"id": id,
"username": username,
"hostname": hostname,
"platform": platform,
"login_name": loginName,
};
}
Peer({
required this.id,
required this.hash,
@ -74,6 +88,7 @@ class Peer {
required this.forceAlwaysRelay,
required this.rdpPort,
required this.rdpUsername,
required this.loginName,
});
Peer.loading()
@ -88,6 +103,7 @@ class Peer {
forceAlwaysRelay: false,
rdpPort: '',
rdpUsername: '',
loginName: '',
);
bool equal(Peer other) {
return id == other.id &&
@ -99,21 +115,24 @@ class Peer {
tags.equals(other.tags) &&
forceAlwaysRelay == other.forceAlwaysRelay &&
rdpPort == other.rdpPort &&
rdpUsername == other.rdpUsername;
rdpUsername == other.rdpUsername &&
loginName == other.loginName;
}
Peer.copy(Peer other)
: this(
id: other.id,
hash: other.hash,
username: other.username,
hostname: other.hostname,
platform: other.platform,
alias: other.alias,
tags: other.tags.toList(),
forceAlwaysRelay: other.forceAlwaysRelay,
rdpPort: other.rdpPort,
rdpUsername: other.rdpUsername);
id: other.id,
hash: other.hash,
username: other.username,
hostname: other.hostname,
platform: other.platform,
alias: other.alias,
tags: other.tags.toList(),
forceAlwaysRelay: other.forceAlwaysRelay,
rdpPort: other.rdpPort,
rdpUsername: other.rdpUsername,
loginName: other.loginName,
);
}
enum UpdateEvent { online, load }
@ -121,11 +140,14 @@ enum UpdateEvent { online, load }
class Peers extends ChangeNotifier {
final String name;
final String loadEvent;
List<Peer> peers;
List<Peer> peers = List.empty(growable: true);
final RxList<Peer>? initPeers;
UpdateEvent event = UpdateEvent.load;
static const _cbQueryOnlines = 'callback_query_onlines';
Peers({required this.name, required this.peers, required this.loadEvent}) {
Peers(
{required this.name, required this.initPeers, required this.loadEvent}) {
peers = initPeers ?? [];
platformFFI.registerEventHandler(_cbQueryOnlines, name, (evt) async {
_updateOnlineState(evt);
});
@ -176,7 +198,11 @@ class Peers extends ChangeNotifier {
void _updatePeers(Map<String, dynamic> evt) {
final onlineStates = _getOnlineStates();
peers = _decodePeers(evt['peers']);
if (initPeers != null) {
peers = initPeers!;
} else {
peers = _decodePeers(evt['peers']);
}
for (var peer in peers) {
final state = onlineStates[peer.id];
peer.online = state != null && state != false;