From 527bcc63ad4f6b04dfd0607a7ce6f9260e6cff00 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 12 Aug 2022 15:23:32 +0200 Subject: [PATCH] refactor: Add reference to itself in bootstrap onUpdate callback --- lib/encryption/encryption.dart | 2 +- lib/encryption/utils/bootstrap.dart | 4 ++-- lib/src/utils/native_implementations.dart | 2 +- test/encryption/bootstrap_test.dart | 25 +++++------------------ 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index 19c8f508..3990c1e3 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -79,7 +79,7 @@ class Encryption { } } - Bootstrap bootstrap({void Function()? onUpdate}) => Bootstrap( + Bootstrap bootstrap({void Function(Bootstrap)? onUpdate}) => Bootstrap( encryption: this, onUpdate: onUpdate, ); diff --git a/lib/encryption/utils/bootstrap.dart b/lib/encryption/utils/bootstrap.dart index 62482dcc..f091647c 100644 --- a/lib/encryption/utils/bootstrap.dart +++ b/lib/encryption/utils/bootstrap.dart @@ -73,7 +73,7 @@ enum BootstrapState { class Bootstrap { final Encryption encryption; Client get client => encryption.client; - void Function()? onUpdate; + void Function(Bootstrap)? onUpdate; BootstrapState get state => _state; BootstrapState _state = BootstrapState.loading; Map? oldSsssKeys; @@ -593,7 +593,7 @@ class Bootstrap { _state = newState; } - onUpdate?.call(); + onUpdate?.call(this); } } diff --git a/lib/src/utils/native_implementations.dart b/lib/src/utils/native_implementations.dart index 5a947253..9e2ba965 100644 --- a/lib/src/utils/native_implementations.dart +++ b/lib/src/utils/native_implementations.dart @@ -55,7 +55,7 @@ abstract class NativeImplementations { /// this implementation will catch any non-implemented method dynamic noSuchMethod(Invocation invocation) { final dynamic argument = invocation.positionalArguments.single; - final bool retryInDummy = invocation.namedArguments['retryInDummy'] as bool; + final retryInDummy = invocation.namedArguments['retryInDummy'] as bool; final memberName = invocation.memberName.toString().split('"')[1]; Logs().w( diff --git a/test/encryption/bootstrap_test.dart b/test/encryption/bootstrap_test.dart index 935c61d9..112ca835 100644 --- a/test/encryption/bootstrap_test.dart +++ b/test/encryption/bootstrap_test.dart @@ -53,10 +53,7 @@ void main() { Bootstrap? bootstrap; bootstrap = client.encryption!.bootstrap( - onUpdate: () async { - while (bootstrap == null) { - await Future.delayed(Duration(milliseconds: 5)); - } + onUpdate: (bootstrap) async { if (bootstrap.state == BootstrapState.askWipeSsss) { bootstrap.wipeSsss(true); } else if (bootstrap.state == BootstrapState.askNewSsss) { @@ -111,10 +108,7 @@ void main() { if (!olmEnabled) return; Bootstrap? bootstrap; bootstrap = client.encryption!.bootstrap( - onUpdate: () async { - while (bootstrap == null) { - await Future.delayed(Duration(milliseconds: 5)); - } + onUpdate: (bootstrap) async { if (bootstrap.state == BootstrapState.askWipeSsss) { bootstrap.wipeSsss(false); } else if (bootstrap.state == BootstrapState.askUseExistingSsss) { @@ -165,10 +159,7 @@ void main() { Bootstrap? bootstrap; bootstrap = client.encryption!.bootstrap( - onUpdate: () async { - while (bootstrap == null) { - await Future.delayed(Duration(milliseconds: 5)); - } + onUpdate: (bootstrap) async { if (bootstrap.state == BootstrapState.askWipeSsss) { bootstrap.wipeSsss(false); } else if (bootstrap.state == BootstrapState.askUseExistingSsss) { @@ -219,10 +210,7 @@ void main() { client.accountData.clear(); Bootstrap? bootstrap; bootstrap = client.encryption!.bootstrap( - onUpdate: () async { - while (bootstrap == null) { - await Future.delayed(Duration(milliseconds: 5)); - } + onUpdate: (bootstrap) async { if (bootstrap.state == BootstrapState.askNewSsss) { await bootstrap.newSsss('thenewestfoxies'); } else if (bootstrap.state == BootstrapState.askSetupCrossSigning) { @@ -248,10 +236,7 @@ void main() { var askedBadSsss = false; Bootstrap? bootstrap; bootstrap = client.encryption!.bootstrap( - onUpdate: () async { - while (bootstrap == null) { - await Future.delayed(Duration(milliseconds: 5)); - } + onUpdate: (bootstrap) async { if (bootstrap.state == BootstrapState.askWipeSsss) { bootstrap.wipeSsss(false); } else if (bootstrap.state == BootstrapState.askBadSsss) {