refactor: Update sdk

This commit is contained in:
Christian Pauly 2020-12-11 10:27:38 +01:00
parent 2a367ca956
commit 32acc21a45
8 changed files with 58 additions and 75 deletions

View File

@ -140,17 +140,6 @@ class MatrixState extends State<Matrix> {
} }
} }
Map<String, dynamic> 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 onRoomKeyRequestSub;
StreamSubscription onKeyVerificationRequestSub; StreamSubscription onKeyVerificationRequestSub;
StreamSubscription onJitsiCallSub; StreamSubscription onJitsiCallSub;
@ -160,11 +149,12 @@ class MatrixState extends State<Matrix> {
StreamSubscription<html.Event> onBlurSub; StreamSubscription<html.Event> onBlurSub;
void _onUiaRequest(UiaRequest uiaRequest) async { void _onUiaRequest(UiaRequest uiaRequest) async {
uiaRequest.onUpdate = () => _onUiaRequest(uiaRequest); uiaRequest.onUpdate = (_) => _onUiaRequest(uiaRequest);
if (uiaRequest.loading || uiaRequest.done || uiaRequest.fail) return; if (uiaRequest.state != UiaRequestState.waitForUser ||
uiaRequest.nextStages.isEmpty) return;
final stage = uiaRequest.nextStages.first; final stage = uiaRequest.nextStages.first;
switch (stage) { switch (stage) {
case 'm.login.password': case AuthenticationTypes.password:
final input = await showTextInputDialog(context: context, textFields: [ final input = await showTextInputDialog(context: context, textFields: [
DialogTextField( DialogTextField(
minLines: 1, minLines: 1,
@ -174,17 +164,12 @@ class MatrixState extends State<Matrix> {
]); ]);
if (input?.isEmpty ?? true) return; if (input?.isEmpty ?? true) return;
return uiaRequest.completeStage( return uiaRequest.completeStage(
'm.login.password', AuthenticationPassword(
{ session: uiaRequest.session,
'type': 'm.login.password', user: client.userID,
'identifier': { password: input.single,
'type': 'm.id.user', identifier: AuthenticationUserIdentifier(user: client.userID),
'user': client.userID, ),
},
'user': client.userID,
'password': input.single,
'session': uiaRequest.session,
},
); );
default: default:
debugPrint('Warning! Cannot handle the stage "$stage"'); debugPrint('Warning! Cannot handle the stage "$stage"');

View File

@ -137,16 +137,19 @@ class _LoginState extends State<Login> {
], ],
); );
if (password == null) return; if (password == null) return;
final threepidCreds = {
'client_secret': clientSecret,
'sid': (response as RequestTokenResponse).sid,
};
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
Matrix.of(context).client.changePassword(password.single, auth: { Matrix.of(context).client.changePassword(
'type': 'm.login.email.identity', password.single,
'threepidCreds': threepidCreds, // Don't ask... >.< auth: AuthenticationThreePidCreds(
'threepid_creds': threepidCreds, type: AuthenticationTypes.emailIdentity,
}), threepidCreds: [
ThreepidCreds(
sid: (response as RequestTokenResponse).sid,
clientSecret: clientSecret,
),
],
),
),
); );
if (success != false) { if (success != false) {
FlushbarHelper.createSuccess( FlushbarHelper.createSuccess(

View File

@ -123,11 +123,14 @@ class _SettingsState extends State<Settings> {
); );
if (input == null) return; if (input == null) return;
await SimpleDialogs(context).tryRequestWithLoadingDialog( await SimpleDialogs(context).tryRequestWithLoadingDialog(
Matrix.of(context).client.deactivateAccount(auth: { Matrix.of(context).client.deactivateAccount(
'type': 'm.login.password', auth: AuthenticationPassword(
'user': Matrix.of(context).client.userID, password: input.single,
'password': input.single, user: Matrix.of(context).client.userID,
}), identifier: AuthenticationUserIdentifier(
user: Matrix.of(context).client.userID),
),
),
); );
} }

View File

@ -69,32 +69,13 @@ class _Settings3PidState extends State<Settings3Pid> {
); );
if (password == null) return; if (password == null) return;
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
Future.microtask(() async { Matrix.of(context).client.uiaRequestBackground(
final Function request = ({Map<String, dynamic> auth}) async => (auth) => Matrix.of(context).client.addThirdPartyIdentifier(
Matrix.of(context).client.addThirdPartyIdentifier(
clientSecret, clientSecret,
(response as RequestTokenResponse).sid, (response as RequestTokenResponse).sid,
auth: auth, 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; if (success == false) return;
setState(() => _request = null); setState(() => _request = null);

View File

@ -61,8 +61,15 @@ class DevicesSettingsState extends State<DevicesSettings> {
if (password == null) return; if (password == null) return;
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
matrix.client.deleteDevices(deviceIds, matrix.client.deleteDevices(
auth: matrix.getAuthByPassword(password.single))); deviceIds,
auth: AuthenticationPassword(
password: password.single,
user: matrix.client.userID,
identifier: AuthenticationUserIdentifier(user: matrix.client.userID),
),
),
);
if (success != false) { if (success != false) {
reload(); reload();
} }

View File

@ -26,7 +26,7 @@ class _SignUpPasswordState extends State<SignUpPassword> {
bool loading = false; bool loading = false;
bool showPassword = true; bool showPassword = true;
void _signUpAction(BuildContext context, {Map<String, dynamic> auth}) async { void _signUpAction(BuildContext context, {AuthenticationData auth}) async {
var matrix = Matrix.of(context); var matrix = Matrix.of(context);
if (passwordController.text.isEmpty) { if (passwordController.text.isEmpty) {
setState(() => passwordError = L10n.of(context).pleaseEnterYourPassword); setState(() => passwordError = L10n.of(context).pleaseEnterYourPassword);
@ -61,10 +61,13 @@ class _SignUpPasswordState extends State<SignUpPassword> {
true); true);
if (currentStage == 'm.login.dummy') { if (currentStage == 'm.login.dummy') {
_signUpAction(context, auth: { _signUpAction(
'type': currentStage, context,
'session': exception.session, auth: AuthenticationData(
}); type: currentStage,
session: exception.session,
),
);
} else { } else {
await Navigator.of(context).push( await Navigator.of(context).push(
AppRoute.defaultRoute( AppRoute.defaultRoute(
@ -72,9 +75,10 @@ class _SignUpPasswordState extends State<SignUpPassword> {
AuthWebView( AuthWebView(
currentStage, currentStage,
exception.session, exception.session,
() => _signUpAction(context, auth: { () => _signUpAction(
'session': exception.session, context,
}), auth: AuthenticationData(session: exception.session),
),
), ),
), ),
); );

View File

@ -201,8 +201,8 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
path: "." path: "."
ref: "bd0c9b0e91e343da86e22bacb340fb2ea8603375" ref: main
resolved-ref: "bd0c9b0e91e343da86e22bacb340fb2ea8603375" resolved-ref: bd0c9b0e91e343da86e22bacb340fb2ea8603375
url: "https://gitlab.com/famedly/famedlysdk.git" url: "https://gitlab.com/famedly/famedlysdk.git"
source: git source: git
version: "0.0.1" version: "0.0.1"

View File

@ -13,7 +13,7 @@ dependencies:
famedlysdk: famedlysdk:
git: git:
url: https://gitlab.com/famedly/famedlysdk.git url: https://gitlab.com/famedly/famedlysdk.git
ref: bd0c9b0e91e343da86e22bacb340fb2ea8603375 ref: main
localstorage: ^3.0.3+6 localstorage: ^3.0.3+6
file_picker_cross: 4.2.2 file_picker_cross: 4.2.2