refactor: Update to matrix_api_lite 0.2.0
This introduces a minor breaking change in the login method. It now uses correctly the AuthenticationIdentifier and deprecates the user, medium and address parameter.
This commit is contained in:
parent
5cf97886b4
commit
97daae3419
|
|
@ -284,7 +284,7 @@ class Client extends MatrixApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets discovery information about the domain. The file may include additional keys.
|
/// Gets discovery information about the domain. The file may include additional keys.
|
||||||
Future<WellKnownInformations> getWellKnownInformationsByUserId(
|
Future<WellKnownInformation> getWellKnownInformationsByUserId(
|
||||||
String MatrixIdOrDomain,
|
String MatrixIdOrDomain,
|
||||||
) async {
|
) async {
|
||||||
final response = await http
|
final response = await http
|
||||||
|
|
@ -296,7 +296,7 @@ class Client extends MatrixApi {
|
||||||
// No-OP
|
// No-OP
|
||||||
}
|
}
|
||||||
final rawJson = json.decode(respBody);
|
final rawJson = json.decode(respBody);
|
||||||
return WellKnownInformations.fromJson(rawJson);
|
return WellKnownInformation.fromJson(rawJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated('Use [checkHomeserver] instead.')
|
@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
|
/// 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]
|
/// client and sets [homeserver] to [serverUrl] if it is. Supports the types [Uri]
|
||||||
/// and [String].
|
/// and [String].
|
||||||
Future<WellKnownInformations> checkHomeserver(dynamic homeserverUrl,
|
Future<WellKnownInformation> checkHomeserver(dynamic homeserverUrl,
|
||||||
{bool checkWellKnown = true}) async {
|
{bool checkWellKnown = true}) async {
|
||||||
try {
|
try {
|
||||||
if (homeserverUrl is Uri) {
|
if (homeserverUrl is Uri) {
|
||||||
|
|
@ -331,10 +331,10 @@ class Client extends MatrixApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look up well known
|
// Look up well known
|
||||||
WellKnownInformations wellKnown;
|
WellKnownInformation wellKnown;
|
||||||
if (checkWellKnown) {
|
if (checkWellKnown) {
|
||||||
try {
|
try {
|
||||||
wellKnown = await requestWellKnownInformations();
|
wellKnown = await requestWellKnownInformation();
|
||||||
homeserverUrl = wellKnown.mHomeserver.baseUrl.trim();
|
homeserverUrl = wellKnown.mHomeserver.baseUrl.trim();
|
||||||
// strip a trailing slash
|
// strip a trailing slash
|
||||||
if (homeserverUrl.endsWith('/')) {
|
if (homeserverUrl.endsWith('/')) {
|
||||||
|
|
@ -408,33 +408,40 @@ class Client extends MatrixApi {
|
||||||
/// Handles the login and allows the client to call all APIs which require
|
/// Handles the login and allows the client to call all APIs which require
|
||||||
/// authentication. Returns false if the login was not successful. Throws
|
/// authentication. Returns false if the login was not successful. Throws
|
||||||
/// MatrixException if login was not successful.
|
/// 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
|
@override
|
||||||
Future<LoginResponse> login({
|
Future<LoginResponse> login({
|
||||||
String type = AuthenticationTypes.password,
|
String type = AuthenticationTypes.password,
|
||||||
String userIdentifierType = AuthenticationIdentifierTypes.userId,
|
AuthenticationIdentifier identifier,
|
||||||
String user,
|
|
||||||
String medium,
|
|
||||||
String address,
|
|
||||||
String password,
|
String password,
|
||||||
String token,
|
String token,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
String initialDeviceDisplayName,
|
String initialDeviceDisplayName,
|
||||||
AuthenticationData auth,
|
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 {
|
}) async {
|
||||||
if (homeserver == null && user.isValidMatrixId) {
|
if (homeserver == null && user.isValidMatrixId) {
|
||||||
await checkHomeserver(user.domain);
|
await checkHomeserver(user.domain);
|
||||||
}
|
}
|
||||||
final loginResp = await super.login(
|
final loginResp = await super.login(
|
||||||
type: type,
|
type: type,
|
||||||
userIdentifierType: userIdentifierType,
|
identifier: identifier,
|
||||||
user: user,
|
|
||||||
password: password,
|
password: password,
|
||||||
|
token: token,
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
initialDeviceDisplayName: initialDeviceDisplayName,
|
initialDeviceDisplayName: initialDeviceDisplayName,
|
||||||
medium: medium,
|
|
||||||
address: address,
|
|
||||||
token: token,
|
|
||||||
auth: auth,
|
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.
|
// Connect if there is an access token in the response.
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ dependencies:
|
||||||
matrix_file_e2ee: ^1.0.5
|
matrix_file_e2ee: ^1.0.5
|
||||||
isolate: ^2.0.3
|
isolate: ^2.0.3
|
||||||
logger: ^0.9.4
|
logger: ^0.9.4
|
||||||
matrix_api_lite: ^0.1.9
|
matrix_api_lite: ^0.2.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
test: ^1.15.7
|
test: ^1.15.7
|
||||||
|
|
|
||||||
|
|
@ -324,7 +324,9 @@ void main() {
|
||||||
await matrix.checkHomeserver('https://fakeserver.notexisting',
|
await matrix.checkHomeserver('https://fakeserver.notexisting',
|
||||||
checkWellKnown: false);
|
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);
|
expect(loginResp != null, true);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -269,7 +269,9 @@ void main() {
|
||||||
var matrix = Client('testclient', httpClient: FakeMatrixApi());
|
var matrix = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
await matrix.checkHomeserver('https://fakeserver.notexisting',
|
await matrix.checkHomeserver('https://fakeserver.notexisting',
|
||||||
checkWellKnown: false);
|
checkWellKnown: false);
|
||||||
await matrix.login(user: 'test', password: '1234');
|
await matrix.login(
|
||||||
|
identifier: AuthenticationUserIdentifier(user: 'test'),
|
||||||
|
password: '1234');
|
||||||
|
|
||||||
var event = Event.fromJson(
|
var event = Event.fromJson(
|
||||||
jsonObj, Room(id: '!1234:example.com', client: matrix));
|
jsonObj, Room(id: '!1234:example.com', client: matrix));
|
||||||
|
|
@ -286,7 +288,9 @@ void main() {
|
||||||
var matrix = Client('testclient', httpClient: FakeMatrixApi());
|
var matrix = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
await matrix.checkHomeserver('https://fakeserver.notexisting',
|
await matrix.checkHomeserver('https://fakeserver.notexisting',
|
||||||
checkWellKnown: false);
|
checkWellKnown: false);
|
||||||
await matrix.login(user: 'test', password: '1234');
|
await matrix.login(
|
||||||
|
identifier: AuthenticationUserIdentifier(user: 'test'),
|
||||||
|
password: '1234');
|
||||||
|
|
||||||
var event = Event.fromJson(
|
var event = Event.fromJson(
|
||||||
jsonObj, Room(id: '!1234:example.com', client: matrix));
|
jsonObj, Room(id: '!1234:example.com', client: matrix));
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,9 @@ void main() {
|
||||||
test('startDirectChat', () async {
|
test('startDirectChat', () async {
|
||||||
await client.checkHomeserver('https://fakeserver.notexisting',
|
await client.checkHomeserver('https://fakeserver.notexisting',
|
||||||
checkWellKnown: false);
|
checkWellKnown: false);
|
||||||
await client.login(user: 'test', password: '1234');
|
await client.login(
|
||||||
|
identifier: AuthenticationUserIdentifier(user: 'test'),
|
||||||
|
password: '1234');
|
||||||
await user1.startDirectChat();
|
await user1.startDirectChat();
|
||||||
});
|
});
|
||||||
test('getPresence', () async {
|
test('getPresence', () async {
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,16 @@ void test() async {
|
||||||
testClientA = Client('TestClientA', databaseBuilder: getDatabase);
|
testClientA = Client('TestClientA', databaseBuilder: getDatabase);
|
||||||
await testClientA.checkHomeserver(TestUser.homeserver);
|
await testClientA.checkHomeserver(TestUser.homeserver);
|
||||||
await testClientA.login(
|
await testClientA.login(
|
||||||
user: TestUser.username, password: TestUser.password);
|
identifier: AuthenticationUserIdentifier(user: TestUser.username),
|
||||||
|
password: TestUser.password);
|
||||||
assert(testClientA.encryptionEnabled);
|
assert(testClientA.encryptionEnabled);
|
||||||
|
|
||||||
Logs().i('++++ Login Bob ++++');
|
Logs().i('++++ Login Bob ++++');
|
||||||
testClientB = Client('TestClientB', databaseBuilder: getDatabase);
|
testClientB = Client('TestClientB', databaseBuilder: getDatabase);
|
||||||
await testClientB.checkHomeserver(TestUser.homeserver);
|
await testClientB.checkHomeserver(TestUser.homeserver);
|
||||||
await testClientB.login(
|
await testClientB.login(
|
||||||
user: TestUser.username2, password: TestUser.password);
|
identifier: AuthenticationUserIdentifier(user: TestUser.username2),
|
||||||
|
password: TestUser.password);
|
||||||
assert(testClientB.encryptionEnabled);
|
assert(testClientB.encryptionEnabled);
|
||||||
|
|
||||||
Logs().i('++++ (Alice) Leave all rooms ++++');
|
Logs().i('++++ (Alice) Leave all rooms ++++');
|
||||||
|
|
@ -218,7 +220,8 @@ void test() async {
|
||||||
var testClientC = Client('TestClientC', databaseBuilder: getDatabase);
|
var testClientC = Client('TestClientC', databaseBuilder: getDatabase);
|
||||||
await testClientC.checkHomeserver(TestUser.homeserver);
|
await testClientC.checkHomeserver(TestUser.homeserver);
|
||||||
await testClientC.login(
|
await testClientC.login(
|
||||||
user: TestUser.username2, password: TestUser.password);
|
identifier: AuthenticationUserIdentifier(user: TestUser.username2),
|
||||||
|
password: TestUser.password);
|
||||||
await Future.delayed(Duration(seconds: 3));
|
await Future.delayed(Duration(seconds: 3));
|
||||||
|
|
||||||
Logs().i("++++ (Alice) Send again encrypted message: '$testMessage4' ++++");
|
Logs().i("++++ (Alice) Send again encrypted message: '$testMessage4' ++++");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue