diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b324a26a..d5294662 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,7 +19,7 @@ code_analyze: image: cirrusci/flutter dependencies: [] script: - - flutter format lib/ test/ test_driver/ --set-exit-if-changed + - flutter format lib/ test/ --set-exit-if-changed - flutter analyze build_api_doc: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1d9171e7..bdbe67d9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,4 +34,4 @@ flutter format lib/**/*/*.dart - Don't repeat yourself! Use local variables, functions, classes. - Write tests for new classes, functions and widgets. - Keep it simple stupid: https://en.wikipedia.org/wiki/KISS_principle -- Describe all of your classes, methods and attributes using **dartdoc** comments. Read this for more informations: https://dart.dev/guides/language/effective-dart/documentation \ No newline at end of file +- Describe all of your classes, methods and attributes using **dartdoc** comments. Read this for more information: https://dart.dev/guides/language/effective-dart/documentation \ No newline at end of file diff --git a/lib/matrix_api_lite.dart b/lib/matrix_api_lite.dart index 9264103e..f44af1ea 100644 --- a/lib/matrix_api_lite.dart +++ b/lib/matrix_api_lite.dart @@ -55,7 +55,7 @@ export 'src/model/public_rooms_response.dart'; export 'src/model/push_rule_set.dart'; export 'src/model/pusher.dart'; export 'src/model/request_token_response.dart'; -export 'src/model/room_alias_informations.dart'; +export 'src/model/room_alias_information.dart'; export 'src/model/room_keys_info.dart'; export 'src/model/room_keys_keys.dart'; export 'src/model/room_summary.dart'; @@ -72,7 +72,7 @@ export 'src/model/timeline_history_response.dart'; export 'src/model/turn_server_credentials.dart'; export 'src/model/upload_key_signatures_response.dart'; export 'src/model/user_search_result.dart'; -export 'src/model/well_known_informations.dart'; +export 'src/model/well_known_information.dart'; export 'src/model/who_is_info.dart'; export 'src/model/auth/authentication_data.dart'; export 'src/model/auth/authentication_identifier.dart'; diff --git a/lib/src/matrix_api.dart b/lib/src/matrix_api.dart index 5042d01e..037847dc 100644 --- a/lib/src/matrix_api.dart +++ b/lib/src/matrix_api.dart @@ -51,7 +51,7 @@ import 'model/public_rooms_response.dart'; import 'model/push_rule_set.dart'; import 'model/pusher.dart'; import 'model/request_token_response.dart'; -import 'model/room_alias_informations.dart'; +import 'model/room_alias_information.dart'; import 'model/room_keys_info.dart'; import 'model/room_keys_keys.dart'; import 'model/server_capabilities.dart'; @@ -66,7 +66,7 @@ import 'model/timeline_history_response.dart'; import 'model/turn_server_credentials.dart'; import 'model/upload_key_signatures_response.dart'; import 'model/user_search_result.dart'; -import 'model/well_known_informations.dart'; +import 'model/well_known_information.dart'; import 'model/who_is_info.dart'; enum RequestType { GET, POST, PUT, DELETE } @@ -233,14 +233,14 @@ class MatrixApi { /// Gets discovery information about the domain. The file may include additional keys. /// https://matrix.org/docs/spec/client_server/r0.6.0#get-well-known-matrix-client - Future requestWellKnownInformations() async { + Future requestWellKnownInformation() async { var baseUrl = homeserver.toString(); if (baseUrl.endsWith('/')) { baseUrl = baseUrl.substring(0, baseUrl.length - 1); } final response = await httpClient.get('$baseUrl/.well-known/matrix/client'); final rawJson = json.decode(response.body); - return WellKnownInformations.fromJson(rawJson); + return WellKnownInformation.fromJson(rawJson); } Future requestLoginTypes() async { @@ -883,13 +883,12 @@ class MatrixApi { /// Requests that the server resolve a room alias to a room ID. /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-directory-room-roomalias - Future requestRoomAliasInformations( - String alias) async { + Future requestRoomAliasInformation(String alias) async { final response = await request( RequestType.GET, '/client/r0/directory/room/${Uri.encodeComponent(alias)}', ); - return RoomAliasInformations.fromJson(response); + return RoomAliasInformation.fromJson(response); } /// Remove a mapping of room alias to room ID. @@ -1726,7 +1725,7 @@ class MatrixApi { /// Performs a full text search across different categories. /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-search /// Please note: The specification is not 100% clear what it is expecting and sending here. - /// So we stick with pure json until we have more informations. + /// So we stick with pure json until we have more information. Future> globalSearch(Map query) async { return await request( RequestType.POST, diff --git a/lib/src/model/login_response.dart b/lib/src/model/login_response.dart index 20960edb..d64b1cd2 100644 --- a/lib/src/model/login_response.dart +++ b/lib/src/model/login_response.dart @@ -21,21 +21,20 @@ * SOFTWARE. */ -import 'well_known_informations.dart'; +import 'well_known_information.dart'; class LoginResponse { String userId; String accessToken; String deviceId; - WellKnownInformations wellKnownInformations; + WellKnownInformation wellKnownInformation; LoginResponse.fromJson(Map json) { userId = json['user_id']; accessToken = json['access_token']; deviceId = json['device_id']; if (json['well_known'] is Map) { - wellKnownInformations = - WellKnownInformations.fromJson(json['well_known']); + wellKnownInformation = WellKnownInformation.fromJson(json['well_known']); } } @@ -44,8 +43,8 @@ class LoginResponse { if (userId != null) data['user_id'] = userId; if (accessToken != null) data['access_token'] = accessToken; if (deviceId != null) data['device_id'] = deviceId; - if (wellKnownInformations != null) { - data['well_known'] = wellKnownInformations.toJson(); + if (wellKnownInformation != null) { + data['well_known'] = wellKnownInformation.toJson(); } return data; } diff --git a/lib/src/model/room_alias_informations.dart b/lib/src/model/room_alias_information.dart similarity index 93% rename from lib/src/model/room_alias_informations.dart rename to lib/src/model/room_alias_information.dart index 82c40f4e..ae675991 100644 --- a/lib/src/model/room_alias_informations.dart +++ b/lib/src/model/room_alias_information.dart @@ -21,11 +21,11 @@ * SOFTWARE. */ -class RoomAliasInformations { +class RoomAliasInformation { String roomId; List servers; - RoomAliasInformations.fromJson(Map json) { + RoomAliasInformation.fromJson(Map json) { roomId = json['room_id']; servers = json['servers'].cast(); } diff --git a/lib/src/model/well_known_informations.dart b/lib/src/model/well_known_information.dart similarity index 65% rename from lib/src/model/well_known_informations.dart rename to lib/src/model/well_known_information.dart index 9978c237..631ef698 100644 --- a/lib/src/model/well_known_informations.dart +++ b/lib/src/model/well_known_information.dart @@ -21,25 +21,34 @@ * SOFTWARE. */ -class WellKnownInformations { +import '../utils/try_get_map_extension.dart'; + +class WellKnownInformation { MHomeserver mHomeserver; MHomeserver mIdentityServer; Map content; - WellKnownInformations.fromJson(Map json) { + WellKnownInformation.fromJson(Map json) { content = json; - mHomeserver = json['m.homeserver'] != null - ? MHomeserver.fromJson(json['m.homeserver']) - : null; - mIdentityServer = json['m.identity_server'] != null - ? MHomeserver.fromJson(json['m.identity_server']) - : null; + final mHomeserverMap = json.tryGetMap('m.homeserver'); + if (mHomeserverMap != null) { + mHomeserver = MHomeserver.fromJson(mHomeserverMap); + } + final mIdentityServerMap = + json.tryGetMap('m.identity_server'); + if (mIdentityServerMap != null) { + mIdentityServer = MHomeserver.fromJson(mIdentityServerMap); + } } Map toJson() { final data = content; - data['m.homeserver'] = mHomeserver.toJson(); - data['m.identity_server'] = mIdentityServer.toJson(); + if (mHomeserver != null) { + data['m.homeserver'] = mHomeserver.toJson(); + } + if (mIdentityServer != null) { + data['m.identity_server'] = mIdentityServer.toJson(); + } return data; } } @@ -48,12 +57,12 @@ class MHomeserver { String baseUrl; MHomeserver.fromJson(Map json) { - baseUrl = json['base_url']; + baseUrl = json.tryGet('base_url'); } Map toJson() { final data = {}; - data['base_url'] = baseUrl; + if (baseUrl != null) data['base_url'] = baseUrl; return data; } } diff --git a/test/matrix_api_test.dart b/test/matrix_api_test.dart index be00af9f..c52b0778 100644 --- a/test/matrix_api_test.dart +++ b/test/matrix_api_test.dart @@ -129,13 +129,13 @@ void main() { supportedVersions.toJson()); matrixApi.homeserver = null; }); - test('getWellKnownInformations', () async { + test('getWellKnownInformation', () async { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); - final wellKnownInformations = - await matrixApi.requestWellKnownInformations(); - expect(wellKnownInformations.mHomeserver.baseUrl, + final wellKnownInformation = + await matrixApi.requestWellKnownInformation(); + expect(wellKnownInformation.mHomeserver.baseUrl, 'https://fakeserver.notexisting'); - expect(wellKnownInformations.toJson(), { + expect(wellKnownInformation.toJson(), { 'm.homeserver': {'base_url': 'https://fakeserver.notexisting'}, 'm.identity_server': { 'base_url': 'https://identity.fakeserver.notexisting' @@ -654,19 +654,18 @@ void main() { matrixApi.homeserver = matrixApi.accessToken = null; }); - test('requestRoomAliasInformations', () async { + test('requestRoomAliasInformation', () async { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; - final roomAliasInformations = - await matrixApi.requestRoomAliasInformations( + final roomAliasInformation = await matrixApi.requestRoomAliasInformation( '#testalias:example.com', ); expect( FakeMatrixApi.api['GET'] ['/client/r0/directory/room/%23testalias%3Aexample.com']({}), - roomAliasInformations.toJson()); + roomAliasInformation.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; });