refactor: sdk 1.0
This commit is contained in:
parent
ca4db07d83
commit
e548d8f895
23 changed files with 1775 additions and 175 deletions
|
|
@ -69,10 +69,11 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
homeserverController.text.trim().toLowerCase().replaceAll(' ', '-');
|
||||
|
||||
if (homeserverInput.isEmpty) {
|
||||
final client = await Matrix.of(context).getLoginClient();
|
||||
setState(() {
|
||||
error = loginFlows = null;
|
||||
isLoading = false;
|
||||
Matrix.of(context).getLoginClient().homeserver = null;
|
||||
client.homeserver = null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
@ -88,7 +89,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
if (homeserver.scheme.isEmpty) {
|
||||
homeserver = Uri.https(homeserverInput, '');
|
||||
}
|
||||
final client = Matrix.of(context).getLoginClient();
|
||||
final client = await Matrix.of(context).getLoginClient();
|
||||
final (_, _, loginFlows) = await client.checkHomeserver(homeserver);
|
||||
this.loginFlows = loginFlows;
|
||||
if (supportsSso && !legacyPasswordLogin) {
|
||||
|
|
@ -105,6 +106,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
}
|
||||
context.push(
|
||||
'${GoRouter.of(context).routeInformationProvider.value.uri.path}/login',
|
||||
extra: client,
|
||||
);
|
||||
} catch (e) {
|
||||
setState(
|
||||
|
|
@ -142,8 +144,8 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
: isDefaultPlatform
|
||||
? '${AppConfig.appOpenUrlScheme.toLowerCase()}://login'
|
||||
: 'http://localhost:3001//login';
|
||||
|
||||
final url = Matrix.of(context).getLoginClient().homeserver!.replace(
|
||||
final client = await Matrix.of(context).getLoginClient();
|
||||
final url = client.homeserver!.replace(
|
||||
path: '/_matrix/client/v3/login/sso/redirect',
|
||||
queryParameters: {'redirectUrl': redirectUrl},
|
||||
);
|
||||
|
|
@ -164,11 +166,12 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
isLoading = true;
|
||||
});
|
||||
try {
|
||||
await Matrix.of(context).getLoginClient().login(
|
||||
LoginType.mLoginToken,
|
||||
token: token,
|
||||
initialDeviceDisplayName: PlatformInfos.clientName,
|
||||
);
|
||||
final client = await Matrix.of(context).getLoginClient();
|
||||
client.login(
|
||||
LoginType.mLoginToken,
|
||||
token: token,
|
||||
initialDeviceDisplayName: PlatformInfos.clientName,
|
||||
);
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
error = e.toLocalizedString(context);
|
||||
|
|
@ -200,7 +203,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
isLoading = true;
|
||||
});
|
||||
try {
|
||||
final client = Matrix.of(context).getLoginClient();
|
||||
final client = await Matrix.of(context).getLoginClient();
|
||||
await client.importDump(String.fromCharCodes(await file.readAsBytes()));
|
||||
Matrix.of(context).initMatrix();
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ import '../../utils/platform_infos.dart';
|
|||
import 'login_view.dart';
|
||||
|
||||
class Login extends StatefulWidget {
|
||||
const Login({super.key});
|
||||
final Client client;
|
||||
const Login({required this.client, super.key});
|
||||
|
||||
@override
|
||||
LoginController createState() => LoginController();
|
||||
|
|
@ -68,17 +69,18 @@ class LoginController extends State<Login> {
|
|||
} else {
|
||||
identifier = AuthenticationUserIdentifier(user: username);
|
||||
}
|
||||
await matrix.getLoginClient().login(
|
||||
LoginType.mLoginPassword,
|
||||
identifier: identifier,
|
||||
// To stay compatible with older server versions
|
||||
// ignore: deprecated_member_use
|
||||
user: identifier.type == AuthenticationIdentifierTypes.userId
|
||||
? username
|
||||
: null,
|
||||
password: passwordController.text,
|
||||
initialDeviceDisplayName: PlatformInfos.clientName,
|
||||
);
|
||||
final client = await matrix.getLoginClient();
|
||||
client.login(
|
||||
LoginType.mLoginPassword,
|
||||
identifier: identifier,
|
||||
// To stay compatible with older server versions
|
||||
// ignore: deprecated_member_use
|
||||
user: identifier.type == AuthenticationIdentifierTypes.userId
|
||||
? username
|
||||
: null,
|
||||
password: passwordController.text,
|
||||
initialDeviceDisplayName: PlatformInfos.clientName,
|
||||
);
|
||||
} on MatrixException catch (exception) {
|
||||
setState(() => passwordError = exception.errorMessage);
|
||||
return setState(() => loading = false);
|
||||
|
|
@ -103,14 +105,13 @@ class LoginController extends State<Login> {
|
|||
void _checkWellKnown(String userId) async {
|
||||
if (mounted) setState(() => usernameError = null);
|
||||
if (!userId.isValidMatrixId) return;
|
||||
final oldHomeserver = Matrix.of(context).getLoginClient().homeserver;
|
||||
final oldHomeserver = widget.client.homeserver;
|
||||
try {
|
||||
var newDomain = Uri.https(userId.domain!, '');
|
||||
Matrix.of(context).getLoginClient().homeserver = newDomain;
|
||||
widget.client.homeserver = newDomain;
|
||||
DiscoveryInformation? wellKnownInformation;
|
||||
try {
|
||||
wellKnownInformation =
|
||||
await Matrix.of(context).getLoginClient().getWellknown();
|
||||
wellKnownInformation = await widget.client.getWellknown();
|
||||
if (wellKnownInformation.mHomeserver.baseUrl.toString().isNotEmpty) {
|
||||
newDomain = wellKnownInformation.mHomeserver.baseUrl;
|
||||
}
|
||||
|
|
@ -118,10 +119,10 @@ class LoginController extends State<Login> {
|
|||
// do nothing, newDomain is already set to a reasonable fallback
|
||||
}
|
||||
if (newDomain != oldHomeserver) {
|
||||
await Matrix.of(context).getLoginClient().checkHomeserver(newDomain);
|
||||
await widget.client.checkHomeserver(newDomain);
|
||||
|
||||
if (Matrix.of(context).getLoginClient().homeserver == null) {
|
||||
Matrix.of(context).getLoginClient().homeserver = oldHomeserver;
|
||||
if (widget.client.homeserver == null) {
|
||||
widget.client.homeserver = oldHomeserver;
|
||||
// okay, the server we checked does not appear to be a matrix server
|
||||
Logs().v(
|
||||
'$newDomain is not running a homeserver, asking to use $oldHomeserver',
|
||||
|
|
@ -144,13 +145,13 @@ class LoginController extends State<Login> {
|
|||
usernameError = null;
|
||||
if (mounted) setState(() {});
|
||||
} else {
|
||||
Matrix.of(context).getLoginClient().homeserver = oldHomeserver;
|
||||
widget.client.homeserver = oldHomeserver;
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Matrix.of(context).getLoginClient().homeserver = oldHomeserver;
|
||||
widget.client.homeserver = oldHomeserver;
|
||||
usernameError = e.toLocalizedString(context);
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
|
@ -173,12 +174,11 @@ class LoginController extends State<Login> {
|
|||
final clientSecret = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
final response = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
Matrix.of(context).getLoginClient().requestTokenToResetPasswordEmail(
|
||||
clientSecret,
|
||||
input,
|
||||
sendAttempt++,
|
||||
),
|
||||
future: () => widget.client.requestTokenToResetPasswordEmail(
|
||||
clientSecret,
|
||||
input,
|
||||
sendAttempt++,
|
||||
),
|
||||
);
|
||||
if (response.error != null) return;
|
||||
final password = await showTextInputDialog(
|
||||
|
|
@ -215,11 +215,11 @@ class LoginController extends State<Login> {
|
|||
};
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).getLoginClient().request(
|
||||
RequestType.POST,
|
||||
'/client/v3/account/password',
|
||||
data: data,
|
||||
),
|
||||
future: () => widget.client.request(
|
||||
RequestType.POST,
|
||||
'/client/v3/account/password',
|
||||
data: data,
|
||||
),
|
||||
);
|
||||
if (success.error == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ class LoginView extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
final homeserver = Matrix.of(context)
|
||||
.getLoginClient()
|
||||
.homeserver
|
||||
final homeserver = controller.widget.client.homeserver
|
||||
.toString()
|
||||
.replaceFirst('https://', '');
|
||||
final title = L10n.of(context).logInTo(homeserver);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue