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 onKeyVerificationRequestSub;
StreamSubscription onJitsiCallSub;
@ -160,11 +149,12 @@ class MatrixState extends State<Matrix> {
StreamSubscription<html.Event> 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<Matrix> {
]);
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"');

View File

@ -137,16 +137,19 @@ class _LoginState extends State<Login> {
],
);
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(

View File

@ -123,11 +123,14 @@ class _SettingsState extends State<Settings> {
);
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),
),
),
);
}

View File

@ -69,32 +69,13 @@ class _Settings3PidState extends State<Settings3Pid> {
);
if (password == null) return;
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
Future.microtask(() async {
final Function request = ({Map<String, dynamic> 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);

View File

@ -61,8 +61,15 @@ class DevicesSettingsState extends State<DevicesSettings> {
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();
}

View File

@ -26,7 +26,7 @@ class _SignUpPasswordState extends State<SignUpPassword> {
bool loading = false;
bool showPassword = true;
void _signUpAction(BuildContext context, {Map<String, dynamic> 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<SignUpPassword> {
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<SignUpPassword> {
AuthWebView(
currentStage,
exception.session,
() => _signUpAction(context, auth: {
'session': exception.session,
}),
() => _signUpAction(
context,
auth: AuthenticationData(session: exception.session),
),
),
),
);

View File

@ -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"

View File

@ -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