2023-12-28 18:53:21 +13:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
|
|
|
|
class ZenithClientProvider extends ChangeNotifier {
|
|
|
|
late Client _client;
|
2023-12-29 09:20:50 +13:00
|
|
|
bool _loading = true;
|
2023-12-28 18:53:21 +13:00
|
|
|
|
|
|
|
Client get client => _client;
|
|
|
|
|
2023-12-29 09:20:50 +13:00
|
|
|
bool get loading => _loading;
|
2023-12-28 18:53:21 +13:00
|
|
|
|
|
|
|
Future<void> initialize(
|
|
|
|
String homeserver, String username, String password) async {
|
2023-12-29 09:20:50 +13:00
|
|
|
_loading = true;
|
2023-12-28 18:53:21 +13:00
|
|
|
_client = Client("zenith");
|
2023-12-29 09:20:50 +13:00
|
|
|
try {
|
|
|
|
print("Checking homeserver...");
|
|
|
|
await client.checkHomeserver(Uri.parse(homeserver));
|
|
|
|
print("Logging in...");
|
|
|
|
await client.login(LoginType.mLoginPassword,
|
|
|
|
identifier: AuthenticationUserIdentifier(user: username),
|
|
|
|
password: password);
|
2023-12-29 11:31:26 +13:00
|
|
|
await client.roomsLoading;
|
|
|
|
await client.accountDataLoading;
|
2023-12-29 09:20:50 +13:00
|
|
|
} finally {
|
|
|
|
_loading = false;
|
|
|
|
}
|
2023-12-28 18:53:21 +13:00
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
}
|