diff --git a/lib/src/client.dart b/lib/src/client.dart index bc02e1f6..bae77cb6 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -284,7 +284,7 @@ class Client extends MatrixApi { } /// Gets discovery information about the domain. The file may include additional keys. - Future getWellKnownInformationsByUserId( + Future 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 checkHomeserver(dynamic homeserverUrl, + Future 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 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. diff --git a/pubspec.yaml b/pubspec.yaml index 9c177949..a30dfa48 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/client_test.dart b/test/client_test.dart index 4112e35a..b469dfdf 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -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); }); diff --git a/test/event_test.dart b/test/event_test.dart index 4d4d4615..2f966ab6 100644 --- a/test/event_test.dart +++ b/test/event_test.dart @@ -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)); diff --git a/test/user_test.dart b/test/user_test.dart index edb2691f..3cbbd1b6 100644 --- a/test/user_test.dart +++ b/test/user_test.dart @@ -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 { diff --git a/test_driver/famedlysdk_test.dart b/test_driver/famedlysdk_test.dart index 90a66a61..ba318bba 100644 --- a/test_driver/famedlysdk_test.dart +++ b/test_driver/famedlysdk_test.dart @@ -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' ++++");