opt pull ab (#7508)
1. Test legacy/new mode only upon logging out. 2. Avoid pulling all data unnecessarily: * On startup: Retrieve list, current, and personal data. * On refresh: Retrieve list and current data. * On changing AB/switching tabs: Attempt to pull current data if not initialized. 3. Cache only personal and current AB. 4. Synchronize current AB from recent. 5. Remove AB loading CircularProgressIndicator. Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
00152e0db4
commit
49f717fcf8
@ -46,12 +46,6 @@ class _AddressBookState extends State<AddressBook> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: loginDialog, child: Text(translate("Login"))));
|
onPressed: loginDialog, child: Text(translate("Login"))));
|
||||||
} else {
|
} else {
|
||||||
if (gFFI.abModel.currentAbLoading.value &&
|
|
||||||
gFFI.abModel.currentAbEmtpy) {
|
|
||||||
return const Center(
|
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
buildErrorBanner(context,
|
buildErrorBanner(context,
|
||||||
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_hbb/common/widgets/dialog.dart';
|
import 'package:flutter_hbb/common/widgets/dialog.dart';
|
||||||
import 'package:flutter_hbb/consts.dart';
|
import 'package:flutter_hbb/consts.dart';
|
||||||
|
import 'package:flutter_hbb/models/ab_model.dart';
|
||||||
import 'package:flutter_hbb/models/peer_tab_model.dart';
|
import 'package:flutter_hbb/models/peer_tab_model.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@ -1059,9 +1060,11 @@ class AddressBookPeerCard extends BasePeerCard {
|
|||||||
return menuItems;
|
return menuItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// address book does not need to update
|
||||||
@protected
|
@protected
|
||||||
@override
|
@override
|
||||||
void _update() => gFFI.abModel.pullAb(quiet: true);
|
void _update() =>
|
||||||
|
{}; //gFFI.abModel.pullAb(force: ForcePullAb.current, quiet: true);
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
MenuEntryBase<String> _editTagAction(String id) {
|
MenuEntryBase<String> _editTagAction(String id) {
|
||||||
|
@ -62,7 +62,9 @@ class _PeerTabPageState extends State<PeerTabPage>
|
|||||||
AddressBook(
|
AddressBook(
|
||||||
menuPadding: _menuPadding(),
|
menuPadding: _menuPadding(),
|
||||||
),
|
),
|
||||||
({dynamic hint}) => gFFI.abModel.pullAb(force: hint == null)),
|
({dynamic hint}) => gFFI.abModel.pullAb(
|
||||||
|
force: hint == null ? ForcePullAb.listAndCurrent : null,
|
||||||
|
quiet: false)),
|
||||||
_TabEntry(
|
_TabEntry(
|
||||||
MyGroup(
|
MyGroup(
|
||||||
menuPadding: _menuPadding(),
|
menuPadding: _menuPadding(),
|
||||||
|
@ -32,9 +32,13 @@ bool filterAbTagByIntersection() {
|
|||||||
const _personalAddressBookName = "My address book";
|
const _personalAddressBookName = "My address book";
|
||||||
const _legacyAddressBookName = "Legacy address book";
|
const _legacyAddressBookName = "Legacy address book";
|
||||||
|
|
||||||
|
enum ForcePullAb {
|
||||||
|
listAndCurrent,
|
||||||
|
current,
|
||||||
|
}
|
||||||
|
|
||||||
class AbModel {
|
class AbModel {
|
||||||
final addressbooks = Map<String, BaseAb>.fromEntries([]).obs;
|
final addressbooks = Map<String, BaseAb>.fromEntries([]).obs;
|
||||||
List<AbProfile> abProfiles = List.empty(growable: true);
|
|
||||||
final RxString _currentName = ''.obs;
|
final RxString _currentName = ''.obs;
|
||||||
RxString get currentName => _currentName;
|
RxString get currentName => _currentName;
|
||||||
final _dummyAb = DummyAb();
|
final _dummyAb = DummyAb();
|
||||||
@ -47,19 +51,18 @@ class AbModel {
|
|||||||
RxBool get currentAbLoading => current.abLoading;
|
RxBool get currentAbLoading => current.abLoading;
|
||||||
RxString get currentAbPullError => current.pullError;
|
RxString get currentAbPullError => current.pullError;
|
||||||
RxString get currentAbPushError => current.pushError;
|
RxString get currentAbPushError => current.pushError;
|
||||||
bool get currentAbEmtpy => currentAbPeers.isEmpty && currentAbTags.isEmpty;
|
|
||||||
String? _personalAbGuid;
|
String? _personalAbGuid;
|
||||||
RxBool legacyMode = true.obs;
|
RxBool legacyMode = true.obs;
|
||||||
|
var _modeTested = false; // whether the mode has been tested
|
||||||
|
|
||||||
final sortTags = shouldSortTags().obs;
|
final sortTags = shouldSortTags().obs;
|
||||||
final filterByIntersection = filterAbTagByIntersection().obs;
|
final filterByIntersection = filterAbTagByIntersection().obs;
|
||||||
|
|
||||||
var _syncAllFromRecent = true;
|
var _syncAllFromRecent = true;
|
||||||
var _syncFromRecentLock = false;
|
var _syncFromRecentLock = false;
|
||||||
var _allInitialized = false;
|
|
||||||
var _timerCounter = 0;
|
var _timerCounter = 0;
|
||||||
var _cacheLoadOnceFlag = false;
|
var _cacheLoadOnceFlag = false;
|
||||||
var _everPulledProfiles = false;
|
var listInitialized = false;
|
||||||
var _maxPeerOneAb = 0;
|
var _maxPeerOneAb = 0;
|
||||||
|
|
||||||
WeakReference<FFI> parent;
|
WeakReference<FFI> parent;
|
||||||
@ -70,7 +73,8 @@ class AbModel {
|
|||||||
Timer.periodic(Duration(milliseconds: 500), (timer) async {
|
Timer.periodic(Duration(milliseconds: 500), (timer) async {
|
||||||
if (_timerCounter++ % 6 == 0) {
|
if (_timerCounter++ % 6 == 0) {
|
||||||
if (!gFFI.userModel.isLogin) return;
|
if (!gFFI.userModel.isLogin) return;
|
||||||
if (!_allInitialized) return;
|
if (!listInitialized) return;
|
||||||
|
if (!current.initialized || !current.canWrite()) return;
|
||||||
_syncFromRecent();
|
_syncFromRecent();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -79,39 +83,54 @@ class AbModel {
|
|||||||
|
|
||||||
reset() async {
|
reset() async {
|
||||||
print("reset ab model");
|
print("reset ab model");
|
||||||
_allInitialized = false;
|
_modeTested = false;
|
||||||
abProfiles.clear();
|
|
||||||
addressbooks.clear();
|
addressbooks.clear();
|
||||||
setCurrentName('');
|
setCurrentName('');
|
||||||
await bind.mainClearAb();
|
await bind.mainClearAb();
|
||||||
_everPulledProfiles = false;
|
listInitialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// #region ab
|
// #region ab
|
||||||
Future<void> pullAb({force = true, quiet = false}) async {
|
/// Pulls the address book data from the server.
|
||||||
|
///
|
||||||
|
/// If `force` is `ForcePullAb.listAndCurrent`, the function will pull the list of address books, current address book, and try initialize personal address book.
|
||||||
|
/// If `force` is `ForcePullAb.current`, the function will only pull the current address book.
|
||||||
|
/// If `quiet` is true, the function will not display any notifications or errors.
|
||||||
|
var _pulling = false;
|
||||||
|
Future<void> pullAb(
|
||||||
|
{required ForcePullAb? force, required bool quiet}) async {
|
||||||
|
if (_pulling) return;
|
||||||
|
_pulling = true;
|
||||||
|
try {
|
||||||
await _pullAb(force: force, quiet: quiet);
|
await _pullAb(force: force, quiet: quiet);
|
||||||
_refreshTab();
|
_refreshTab();
|
||||||
|
} catch (_) {}
|
||||||
|
_pulling = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _pullAb({force = true, quiet = false}) async {
|
Future<void> _pullAb(
|
||||||
debugPrint("pullAb, force:$force, quiet:$quiet");
|
{required ForcePullAb? force, required bool quiet}) async {
|
||||||
|
debugPrint("pullAb, force: $force, quiet: $quiet");
|
||||||
if (!gFFI.userModel.isLogin) return;
|
if (!gFFI.userModel.isLogin) return;
|
||||||
if (!force && _allInitialized) return;
|
if (force == null && listInitialized && current.initialized) return;
|
||||||
_allInitialized = false;
|
if (!listInitialized || force == ForcePullAb.listAndCurrent) {
|
||||||
try {
|
try {
|
||||||
|
if (!_modeTested) {
|
||||||
// Get personal address book guid
|
// Get personal address book guid
|
||||||
_personalAbGuid = null;
|
_personalAbGuid = null;
|
||||||
await _getPersonalAbGuid();
|
await _getPersonalAbGuid();
|
||||||
|
await _getAbSettings();
|
||||||
// Determine legacy mode based on whether _personalAbGuid is null
|
// Determine legacy mode based on whether _personalAbGuid is null
|
||||||
legacyMode.value = _personalAbGuid == null;
|
legacyMode.value = _personalAbGuid == null;
|
||||||
|
_modeTested = true;
|
||||||
|
}
|
||||||
if (_personalAbGuid != null) {
|
if (_personalAbGuid != null) {
|
||||||
await _getAbSettings();
|
debugPrint("pull ab list");
|
||||||
List<AbProfile> tmpAbProfiles = List.empty(growable: true);
|
List<AbProfile> abProfiles = List.empty(growable: true);
|
||||||
tmpAbProfiles.add(AbProfile(_personalAbGuid!, _personalAddressBookName,
|
abProfiles.add(AbProfile(_personalAbGuid!, _personalAddressBookName,
|
||||||
gFFI.userModel.userName.value, null, ShareRule.read.value));
|
gFFI.userModel.userName.value, null, ShareRule.read.value));
|
||||||
// get all address book name
|
// get all address book name
|
||||||
await _getSharedAbProfiles(tmpAbProfiles);
|
await _getSharedAbProfiles(abProfiles);
|
||||||
abProfiles = tmpAbProfiles;
|
|
||||||
addressbooks.removeWhere((key, value) =>
|
addressbooks.removeWhere((key, value) =>
|
||||||
abProfiles.firstWhereOrNull((e) => e.name == key) == null);
|
abProfiles.firstWhereOrNull((e) => e.name == key) == null);
|
||||||
for (int i = 0; i < abProfiles.length; i++) {
|
for (int i = 0; i < abProfiles.length; i++) {
|
||||||
@ -124,38 +143,46 @@ class AbModel {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// only legacy address book
|
// only legacy address book
|
||||||
addressbooks.removeWhere((key, value) => key != _legacyAddressBookName);
|
addressbooks
|
||||||
|
.removeWhere((key, value) => key != _legacyAddressBookName);
|
||||||
if (!addressbooks.containsKey(_legacyAddressBookName)) {
|
if (!addressbooks.containsKey(_legacyAddressBookName)) {
|
||||||
addressbooks[_legacyAddressBookName] = LegacyAb();
|
addressbooks[_legacyAddressBookName] = LegacyAb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set current address book name
|
// set current address book name
|
||||||
if (!_everPulledProfiles) {
|
if (!listInitialized) {
|
||||||
_everPulledProfiles = true;
|
listInitialized = true;
|
||||||
final name = bind.getLocalFlutterOption(k: 'current-ab-name');
|
final name = bind.getLocalFlutterOption(k: 'current-ab-name');
|
||||||
if (addressbooks.containsKey(name)) {
|
if (addressbooks.containsKey(name)) {
|
||||||
_currentName.value = name;
|
_currentName.value = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!addressbooks.containsKey(_currentName.value)) {
|
if (!addressbooks.containsKey(_currentName.value)) {
|
||||||
setCurrentName(_personalAddressBookName);
|
setCurrentName(legacyMode.value
|
||||||
|
? _legacyAddressBookName
|
||||||
|
: _personalAddressBookName);
|
||||||
|
}
|
||||||
|
// pull current address book
|
||||||
|
await current.pullAb(quiet: quiet);
|
||||||
|
// try initialize personal address book
|
||||||
|
if (!current.isPersonal()) {
|
||||||
|
final personalAb = addressbooks[_personalAddressBookName];
|
||||||
|
if (personalAb != null && !personalAb.initialized) {
|
||||||
|
await personalAb.pullAb(quiet: quiet);
|
||||||
}
|
}
|
||||||
// pull shared ab data, current first
|
|
||||||
await current.pullAb(force: force, quiet: quiet);
|
|
||||||
addressbooks.forEach((key, value) async {
|
|
||||||
if (key != current.name()) {
|
|
||||||
return await value.pullAb(force: force, quiet: quiet);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
_saveCache();
|
|
||||||
_allInitialized = true;
|
|
||||||
_syncAllFromRecent = true;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint("pullAb error: $e");
|
debugPrint("pull ab list error: $e");
|
||||||
}
|
}
|
||||||
// again in case of error happens
|
} else if (!current.initialized || force == ForcePullAb.current) {
|
||||||
if (!addressbooks.containsKey(_currentName.value)) {
|
try {
|
||||||
setCurrentName(_personalAddressBookName);
|
await current.pullAb(quiet: quiet);
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint("pull current Ab error: $e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (listInitialized && current.initialized) {
|
||||||
|
_saveCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +219,7 @@ class AbModel {
|
|||||||
headers['Content-Type'] = "application/json";
|
headers['Content-Type'] = "application/json";
|
||||||
final resp = await http.post(Uri.parse(api), headers: headers);
|
final resp = await http.post(Uri.parse(api), headers: headers);
|
||||||
if (resp.statusCode == 404) {
|
if (resp.statusCode == 404) {
|
||||||
debugPrint("HTTP 404, api server doesn't support shared address book");
|
debugPrint("HTTP 404, current api server is legacy mode");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Map<String, dynamic> json =
|
Map<String, dynamic> json =
|
||||||
@ -211,7 +238,7 @@ class AbModel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> _getSharedAbProfiles(List<AbProfile> tmpSharedAbs) async {
|
Future<bool> _getSharedAbProfiles(List<AbProfile> profiles) async {
|
||||||
final api = "${await bind.mainGetApiServer()}/api/ab/shared/profiles";
|
final api = "${await bind.mainGetApiServer()}/api/ab/shared/profiles";
|
||||||
try {
|
try {
|
||||||
var uri0 = Uri.parse(api);
|
var uri0 = Uri.parse(api);
|
||||||
@ -247,11 +274,11 @@ class AbModel {
|
|||||||
if (data is List) {
|
if (data is List) {
|
||||||
for (final profile in data) {
|
for (final profile in data) {
|
||||||
final u = AbProfile.fromJson(profile);
|
final u = AbProfile.fromJson(profile);
|
||||||
int index = tmpSharedAbs.indexWhere((e) => e.name == u.name);
|
int index = profiles.indexWhere((e) => e.name == u.name);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
tmpSharedAbs.add(u);
|
profiles.add(u);
|
||||||
} else {
|
} else {
|
||||||
tmpSharedAbs[index] = u;
|
profiles[index] = u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -475,11 +502,9 @@ class AbModel {
|
|||||||
final recents = await getRecentPeers();
|
final recents = await getRecentPeers();
|
||||||
if (recents.isEmpty) return;
|
if (recents.isEmpty) return;
|
||||||
debugPrint("sync from recent, len: ${recents.length}");
|
debugPrint("sync from recent, len: ${recents.length}");
|
||||||
addressbooks.forEach((key, value) async {
|
if (current.canWrite() && current.initialized) {
|
||||||
if (value.canWrite()) {
|
await current.syncFromRecent(recents);
|
||||||
await value.syncFromRecent(recents);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('_syncFromRecentWithoutLock: $e');
|
debugPrint('_syncFromRecentWithoutLock: $e');
|
||||||
}
|
}
|
||||||
@ -510,6 +535,7 @@ class AbModel {
|
|||||||
List<dynamic> _serializeCache() {
|
List<dynamic> _serializeCache() {
|
||||||
var res = [];
|
var res = [];
|
||||||
addressbooks.forEach((key, value) {
|
addressbooks.forEach((key, value) {
|
||||||
|
if (!value.isPersonal() && key != current.name()) return;
|
||||||
res.add({
|
res.add({
|
||||||
"guid": value.sharedProfile()?.guid ?? '',
|
"guid": value.sharedProfile()?.guid ?? '',
|
||||||
"name": key,
|
"name": key,
|
||||||
@ -616,7 +642,8 @@ class AbModel {
|
|||||||
return addressbooks.keys.toList();
|
return addressbooks.keys.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentName(String name) {
|
Future<void> setCurrentName(String name) async {
|
||||||
|
final oldName = _currentName.value;
|
||||||
if (addressbooks.containsKey(name)) {
|
if (addressbooks.containsKey(name)) {
|
||||||
_currentName.value = name;
|
_currentName.value = name;
|
||||||
} else {
|
} else {
|
||||||
@ -628,7 +655,14 @@ class AbModel {
|
|||||||
_currentName.value = '';
|
_currentName.value = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!current.initialized) {
|
||||||
|
await current.pullAb(quiet: true);
|
||||||
|
_saveCache();
|
||||||
|
}
|
||||||
_refreshTab();
|
_refreshTab();
|
||||||
|
if (oldName != _currentName.value) {
|
||||||
|
_syncAllFromRecent = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isCurrentAbFull(bool warn) {
|
bool isCurrentAbFull(bool warn) {
|
||||||
@ -648,12 +682,12 @@ class AbModel {
|
|||||||
Future<void> pullNonLegacyAfterChange({String? name}) async {
|
Future<void> pullNonLegacyAfterChange({String? name}) async {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
if (current.name() != _legacyAddressBookName) {
|
if (current.name() != _legacyAddressBookName) {
|
||||||
return await current.pullAb(force: true, quiet: true);
|
return await current.pullAb(quiet: true);
|
||||||
}
|
}
|
||||||
} else if (name != _legacyAddressBookName) {
|
} else if (name != _legacyAddressBookName) {
|
||||||
final ab = addressbooks[name];
|
final ab = addressbooks[name];
|
||||||
if (ab != null) {
|
if (ab != null) {
|
||||||
return await ab.pullAb(force: true, quiet: true);
|
return await ab.pullAb(quiet: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -696,13 +730,7 @@ abstract class BaseAb {
|
|||||||
final pullError = "".obs;
|
final pullError = "".obs;
|
||||||
final pushError = "".obs;
|
final pushError = "".obs;
|
||||||
final abLoading = false.obs;
|
final abLoading = false.obs;
|
||||||
|
bool initialized = false;
|
||||||
reset() {
|
|
||||||
pullError.value = '';
|
|
||||||
pushError.value = '';
|
|
||||||
tags.clear();
|
|
||||||
peers.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
String name();
|
String name();
|
||||||
|
|
||||||
@ -711,18 +739,19 @@ abstract class BaseAb {
|
|||||||
name() == _legacyAddressBookName;
|
name() == _legacyAddressBookName;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> pullAb({force = true, quiet = false}) async {
|
Future<void> pullAb({quiet = false}) async {
|
||||||
|
debugPrint("pull ab \"${name()}\"");
|
||||||
if (abLoading.value) return;
|
if (abLoading.value) return;
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
abLoading.value = true;
|
abLoading.value = true;
|
||||||
pullError.value = "";
|
pullError.value = "";
|
||||||
}
|
}
|
||||||
final ret = await pullAbImpl(force: force, quiet: quiet);
|
initialized = false;
|
||||||
|
initialized = await pullAbImpl(quiet: quiet);
|
||||||
abLoading.value = false;
|
abLoading.value = false;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> pullAbImpl({force = true, quiet = false});
|
Future<bool> pullAbImpl({quiet = false});
|
||||||
|
|
||||||
Future<String?> addPeers(List<Map<String, dynamic>> ps);
|
Future<String?> addPeers(List<Map<String, dynamic>> ps);
|
||||||
removeHash(Map<String, dynamic> p) {
|
removeHash(Map<String, dynamic> p) {
|
||||||
@ -806,7 +835,8 @@ class LegacyAb extends BaseAb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> pullAbImpl({force = true, quiet = false}) async {
|
Future<bool> pullAbImpl({quiet = false}) async {
|
||||||
|
bool ret = false;
|
||||||
final api = "${await bind.mainGetApiServer()}/api/ab";
|
final api = "${await bind.mainGetApiServer()}/api/ab";
|
||||||
int? statusCode;
|
int? statusCode;
|
||||||
try {
|
try {
|
||||||
@ -834,6 +864,7 @@ class LegacyAb extends BaseAb {
|
|||||||
if (data != null) {
|
if (data != null) {
|
||||||
_deserialize(data);
|
_deserialize(data);
|
||||||
}
|
}
|
||||||
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -848,6 +879,7 @@ class LegacyAb extends BaseAb {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> pushAb(
|
Future<bool> pushAb(
|
||||||
@ -1214,18 +1246,24 @@ class Ab extends BaseAb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> pullAbImpl({force = true, quiet = false}) async {
|
Future<bool> pullAbImpl({quiet = false}) async {
|
||||||
|
bool ret = true;
|
||||||
List<Peer> tmpPeers = [];
|
List<Peer> tmpPeers = [];
|
||||||
await _fetchPeers(tmpPeers);
|
if (!await _fetchPeers(tmpPeers)) {
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
peers.value = tmpPeers;
|
peers.value = tmpPeers;
|
||||||
List<AbTag> tmpTags = [];
|
List<AbTag> tmpTags = [];
|
||||||
await _fetchTags(tmpTags);
|
if (!await _fetchTags(tmpTags)) {
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
tags.value = tmpTags.map((e) => e.name).toList();
|
tags.value = tmpTags.map((e) => e.name).toList();
|
||||||
Map<String, int> tmpTagColors = {};
|
Map<String, int> tmpTagColors = {};
|
||||||
for (var t in tmpTags) {
|
for (var t in tmpTags) {
|
||||||
tmpTagColors[t.name] = t.color;
|
tmpTagColors[t.name] = t.color;
|
||||||
}
|
}
|
||||||
tagColors.value = tmpTagColors;
|
tagColors.value = tmpTagColors;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> _fetchPeers(List<Peer> tmpPeers) async {
|
Future<bool> _fetchPeers(List<Peer> tmpPeers) async {
|
||||||
@ -1639,7 +1677,7 @@ class DummyAb extends BaseAb {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String?> addPeers(List<Map<String, dynamic>> ps) async {
|
Future<String?> addPeers(List<Map<String, dynamic>> ps) async {
|
||||||
return "Unreachable";
|
return "dummpy";
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -1690,11 +1728,13 @@ class DummyAb extends BaseAb {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String name() {
|
String name() {
|
||||||
return "Unreachable";
|
return "dummpy";
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> pullAbImpl({force = true, quiet = false}) async {}
|
Future<bool> pullAbImpl({quiet = false}) async {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> renameTag(String oldTag, String newTag) async {
|
Future<bool> renameTag(String oldTag, String newTag) async {
|
||||||
|
@ -4,6 +4,7 @@ import 'dart:convert';
|
|||||||
import 'package:bot_toast/bot_toast.dart';
|
import 'package:bot_toast/bot_toast.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/common/hbbs/hbbs.dart';
|
import 'package:flutter_hbb/common/hbbs/hbbs.dart';
|
||||||
|
import 'package:flutter_hbb/models/ab_model.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
@ -102,7 +103,10 @@ class UserModel {
|
|||||||
|
|
||||||
// update ab and group status
|
// update ab and group status
|
||||||
static Future<void> updateOtherModels() async {
|
static Future<void> updateOtherModels() async {
|
||||||
await Future.wait([gFFI.abModel.pullAb(), gFFI.groupModel.pull()]);
|
await Future.wait([
|
||||||
|
gFFI.abModel.pullAb(force: ForcePullAb.listAndCurrent, quiet: false),
|
||||||
|
gFFI.groupModel.pull()
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> logOut({String? apiServer}) async {
|
Future<void> logOut({String? apiServer}) async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user