Merge branch 'krille/update-login' into 'main'

refactor: Update to matrix_api_lite 0.2.0

See merge request famedly/famedlysdk!664
This commit is contained in:
Krille Fear 2021-03-09 18:22:52 +00:00
commit fb0de1ce59
6 changed files with 40 additions and 22 deletions

View File

@ -284,7 +284,7 @@ class Client extends MatrixApi {
}
/// Gets discovery information about the domain. The file may include additional keys.
Future<WellKnownInformations> getWellKnownInformationsByUserId(
Future<WellKnownInformation> getWellKnownInformationsByUserId(
String MatrixIdOrDomain,
) async {
final response = await http
@ -296,7 +296,7 @@ class Client extends MatrixApi {
// No-OP
}
final rawJson = json.decode(respBody);
return WellKnownInformations.fromJson(rawJson);
return WellKnownInformation.fromJson(rawJson);
}
@Deprecated('Use [checkHomeserver] instead.')
@ -313,7 +313,7 @@ class Client extends MatrixApi {
/// login types. Throws an exception if the server is not compatible with the
/// client and sets [homeserver] to [serverUrl] if it is. Supports the types [Uri]
/// and [String].
Future<WellKnownInformations> checkHomeserver(dynamic homeserverUrl,
Future<WellKnownInformation> checkHomeserver(dynamic homeserverUrl,
{bool checkWellKnown = true}) async {
try {
if (homeserverUrl is Uri) {
@ -331,10 +331,10 @@ class Client extends MatrixApi {
}
// Look up well known
WellKnownInformations wellKnown;
WellKnownInformation wellKnown;
if (checkWellKnown) {
try {
wellKnown = await requestWellKnownInformations();
wellKnown = await requestWellKnownInformation();
homeserverUrl = wellKnown.mHomeserver.baseUrl.trim();
// strip a trailing slash
if (homeserverUrl.endsWith('/')) {
@ -408,33 +408,40 @@ class Client extends MatrixApi {
/// Handles the login and allows the client to call all APIs which require
/// authentication. Returns false if the login was not successful. Throws
/// MatrixException if login was not successful.
/// To just login with the username 'alice' you set [identifier] to:
/// `AuthenticationUserIdentifier(user: 'alice')`
/// Maybe you want to set [user] to the same String to stay compatible with
/// older server versions.
@override
Future<LoginResponse> login({
String type = AuthenticationTypes.password,
String userIdentifierType = AuthenticationIdentifierTypes.userId,
String user,
String medium,
String address,
AuthenticationIdentifier identifier,
String password,
String token,
String deviceId,
String initialDeviceDisplayName,
AuthenticationData auth,
@Deprecated('Deprecated in favour of identifier.') String user,
@Deprecated('Deprecated in favour of identifier.') String medium,
@Deprecated('Deprecated in favour of identifier.') String address,
}) async {
if (homeserver == null && user.isValidMatrixId) {
await checkHomeserver(user.domain);
}
final loginResp = await super.login(
type: type,
userIdentifierType: userIdentifierType,
user: user,
identifier: identifier,
password: password,
token: token,
deviceId: deviceId,
initialDeviceDisplayName: initialDeviceDisplayName,
medium: medium,
address: address,
token: token,
auth: auth,
// ignore: deprecated_member_use
user: user,
// ignore: deprecated_member_use
medium: medium,
// ignore: deprecated_member_use
address: address,
);
// Connect if there is an access token in the response.

View File

@ -23,7 +23,7 @@ dependencies:
matrix_file_e2ee: ^1.0.5
isolate: ^2.0.3
logger: ^0.9.4
matrix_api_lite: ^0.1.9
matrix_api_lite: ^0.2.0
dev_dependencies:
test: ^1.15.7

View File

@ -324,7 +324,9 @@ void main() {
await matrix.checkHomeserver('https://fakeserver.notexisting',
checkWellKnown: false);
final loginResp = await matrix.login(user: 'test', password: '1234');
final loginResp = await matrix.login(
identifier: AuthenticationUserIdentifier(user: 'test'),
password: '1234');
expect(loginResp != null, true);
});

View File

@ -269,7 +269,9 @@ void main() {
var matrix = Client('testclient', httpClient: FakeMatrixApi());
await matrix.checkHomeserver('https://fakeserver.notexisting',
checkWellKnown: false);
await matrix.login(user: 'test', password: '1234');
await matrix.login(
identifier: AuthenticationUserIdentifier(user: 'test'),
password: '1234');
var event = Event.fromJson(
jsonObj, Room(id: '!1234:example.com', client: matrix));
@ -286,7 +288,9 @@ void main() {
var matrix = Client('testclient', httpClient: FakeMatrixApi());
await matrix.checkHomeserver('https://fakeserver.notexisting',
checkWellKnown: false);
await matrix.login(user: 'test', password: '1234');
await matrix.login(
identifier: AuthenticationUserIdentifier(user: 'test'),
password: '1234');
var event = Event.fromJson(
jsonObj, Room(id: '!1234:example.com', client: matrix));

View File

@ -108,7 +108,9 @@ void main() {
test('startDirectChat', () async {
await client.checkHomeserver('https://fakeserver.notexisting',
checkWellKnown: false);
await client.login(user: 'test', password: '1234');
await client.login(
identifier: AuthenticationUserIdentifier(user: 'test'),
password: '1234');
await user1.startDirectChat();
});
test('getPresence', () async {

View File

@ -23,14 +23,16 @@ void test() async {
testClientA = Client('TestClientA', databaseBuilder: getDatabase);
await testClientA.checkHomeserver(TestUser.homeserver);
await testClientA.login(
user: TestUser.username, password: TestUser.password);
identifier: AuthenticationUserIdentifier(user: TestUser.username),
password: TestUser.password);
assert(testClientA.encryptionEnabled);
Logs().i('++++ Login Bob ++++');
testClientB = Client('TestClientB', databaseBuilder: getDatabase);
await testClientB.checkHomeserver(TestUser.homeserver);
await testClientB.login(
user: TestUser.username2, password: TestUser.password);
identifier: AuthenticationUserIdentifier(user: TestUser.username2),
password: TestUser.password);
assert(testClientB.encryptionEnabled);
Logs().i('++++ (Alice) Leave all rooms ++++');
@ -218,7 +220,8 @@ void test() async {
var testClientC = Client('TestClientC', databaseBuilder: getDatabase);
await testClientC.checkHomeserver(TestUser.homeserver);
await testClientC.login(
user: TestUser.username2, password: TestUser.password);
identifier: AuthenticationUserIdentifier(user: TestUser.username2),
password: TestUser.password);
await Future.delayed(Duration(seconds: 3));
Logs().i("++++ (Alice) Send again encrypted message: '$testMessage4' ++++");