From 32acc21a450ad27a8c2b2439bee753ca15b0c588 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 11 Dec 2020 10:27:38 +0100 Subject: [PATCH] refactor: Update sdk --- lib/components/matrix.dart | 35 ++++++++++----------------------- lib/views/login.dart | 21 +++++++++++--------- lib/views/settings.dart | 13 +++++++----- lib/views/settings_3pid.dart | 27 ++++--------------------- lib/views/settings_devices.dart | 11 +++++++++-- lib/views/sign_up_password.dart | 20 +++++++++++-------- pubspec.lock | 4 ++-- pubspec.yaml | 2 +- 8 files changed, 58 insertions(+), 75 deletions(-) diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index baf9dca2..cc0c6008 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -140,17 +140,6 @@ class MatrixState extends State { } } - Map getAuthByPassword(String password, [String session]) => { - 'type': 'm.login.password', - 'identifier': { - 'type': 'm.id.user', - 'user': client.userID, - }, - 'user': client.userID, - 'password': password, - if (session != null) 'session': session, - }; - StreamSubscription onRoomKeyRequestSub; StreamSubscription onKeyVerificationRequestSub; StreamSubscription onJitsiCallSub; @@ -160,11 +149,12 @@ class MatrixState extends State { StreamSubscription onBlurSub; void _onUiaRequest(UiaRequest uiaRequest) async { - uiaRequest.onUpdate = () => _onUiaRequest(uiaRequest); - if (uiaRequest.loading || uiaRequest.done || uiaRequest.fail) return; + uiaRequest.onUpdate = (_) => _onUiaRequest(uiaRequest); + if (uiaRequest.state != UiaRequestState.waitForUser || + uiaRequest.nextStages.isEmpty) return; final stage = uiaRequest.nextStages.first; switch (stage) { - case 'm.login.password': + case AuthenticationTypes.password: final input = await showTextInputDialog(context: context, textFields: [ DialogTextField( minLines: 1, @@ -174,17 +164,12 @@ class MatrixState extends State { ]); if (input?.isEmpty ?? true) return; return uiaRequest.completeStage( - 'm.login.password', - { - 'type': 'm.login.password', - 'identifier': { - 'type': 'm.id.user', - 'user': client.userID, - }, - 'user': client.userID, - 'password': input.single, - 'session': uiaRequest.session, - }, + AuthenticationPassword( + session: uiaRequest.session, + user: client.userID, + password: input.single, + identifier: AuthenticationUserIdentifier(user: client.userID), + ), ); default: debugPrint('Warning! Cannot handle the stage "$stage"'); diff --git a/lib/views/login.dart b/lib/views/login.dart index ccaa5aae..664ddbb5 100644 --- a/lib/views/login.dart +++ b/lib/views/login.dart @@ -137,16 +137,19 @@ class _LoginState extends State { ], ); if (password == null) return; - final threepidCreds = { - 'client_secret': clientSecret, - 'sid': (response as RequestTokenResponse).sid, - }; final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( - Matrix.of(context).client.changePassword(password.single, auth: { - 'type': 'm.login.email.identity', - 'threepidCreds': threepidCreds, // Don't ask... >.< - 'threepid_creds': threepidCreds, - }), + Matrix.of(context).client.changePassword( + password.single, + auth: AuthenticationThreePidCreds( + type: AuthenticationTypes.emailIdentity, + threepidCreds: [ + ThreepidCreds( + sid: (response as RequestTokenResponse).sid, + clientSecret: clientSecret, + ), + ], + ), + ), ); if (success != false) { FlushbarHelper.createSuccess( diff --git a/lib/views/settings.dart b/lib/views/settings.dart index 15530a42..67be51c0 100644 --- a/lib/views/settings.dart +++ b/lib/views/settings.dart @@ -123,11 +123,14 @@ class _SettingsState extends State { ); if (input == null) return; await SimpleDialogs(context).tryRequestWithLoadingDialog( - Matrix.of(context).client.deactivateAccount(auth: { - 'type': 'm.login.password', - 'user': Matrix.of(context).client.userID, - 'password': input.single, - }), + Matrix.of(context).client.deactivateAccount( + auth: AuthenticationPassword( + password: input.single, + user: Matrix.of(context).client.userID, + identifier: AuthenticationUserIdentifier( + user: Matrix.of(context).client.userID), + ), + ), ); } diff --git a/lib/views/settings_3pid.dart b/lib/views/settings_3pid.dart index f6c4f624..b9a231ba 100644 --- a/lib/views/settings_3pid.dart +++ b/lib/views/settings_3pid.dart @@ -69,32 +69,13 @@ class _Settings3PidState extends State { ); if (password == null) return; final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( - Future.microtask(() async { - final Function request = ({Map auth}) async => - Matrix.of(context).client.addThirdPartyIdentifier( + Matrix.of(context).client.uiaRequestBackground( + (auth) => Matrix.of(context).client.addThirdPartyIdentifier( clientSecret, (response as RequestTokenResponse).sid, auth: auth, - ); - try { - await request(); - } on MatrixException catch (exception) { - if (!exception.requireAdditionalAuthentication) rethrow; - await request( - auth: { - 'type': 'm.login.password', - 'identifier': { - 'type': 'm.id.user', - 'user': Matrix.of(context).client.userID, - }, - 'user': Matrix.of(context).client.userID, - 'password': password.single, - 'session': exception.session, - }, - ); - } - return; - }), + ), + ), ); if (success == false) return; setState(() => _request = null); diff --git a/lib/views/settings_devices.dart b/lib/views/settings_devices.dart index e0f782b0..4ab04554 100644 --- a/lib/views/settings_devices.dart +++ b/lib/views/settings_devices.dart @@ -61,8 +61,15 @@ class DevicesSettingsState extends State { if (password == null) return; final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( - matrix.client.deleteDevices(deviceIds, - auth: matrix.getAuthByPassword(password.single))); + matrix.client.deleteDevices( + deviceIds, + auth: AuthenticationPassword( + password: password.single, + user: matrix.client.userID, + identifier: AuthenticationUserIdentifier(user: matrix.client.userID), + ), + ), + ); if (success != false) { reload(); } diff --git a/lib/views/sign_up_password.dart b/lib/views/sign_up_password.dart index ce9d797a..10fa2cf1 100644 --- a/lib/views/sign_up_password.dart +++ b/lib/views/sign_up_password.dart @@ -26,7 +26,7 @@ class _SignUpPasswordState extends State { bool loading = false; bool showPassword = true; - void _signUpAction(BuildContext context, {Map auth}) async { + void _signUpAction(BuildContext context, {AuthenticationData auth}) async { var matrix = Matrix.of(context); if (passwordController.text.isEmpty) { setState(() => passwordError = L10n.of(context).pleaseEnterYourPassword); @@ -61,10 +61,13 @@ class _SignUpPasswordState extends State { true); if (currentStage == 'm.login.dummy') { - _signUpAction(context, auth: { - 'type': currentStage, - 'session': exception.session, - }); + _signUpAction( + context, + auth: AuthenticationData( + type: currentStage, + session: exception.session, + ), + ); } else { await Navigator.of(context).push( AppRoute.defaultRoute( @@ -72,9 +75,10 @@ class _SignUpPasswordState extends State { AuthWebView( currentStage, exception.session, - () => _signUpAction(context, auth: { - 'session': exception.session, - }), + () => _signUpAction( + context, + auth: AuthenticationData(session: exception.session), + ), ), ), ); diff --git a/pubspec.lock b/pubspec.lock index 04b15bb4..ea78ae4b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -201,8 +201,8 @@ packages: dependency: "direct main" description: path: "." - ref: "bd0c9b0e91e343da86e22bacb340fb2ea8603375" - resolved-ref: "bd0c9b0e91e343da86e22bacb340fb2ea8603375" + ref: main + resolved-ref: bd0c9b0e91e343da86e22bacb340fb2ea8603375 url: "https://gitlab.com/famedly/famedlysdk.git" source: git version: "0.0.1" diff --git a/pubspec.yaml b/pubspec.yaml index 7ac42e30..c47efeae 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: famedlysdk: git: url: https://gitlab.com/famedly/famedlysdk.git - ref: bd0c9b0e91e343da86e22bacb340fb2ea8603375 + ref: main localstorage: ^3.0.3+6 file_picker_cross: 4.2.2