From 06d587e64f6bfb13498757dc6f8e09812529ae53 Mon Sep 17 00:00:00 2001 From: Malin Errenst Date: Fri, 9 Jun 2023 09:49:24 +0200 Subject: [PATCH] refactor: Changed Map to Map - contains breaking changes because some type casts will be needed in Matrix SDK --- lib/fake_matrix_api.dart | 210 +++++++++--------- lib/src/matrix_api.dart | 14 +- lib/src/model/auth/authentication_data.dart | 6 +- .../model/auth/authentication_identifier.dart | 8 +- .../model/auth/authentication_password.dart | 6 +- .../auth/authentication_phone_identifier.dart | 4 +- .../model/auth/authentication_recaptcha.dart | 4 +- ...authentication_third_party_identifier.dart | 4 +- .../auth/authentication_three_pid_creds.dart | 12 +- lib/src/model/auth/authentication_token.dart | 4 +- .../auth/authentication_user_identifier.dart | 4 +- lib/src/model/basic_event.dart | 10 +- lib/src/model/basic_event_with_sender.dart | 6 +- lib/src/model/basic_room_event.dart | 6 +- lib/src/model/children_state.dart | 6 +- .../events/forwarded_room_key_content.dart | 4 +- lib/src/model/events/image_pack_content.dart | 32 +-- .../model/events/olm_plaintext_payload.dart | 8 +- .../model/events/room_encrypted_content.dart | 16 +- .../model/events/room_encryption_content.dart | 6 +- lib/src/model/events/room_key_content.dart | 6 +- .../events/room_key_request_content.dart | 14 +- .../secret_storage_default_key_content.dart | 6 +- .../events/secret_storage_key_content.dart | 14 +- lib/src/model/events/tombstone_content.dart | 6 +- lib/src/model/matrix_event.dart | 14 +- lib/src/model/matrix_exception.dart | 12 +- lib/src/model/matrix_keys.dart | 32 +-- lib/src/model/presence.dart | 4 +- lib/src/model/presence_content.dart | 6 +- lib/src/model/room_keys_keys.dart | 26 +-- lib/src/model/room_summary.dart | 6 +- lib/src/model/stripped_state_event.dart | 6 +- lib/src/model/sync_update.dart | 84 +++---- lib/src/utils/map_copy_extension.dart | 8 +- lib/src/utils/try_get_map_extension.dart | 6 +- test/event_content_test.dart | 52 ++--- test/map_copy_extension_test.dart | 18 +- test/matrix_api_test.dart | 26 +-- test/try_get_map_extension_test.dart | 10 +- 40 files changed, 363 insertions(+), 363 deletions(-) diff --git a/lib/fake_matrix_api.dart b/lib/fake_matrix_api.dart index fc32738f..76002f73 100644 --- a/lib/fake_matrix_api.dart +++ b/lib/fake_matrix_api.dart @@ -30,14 +30,14 @@ import 'package:http/testing.dart'; import 'package:matrix_api_lite/matrix_api_lite.dart'; -Map decodeJson(dynamic data) { +Map decodeJson(dynamic data) { if (data is String) { - return json.decode(data) as Map; + return json.decode(data) as Map; } if (data is Map && data.isEmpty) { - return {}; + return {}; } - return data as Map; + return data as Map; } T? tryCast(dynamic object) => object is T ? object : null; @@ -65,13 +65,13 @@ class FakeMatrixApi extends MockClient { final method = request.method; final dynamic data = method == 'GET' ? request.url.queryParameters : request.body; - dynamic res = {}; + dynamic res = {}; var statusCode = 200; //print('\$method request to $action with Data: $data'); // Sync requests with timeout - if (data is Map && data['timeout'] is String) { + if (data is Map && data['timeout'] is String) { await Future.delayed(Duration(seconds: 5)); } @@ -92,7 +92,7 @@ class FakeMatrixApi extends MockClient { } } else if (method == 'PUT' && action.contains('/client/v3/sendToDevice/')) { - res = {}; + res = {}; } else if (method == 'GET' && action.contains('/client/v3/rooms/') && action.contains('/state/m.room.member/')) { @@ -116,7 +116,7 @@ class FakeMatrixApi extends MockClient { return Response.bytes(utf8.encode(json.encode(res)), statusCode); }); - static Map messagesResponse = { + static Map messagesResponse = { 'start': 't47429-4392820_219380_26003_2265', 'end': 't47409-4357353_219380_26003_2265', 'chunk': [ @@ -172,10 +172,10 @@ class FakeMatrixApi extends MockClient { 'unsigned': {'age': 1234} } ], - 'state': >[], + 'state': >[], }; - static Map syncResponse = { + static Map syncResponse = { 'next_batch': Random().nextDouble().toString(), 'rooms': { 'join': { @@ -394,7 +394,7 @@ class FakeMatrixApi extends MockClient { 'override': [ { 'actions': ['dont_notify'], - 'conditions': >[], + 'conditions': >[], 'default': true, 'enabled': false, 'rule_id': '.m.rule.master' @@ -428,7 +428,7 @@ class FakeMatrixApi extends MockClient { 'rule_id': '!localpart:server.abc' } ], - 'sender': >[], + 'sender': >[], 'underride': [ { 'actions': [ @@ -676,14 +676,14 @@ class FakeMatrixApi extends MockClient { 'device_one_time_keys_count': {'curve25519': 10, 'signed_curve25519': 20}, }; - static Map archiveSyncResponse = { + static Map archiveSyncResponse = { 'next_batch': Random().nextDouble().toString(), - 'presence': {'events': >[]}, - 'account_data': {'events': >[]}, - 'to_device': {'events': >[]}, + 'presence': {'events': >[]}, + 'account_data': {'events': >[]}, + 'to_device': {'events': >[]}, 'rooms': { - 'join': {}, - 'invite': {}, + 'join': {}, + 'invite': {}, 'leave': { '!5345234234:example.com': { 'timeline': { @@ -728,7 +728,7 @@ class FakeMatrixApi extends MockClient { }, }, '!5345234235:example.com': { - 'timeline': {'events': >[]}, + 'timeline': {'events': >[]}, 'state': { 'events': [ { @@ -748,7 +748,7 @@ class FakeMatrixApi extends MockClient { } }; - static Map spaceHierarchyResponse = { + static Map spaceHierarchyResponse = { 'rooms': [ { 'room_id': '!gPxZhKUssFZKZcoCKY:neko.dev', @@ -864,7 +864,7 @@ class FakeMatrixApi extends MockClient { 'join_rule': 'public', 'world_readable': true, 'guest_can_join': true, - 'children_state': >[] + 'children_state': >[] }, { 'room_id': '!aZUzMIEZvEwnDquxLf:neko.dev', @@ -877,7 +877,7 @@ class FakeMatrixApi extends MockClient { 'join_rule': 'public', 'world_readable': true, 'guest_can_join': true, - 'children_state': >[] + 'children_state': >[] }, { 'room_id': '!aRzRZBvOAkHMcEjAPS:libera.chat', @@ -889,7 +889,7 @@ class FakeMatrixApi extends MockClient { 'join_rule': 'public', 'world_readable': false, 'guest_can_join': false, - 'children_state': >[] + 'children_state': >[] }, { 'room_id': '!DXsRRxkqqDhDkAyXfL:matrix.org', @@ -902,7 +902,7 @@ class FakeMatrixApi extends MockClient { 'join_rule': 'public', 'world_readable': false, 'guest_can_join': false, - 'children_state': >[] + 'children_state': >[] }, { 'room_id': '!tbCRpmsMiwMBlIThOd:matrix.org', @@ -914,7 +914,7 @@ class FakeMatrixApi extends MockClient { 'join_rule': 'public', 'world_readable': false, 'guest_can_join': false, - 'children_state': >[] + 'children_state': >[] }, { 'room_id': '!LPpmvMsEgDwuSuHSpM:matrix.org', @@ -926,7 +926,7 @@ class FakeMatrixApi extends MockClient { 'join_rule': 'public', 'world_readable': true, 'guest_can_join': true, - 'children_state': >[] + 'children_state': >[] }, { 'room_id': '!prlZxmnmAGuCYHUNSw:neko.dev', @@ -939,7 +939,7 @@ class FakeMatrixApi extends MockClient { 'join_rule': 'public', 'world_readable': true, 'guest_can_join': false, - 'children_state': >[] + 'children_state': >[] }, { 'room_id': '!ooHixUOgoLVUjCSMZC:matrix.org', @@ -951,12 +951,12 @@ class FakeMatrixApi extends MockClient { 'join_rule': 'public', 'world_readable': true, 'guest_can_join': true, - 'children_state': >[] + 'children_state': >[] } ] }; - static final Map> api = { + static final Map> api = { 'GET': { '/path/to/auth/error': (var req) => { 'errcode': 'M_FORBIDDEN', @@ -983,7 +983,7 @@ class FakeMatrixApi extends MockClient { 'tags': { 'm.favourite': {'order': 0.1}, 'u.Work': {'order': 0.7}, - 'u.Customers': {}, + 'u.Customers': {}, } }, '/client/v3/events?from=1234&timeout=10&room_id=%211234': (var req) => { @@ -1093,7 +1093,7 @@ class FakeMatrixApi extends MockClient { 'network_id': 'gitter', 'desc': 'Gitter', 'icon': 'mxc://example.org/zXyWvUt', - 'fields': {} + 'fields': {} } ] } @@ -1611,7 +1611,7 @@ class FakeMatrixApi extends MockClient { 'override': [ { 'actions': ['dont_notify'], - 'conditions': >[], + 'conditions': >[], 'default': true, 'enabled': false, 'rule_id': '.m.rule.master' @@ -1630,8 +1630,8 @@ class FakeMatrixApi extends MockClient { 'rule_id': '.m.rule.suppress_notices' } ], - 'room': >[], - 'sender': >[], + 'room': >[], + 'sender': >[], 'underride': [ { 'actions': [ @@ -1781,7 +1781,7 @@ class FakeMatrixApi extends MockClient { 'algorithm': AlgorithmTypes.megolmBackupV1Curve25519AesSha2, 'auth_data': { 'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM', - 'signatures': {}, + 'signatures': {}, }, 'count': 0, 'etag': '0', @@ -1840,15 +1840,15 @@ class FakeMatrixApi extends MockClient { (var req) => spaceHierarchyResponse, }, 'POST': { - '/client/v3/delete_devices': (var req) => {}, - '/client/v3/account/3pid/add': (var req) => {}, - '/client/v3/account/3pid/bind': (var req) => {}, + '/client/v3/delete_devices': (var req) => {}, + '/client/v3/account/3pid/add': (var req) => {}, + '/client/v3/account/3pid/bind': (var req) => {}, '/client/v3/account/3pid/delete': (var req) => {'id_server_unbind_result': 'success'}, '/client/v3/account/3pid/unbind': (var req) => {'id_server_unbind_result': 'success'}, - '/client/v3/account/password': (var req) => {}, - '/client/v3/rooms/1234/report/1234': (var req) => {}, + '/client/v3/account/password': (var req) => {}, + '/client/v3/rooms/1234/report/1234': (var req) => {}, '/client/v3/search': (var req) => { 'search_categories': { 'room_events': { @@ -1924,9 +1924,9 @@ class FakeMatrixApi extends MockClient { 'submit_url': 'https://example.org/path/to/submitToken' }, '/client/v3/rooms/!localpart%3Aexample.com/receipt/m.read/%241234%3Aexample.com': - (var req) => {}, + (var req) => {}, '/client/v3/rooms/!localpart%3Aexample.com/read_markers': (var req) => - {}, + {}, '/client/v3/user/${Uri.encodeComponent('alice@example.com')}/filter': (var req) => {'filter_id': '1234'}, '/client/v3/publicRooms?server=example.com': (var req) => { @@ -1948,11 +1948,11 @@ class FakeMatrixApi extends MockClient { }, '/client/v3/keys/claim': (dynamic req) { final request = decodeJson(req)["one_time_keys"]; - final keys = (request is Map) - ? request["one_time_keys"] as Map? + final keys = (request is Map) + ? request["one_time_keys"] as Map? : null; return { - 'failures': {}, + 'failures': {}, 'one_time_keys': { if (keys?['@alice:example.com'] != null) '@alice:example.com': { @@ -1986,19 +1986,19 @@ class FakeMatrixApi extends MockClient { }; }, '/client/v3/rooms/!localpart%3Aexample.com/invite': (var req) => - {}, + {}, '/client/v3/rooms/!localpart%3Aexample.com/leave': (var req) => - {}, + {}, '/client/v3/rooms/!localpart%3Aexample.com/forget': (var req) => - {}, + {}, '/client/v3/rooms/!localpart%3Aserver.abc/kick': (var req) => - {}, + {}, '/client/v3/rooms/!localpart%3Aexample.com/kick': (var req) => - {}, + {}, '/client/v3/rooms/!localpart%3Aexample.com/ban': (var req) => - {}, + {}, '/client/v3/rooms/!localpart%3Aexample.com/unban': (var req) => - {}, + {}, '/client/v3/rooms/!localpart%3Aexample.com/join': (var req) => {'room_id': '!localpart:example.com'}, '/client/v3/join/!localpart%3Aexample.com?server_name=example.com&server_name=example.abc': @@ -2006,7 +2006,7 @@ class FakeMatrixApi extends MockClient { '/client/v3/keys/upload': (var req) => { 'one_time_key_counts': { 'curve25519': 10, - 'signed_curve25519': tryCast>>( + 'signed_curve25519': tryCast>>( decodeJson(req))?['one_time_keys'] ?.keys .length ?? @@ -2014,7 +2014,7 @@ class FakeMatrixApi extends MockClient { } }, '/client/v3/keys/query': (var req) => { - 'failures': {}, + 'failures': {}, 'device_keys': { '@alice:example.com': { 'JLAFKJWSCS': { @@ -2136,7 +2136,7 @@ class FakeMatrixApi extends MockClient { 'ed25519:82mAXjsmbTbrE6zyShpR869jnrANO75H8nYY0nDLoJ8': '82mAXjsmbTbrE6zyShpR869jnrANO75H8nYY0nDLoJ8', }, - 'signatures': {}, + 'signatures': {}, }, '@othertest:fakeServer.notExisting': { 'user_id': '@othertest:fakeServer.notExisting', @@ -2144,7 +2144,7 @@ class FakeMatrixApi extends MockClient { 'keys': { 'ed25519:master': 'master', }, - 'signatures': {}, + 'signatures': {}, }, }, 'self_signing_keys': { @@ -2168,7 +2168,7 @@ class FakeMatrixApi extends MockClient { 'keys': { 'ed25519:self_signing': 'self_signing', }, - 'signatures': {}, + 'signatures': {}, }, }, 'user_signing_keys': { @@ -2192,7 +2192,7 @@ class FakeMatrixApi extends MockClient { 'keys': { 'ed25519:user_signing': 'user_signing', }, - 'signatures': {}, + 'signatures': {}, }, }, }, @@ -2232,64 +2232,64 @@ class FakeMatrixApi extends MockClient { }, '/media/v3/upload?filename=file.jpeg': (var req) => {'content_uri': 'mxc://example.com/AQwafuaFswefuhsfAFAgsw'}, - '/client/v3/logout': (var reqI) => {}, - '/client/v3/pushers/set': (var reqI) => {}, + '/client/v3/logout': (var reqI) => {}, + '/client/v3/pushers/set': (var reqI) => {}, '/client/v3/join/1234': (var reqI) => {'room_id': '1234'}, - '/client/v3/logout/all': (var reqI) => {}, + '/client/v3/logout/all': (var reqI) => {}, '/client/v3/createRoom': (var reqI) => { 'room_id': '!1234:fakeServer.notExisting', }, '/client/v3/rooms/!localpart%3Aserver.abc/read_markers': (var reqI) => - {}, + {}, '/client/v3/rooms/!localpart:server.abc/kick': (var reqI) => - {}, + {}, '/client/v3/rooms/!localpart%3Aserver.abc/ban': (var reqI) => - {}, + {}, '/client/v3/rooms/!localpart%3Aserver.abc/unban': (var reqI) => - {}, + {}, '/client/v3/rooms/!localpart%3Aserver.abc/invite': (var reqI) => - {}, + {}, '/client/v3/keys/device_signing/upload': (var reqI) { - return {}; + return {}; }, '/client/v3/keys/signatures/upload': (var reqI) => - {'failures': {}}, + {'failures': {}}, '/client/v3/room_keys/version': (var reqI) => {'version': '5'}, }, 'PUT': { '/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.ignored_user_list': - (var req) => {}, + (var req) => {}, '/client/v3/presence/${Uri.encodeComponent('@alice:example.com')}/status': - (var req) => {}, + (var req) => {}, '/client/v3/pushrules/global/content/nocake/enabled': (var req) => - {}, + {}, '/client/v3/pushrules/global/content/nocake/actions': (var req) => - {}, + {}, '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.history_visibility': - (var req) => {}, + (var req) => {}, '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.join_rules': - (var req) => {}, + (var req) => {}, '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.guest_access': - (var req) => {}, + (var req) => {}, '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.invite/1234': - (var req) => {}, + (var req) => {}, '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.answer/1234': - (var req) => {}, + (var req) => {}, '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.candidates/1234': - (var req) => {}, + (var req) => {}, '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.hangup/1234': - (var req) => {}, + (var req) => {}, '/client/v3/rooms/!1234%3Aexample.com/redact/1143273582443PhrSn%3Aexample.org/1234': (var req) => {'event_id': '1234'}, '/client/v3/pushrules/global/room/!localpart%3Aserver.abc': (var req) => - {}, + {}, '/client/v3/pushrules/global/override/.m.rule.master/enabled': - (var req) => {}, + (var req) => {}, '/client/v3/pushrules/global/content/nocake?before=1&after=2': - (var req) => {}, - '/client/v3/devices/QBUAZIFURK': (var req) => {}, + (var req) => {}, + '/client/v3/devices/QBUAZIFURK': (var req) => {}, '/client/v3/directory/room/%23testalias%3Aexample.com': (var reqI) => - {}, + {}, '/client/v3/rooms/!localpart%3Aserver.abc/send/m.room.message/testtxid': (var reqI) => { 'event_id': '\$event${FakeMatrixApi.eventCounter++}', @@ -2299,7 +2299,7 @@ class FakeMatrixApi extends MockClient { 'event_id': '\$event${FakeMatrixApi.eventCounter++}', }, '/client/v3/rooms/!localpart%3Aexample.com/typing/%40alice%3Aexample.com': - (var req) => {}, + (var req) => {}, '/client/v3/rooms/!1234%3Aexample.com/send/m.room.message/1234': (var reqI) => { 'event_id': '\$event${FakeMatrixApi.eventCounter++}', @@ -2309,27 +2309,27 @@ class FakeMatrixApi extends MockClient { 'event_id': '\$event${FakeMatrixApi.eventCounter++}', }, '/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/tags/m.favourite': - (var req) => {}, + (var req) => {}, '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags/testtag': - (var req) => {}, + (var req) => {}, '/client/v3/user/%40alice%3Aexample.com/account_data/test.account.data': - (var req) => {}, + (var req) => {}, '/client/v3/user/%40test%3AfakeServer.notExisting/account_data/best%20animal': - (var req) => {}, + (var req) => {}, '/client/v3/user/%40alice%3Aexample.com/rooms/1234/account_data/test.account.data': - (var req) => {}, + (var req) => {}, '/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/account_data/com.famedly.marked_unread': - (var req) => {}, + (var req) => {}, '/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct': - (var req) => {}, + (var req) => {}, '/client/v3/user/%40othertest%3AfakeServer.notExisting/account_data/m.direct': - (var req) => {}, + (var req) => {}, '/client/v3/profile/%40alice%3Aexample.com/displayname': (var reqI) => - {}, + {}, '/client/v3/profile/%40alice%3Aexample.com/avatar_url': (var reqI) => - {}, + {}, '/client/v3/profile/%40test%3AfakeServer.notExisting/avatar_url': - (var reqI) => {}, + (var reqI) => {}, '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.encryption': (var reqI) => {'event_id': 'YUwRidLecu:example.com'}, '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.avatar': @@ -2355,8 +2355,8 @@ class FakeMatrixApi extends MockClient { 'event_id': '42', }, '/client/v3/directory/list/room/!localpart%3Aexample.com': (var req) => - {}, - '/client/v3/room_keys/version/5': (var req) => {}, + {}, + '/client/v3/room_keys/version/5': (var req) => {}, '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5': (var req) => { 'etag': 'asdf', @@ -2374,18 +2374,18 @@ class FakeMatrixApi extends MockClient { }, 'DELETE': { '/unknown/token': (var req) => {'errcode': 'M_UNKNOWN_TOKEN'}, - '/client/v3/devices/QBUAZIFURK': (var req) => {}, + '/client/v3/devices/QBUAZIFURK': (var req) => {}, '/client/v3/directory/room/%23testalias%3Aexample.com': (var reqI) => - {}, + {}, '/client/v3/pushrules/global/content/nocake': (var req) => - {}, + {}, '/client/v3/pushrules/global/override/!localpart%3Aserver.abc': - (var req) => {}, + (var req) => {}, '/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/tags/m.favourite': - (var req) => {}, + (var req) => {}, '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags/testtag': - (var req) => {}, - '/client/v3/room_keys/version/5': (var req) => {}, + (var req) => {}, + '/client/v3/room_keys/version/5': (var req) => {}, '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5': (var req) => { 'etag': 'asdf', diff --git a/lib/src/matrix_api.dart b/lib/src/matrix_api.dart index 772fc58d..605b4932 100644 --- a/lib/src/matrix_api.dart +++ b/lib/src/matrix_api.dart @@ -48,7 +48,7 @@ class MatrixApi extends Api { Never unexpectedResponse(http.BaseResponse response, Uint8List body) { if (response.statusCode >= 400 && response.statusCode < 500) { final resp = json.decode(utf8.decode(body)); - if (resp is Map) { + if (resp is Map) { throw MatrixException.fromJson(resp); } } @@ -82,12 +82,12 @@ class MatrixApi extends Api { /// ); /// ``` /// - Future> request( + Future> request( RequestType type, String action, { dynamic data = '', String contentType = 'application/json', - Map? query, + Map? query, }) async { if (homeserver == null) { throw ('No homeserver specified.'); @@ -108,7 +108,7 @@ class MatrixApi extends Api { } late http.Response resp; - Map? jsonResp = {}; + Map? jsonResp = {}; try { switch (type) { case RequestType.GET: @@ -138,7 +138,7 @@ class MatrixApi extends Api { jsonString = '{"chunk":$jsonString}'; } jsonResp = jsonDecode(jsonString) - as Map?; // May throw FormatException + as Map?; // May throw FormatException } catch (e, s) { throw MatrixConnectionException(e, s); } @@ -153,8 +153,8 @@ class MatrixApi extends Api { /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-query Future> uploadKeys( {MatrixDeviceKeys? deviceKeys, - Map? oneTimeKeys, - Map? fallbackKeys}) async { + Map? oneTimeKeys, + Map? fallbackKeys}) async { final response = await request( RequestType.POST, '/client/v3/keys/upload', diff --git a/lib/src/model/auth/authentication_data.dart b/lib/src/model/auth/authentication_data.dart index a01faafc..27eae960 100644 --- a/lib/src/model/auth/authentication_data.dart +++ b/lib/src/model/auth/authentication_data.dart @@ -29,12 +29,12 @@ class AuthenticationData { AuthenticationData({this.type, this.session}); - AuthenticationData.fromJson(Map json) + AuthenticationData.fromJson(Map json) : type = json['type'] as String?, session = json['session'] as String?; - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (type != null) data['type'] = type; if (session != null) data['session'] = session; return data; diff --git a/lib/src/model/auth/authentication_identifier.dart b/lib/src/model/auth/authentication_identifier.dart index e02cf840..06ead12d 100644 --- a/lib/src/model/auth/authentication_identifier.dart +++ b/lib/src/model/auth/authentication_identifier.dart @@ -31,10 +31,10 @@ class AuthenticationIdentifier { AuthenticationIdentifier({required this.type}); - AuthenticationIdentifier.fromJson(Map json) + AuthenticationIdentifier.fromJson(Map json) : type = json['type'] as String; - factory AuthenticationIdentifier.subFromJson(Map json) { + factory AuthenticationIdentifier.subFromJson(Map json) { switch (json['type']) { case AuthenticationIdentifierTypes.userId: return AuthenticationUserIdentifier.fromJson(json); @@ -47,8 +47,8 @@ class AuthenticationIdentifier { } } - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['type'] = type; return data; } diff --git a/lib/src/model/auth/authentication_password.dart b/lib/src/model/auth/authentication_password.dart index 4135a535..a9033445 100644 --- a/lib/src/model/auth/authentication_password.dart +++ b/lib/src/model/auth/authentication_password.dart @@ -40,14 +40,14 @@ class AuthenticationPassword extends AuthenticationData { session: session, ); - AuthenticationPassword.fromJson(Map json) + AuthenticationPassword.fromJson(Map json) : password = json['password'] as String, identifier = AuthenticationIdentifier.subFromJson( - json['identifier'] as Map), + json['identifier'] as Map), super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['password'] = password; data['identifier'] = identifier.toJson(); diff --git a/lib/src/model/auth/authentication_phone_identifier.dart b/lib/src/model/auth/authentication_phone_identifier.dart index 0c79d7d3..e12b510e 100644 --- a/lib/src/model/auth/authentication_phone_identifier.dart +++ b/lib/src/model/auth/authentication_phone_identifier.dart @@ -31,13 +31,13 @@ class AuthenticationPhoneIdentifier extends AuthenticationIdentifier { AuthenticationPhoneIdentifier({required this.country, required this.phone}) : super(type: AuthenticationIdentifierTypes.phone); - AuthenticationPhoneIdentifier.fromJson(Map json) + AuthenticationPhoneIdentifier.fromJson(Map json) : country = json['country'] as String, phone = json['phone'] as String, super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['country'] = country; data['phone'] = phone; diff --git a/lib/src/model/auth/authentication_recaptcha.dart b/lib/src/model/auth/authentication_recaptcha.dart index 5244e16d..33009b31 100644 --- a/lib/src/model/auth/authentication_recaptcha.dart +++ b/lib/src/model/auth/authentication_recaptcha.dart @@ -33,12 +33,12 @@ class AuthenticationRecaptcha extends AuthenticationData { session: session, ); - AuthenticationRecaptcha.fromJson(Map json) + AuthenticationRecaptcha.fromJson(Map json) : response = json['response'] as String, super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['response'] = response; return data; diff --git a/lib/src/model/auth/authentication_third_party_identifier.dart b/lib/src/model/auth/authentication_third_party_identifier.dart index f40fd98b..55bc8c40 100644 --- a/lib/src/model/auth/authentication_third_party_identifier.dart +++ b/lib/src/model/auth/authentication_third_party_identifier.dart @@ -32,13 +32,13 @@ class AuthenticationThirdPartyIdentifier extends AuthenticationIdentifier { {required this.medium, required this.address}) : super(type: AuthenticationIdentifierTypes.thirdParty); - AuthenticationThirdPartyIdentifier.fromJson(Map json) + AuthenticationThirdPartyIdentifier.fromJson(Map json) : medium = json['medium'] as String, address = json['address'] as String, super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['medium'] = medium; data['address'] = address; diff --git a/lib/src/model/auth/authentication_three_pid_creds.dart b/lib/src/model/auth/authentication_three_pid_creds.dart index a1a119de..89e5784a 100644 --- a/lib/src/model/auth/authentication_three_pid_creds.dart +++ b/lib/src/model/auth/authentication_three_pid_creds.dart @@ -37,16 +37,16 @@ class AuthenticationThreePidCreds extends AuthenticationData { session: session, ); - AuthenticationThreePidCreds.fromJson(Map json) + AuthenticationThreePidCreds.fromJson(Map json) : super.fromJson(json) { final creds = json['threepid_creds']; - if (creds is Map) { + if (creds is Map) { threepidCreds = ThreepidCreds.fromJson(creds); } } @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['threepid_creds'] = threepidCreds.toJson(); return data; @@ -65,14 +65,14 @@ class ThreepidCreds { this.idServer, this.idAccessToken}); - ThreepidCreds.fromJson(Map json) + ThreepidCreds.fromJson(Map json) : sid = json['sid'] as String, clientSecret = json['client_secret'] as String, idServer = json['id_server'] as String?, idAccessToken = json['id_access_token'] as String?; - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['sid'] = sid; data['client_secret'] = clientSecret; if (idServer != null) data['id_server'] = idServer; diff --git a/lib/src/model/auth/authentication_token.dart b/lib/src/model/auth/authentication_token.dart index 7c86bd45..fc375f5d 100644 --- a/lib/src/model/auth/authentication_token.dart +++ b/lib/src/model/auth/authentication_token.dart @@ -36,13 +36,13 @@ class AuthenticationToken extends AuthenticationData { session: session, ); - AuthenticationToken.fromJson(Map json) + AuthenticationToken.fromJson(Map json) : token = json['token'] as String, txnId = json['txn_id'] as String?, super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['token'] = token; data['txn_id'] = txnId; diff --git a/lib/src/model/auth/authentication_user_identifier.dart b/lib/src/model/auth/authentication_user_identifier.dart index 1736c47a..232cafe6 100644 --- a/lib/src/model/auth/authentication_user_identifier.dart +++ b/lib/src/model/auth/authentication_user_identifier.dart @@ -30,12 +30,12 @@ class AuthenticationUserIdentifier extends AuthenticationIdentifier { AuthenticationUserIdentifier({required this.user}) : super(type: AuthenticationIdentifierTypes.userId); - AuthenticationUserIdentifier.fromJson(Map json) + AuthenticationUserIdentifier.fromJson(Map json) : user = json['user'] as String, super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['user'] = user; return data; diff --git a/lib/src/model/basic_event.dart b/lib/src/model/basic_event.dart index e91c2e80..9700fc02 100644 --- a/lib/src/model/basic_event.dart +++ b/lib/src/model/basic_event.dart @@ -25,19 +25,19 @@ import '../utils/map_copy_extension.dart'; class BasicEvent { String type; - Map content; + Map content; BasicEvent({ required this.type, required this.content, }); - BasicEvent.fromJson(Map json) + BasicEvent.fromJson(Map json) : type = json['type'] as String, - content = (json['content'] as Map).copy(); + content = (json['content'] as Map).copy(); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['type'] = type; data['content'] = content; return data; diff --git a/lib/src/model/basic_event_with_sender.dart b/lib/src/model/basic_event_with_sender.dart index cb3a6486..7da96bf8 100644 --- a/lib/src/model/basic_event_with_sender.dart +++ b/lib/src/model/basic_event_with_sender.dart @@ -28,16 +28,16 @@ class BasicEventWithSender extends BasicEvent { BasicEventWithSender( {required String type, - required Map content, + required Map content, required this.senderId}) : super(type: type, content: content); - BasicEventWithSender.fromJson(Map json) + BasicEventWithSender.fromJson(Map json) : senderId = json['sender'] as String, super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['sender'] = senderId; return data; diff --git a/lib/src/model/basic_room_event.dart b/lib/src/model/basic_room_event.dart index 1771e2ca..97f242ea 100644 --- a/lib/src/model/basic_room_event.dart +++ b/lib/src/model/basic_room_event.dart @@ -28,19 +28,19 @@ class BasicRoomEvent extends BasicEvent { BasicRoomEvent({ this.roomId, - required Map content, + required Map content, required String type, }) : super( content: content, type: type, ); - BasicRoomEvent.fromJson(Map json) + BasicRoomEvent.fromJson(Map json) : roomId = json['room_id'] as String?, super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); if (roomId != null) data['room_id'] = roomId; return data; diff --git a/lib/src/model/children_state.dart b/lib/src/model/children_state.dart index 03b0688b..f5ae40de 100644 --- a/lib/src/model/children_state.dart +++ b/lib/src/model/children_state.dart @@ -28,7 +28,7 @@ class ChildrenState extends StrippedStateEvent { ChildrenState({ required String type, - required Map content, + required Map content, required String senderId, required String stateKey, required this.originServerTs, @@ -38,13 +38,13 @@ class ChildrenState extends StrippedStateEvent { senderId: senderId, stateKey: stateKey); - ChildrenState.fromJson(Map json) + ChildrenState.fromJson(Map json) : originServerTs = DateTime.fromMillisecondsSinceEpoch( json['origin_server_ts'] as int), super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch; return data; diff --git a/lib/src/model/events/forwarded_room_key_content.dart b/lib/src/model/events/forwarded_room_key_content.dart index 46196692..8fbf4311 100644 --- a/lib/src/model/events/forwarded_room_key_content.dart +++ b/lib/src/model/events/forwarded_room_key_content.dart @@ -35,7 +35,7 @@ class ForwardedRoomKeyContent extends RoomKeyContent { String senderClaimedEd25519Key; List forwardingCurve25519KeyChain; - ForwardedRoomKeyContent.fromJson(Map json) + ForwardedRoomKeyContent.fromJson(Map json) : senderKey = json.tryGet('sender_key', TryGet.required) ?? '', senderClaimedEd25519Key = json.tryGet('sender_claimed_ed25519_key', TryGet.required) ?? '', @@ -45,7 +45,7 @@ class ForwardedRoomKeyContent extends RoomKeyContent { super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['sender_key'] = senderKey; data['sender_claimed_ed25519_key'] = senderClaimedEd25519Key; diff --git a/lib/src/model/events/image_pack_content.dart b/lib/src/model/events/image_pack_content.dart index 4365f0ea..ff465df2 100644 --- a/lib/src/model/events/image_pack_content.dart +++ b/lib/src/model/events/image_pack_content.dart @@ -66,31 +66,31 @@ List imagePackUsageToJson( class ImagePackContent { // we want to preserve potential custom keys in this object - final Map _json; + final Map _json; Map images; ImagePackPackContent pack; ImagePackContent({required this.images, required this.pack}) : _json = {}; - ImagePackContent.fromJson(Map json) + ImagePackContent.fromJson(Map json) : _json = Map.fromEntries(json.entries.where( (e) => !['images', 'pack', 'emoticons', 'short'].contains(e.key))), pack = ImagePackPackContent.fromJson( - json.tryGetMap('pack') ?? {}), - images = json.tryGetMap('images')?.catchMap((k, v) => + json.tryGetMap('pack') ?? {}), + images = json.tryGetMap('images')?.catchMap((k, v) => MapEntry( k, ImagePackImageContent.fromJson( - v as Map))) ?? + v as Map))) ?? // the "emoticons" key needs a small migration on the key, ":string:" --> "string" - json.tryGetMap('emoticons')?.catchMap((k, v) => + json.tryGetMap('emoticons')?.catchMap((k, v) => MapEntry( k.startsWith(':') && k.endsWith(':') ? k.substring(1, k.length - 1) : k, ImagePackImageContent.fromJson( - v as Map))) ?? + v as Map))) ?? // the "short" key was still just a map from shortcode to mxc uri json.tryGetMap('short')?.catchMap((k, v) => MapEntry( @@ -100,7 +100,7 @@ class ImagePackContent { ImagePackImageContent(url: Uri.parse(v)))) ?? {}; - Map toJson() => { + Map toJson() => { ..._json, 'images': images.map((k, v) => MapEntry(k, v.toJson())), 'pack': pack.toJson(), @@ -109,25 +109,25 @@ class ImagePackContent { class ImagePackImageContent { // we want to preserve potential custom keys in this object - final Map _json; + final Map _json; Uri url; String? body; - Map? info; + Map? info; List? usage; ImagePackImageContent({required this.url, this.body, this.info, this.usage}) : _json = {}; - ImagePackImageContent.fromJson(Map json) + ImagePackImageContent.fromJson(Map json) : _json = Map.fromEntries(json.entries .where((e) => !['url', 'body', 'info'].contains(e.key))), url = Uri.parse(json['url'] as String), body = json.tryGet('body'), - info = json.tryGetMap('info'), + info = json.tryGetMap('info'), usage = imagePackUsageFromJson(json.tryGetList('usage')); - Map toJson() { + Map toJson() { return { ...Map.from(_json)..remove('usage'), 'url': url.toString(), @@ -141,7 +141,7 @@ class ImagePackImageContent { class ImagePackPackContent { // we want to preserve potential custom keys in this object - final Map _json; + final Map _json; String? displayName; Uri? avatarUrl; @@ -152,7 +152,7 @@ class ImagePackPackContent { {this.displayName, this.avatarUrl, this.usage, this.attribution}) : _json = {}; - ImagePackPackContent.fromJson(Map json) + ImagePackPackContent.fromJson(Map json) : _json = Map.fromEntries(json.entries.where((e) => !['display_name', 'avatar_url', 'attribution'].contains(e.key))), displayName = json.tryGet('display_name'), @@ -161,7 +161,7 @@ class ImagePackPackContent { usage = imagePackUsageFromJson(json.tryGetList('usage')), attribution = json.tryGet('attribution'); - Map toJson() { + Map toJson() { return { ...Map.from(_json)..remove('usage'), if (displayName != null) 'display_name': displayName, diff --git a/lib/src/model/events/olm_plaintext_payload.dart b/lib/src/model/events/olm_plaintext_payload.dart index fe7e0611..11ec26c7 100644 --- a/lib/src/model/events/olm_plaintext_payload.dart +++ b/lib/src/model/events/olm_plaintext_payload.dart @@ -25,7 +25,7 @@ import '../../utils/try_get_map_extension.dart'; class OlmPlaintextPayload { String? type; - Map? content; + Map? content; String? sender; String? recipient; Map? recipientKeys; @@ -40,7 +40,7 @@ class OlmPlaintextPayload { this.keys, }) : super(); - factory OlmPlaintextPayload.fromJson(Map json) => + factory OlmPlaintextPayload.fromJson(Map json) => OlmPlaintextPayload( sender: json.tryGet('sender', TryGet.required), type: json.tryGet('type', TryGet.required), @@ -50,8 +50,8 @@ class OlmPlaintextPayload { keys: json.tryGetMap('keys', TryGet.required), ); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (type != null) data['type'] = type; if (sender != null) data['sender'] = sender; if (content != null) data['content'] = content; diff --git a/lib/src/model/events/room_encrypted_content.dart b/lib/src/model/events/room_encrypted_content.dart index 7d4ef4b0..c92ed261 100644 --- a/lib/src/model/events/room_encrypted_content.dart +++ b/lib/src/model/events/room_encrypted_content.dart @@ -39,7 +39,7 @@ class RoomEncryptedContent { String? ciphertextMegolm; Map? ciphertextOlm; - RoomEncryptedContent.fromJson(Map json) + RoomEncryptedContent.fromJson(Map json) : algorithm = json.tryGet('algorithm', TryGet.required) ?? '', senderKey = json.tryGet('sender_key', TryGet.required) ?? '', deviceId = json.tryGet('device_id'), @@ -47,12 +47,12 @@ class RoomEncryptedContent { ciphertextMegolm = json.tryGet('ciphertext', TryGet.silent), // filter out invalid/incomplete CiphertextInfos ciphertextOlm = json - .tryGet>('ciphertext', TryGet.silent) + .tryGet>('ciphertext', TryGet.silent) ?.catchMap((k, v) => MapEntry( - k, CiphertextInfo.fromJson(v as Map))); + k, CiphertextInfo.fromJson(v as Map))); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['algorithm'] = algorithm; data['sender_key'] = senderKey; if (deviceId != null) { @@ -80,12 +80,12 @@ class CiphertextInfo { String body; int type; - CiphertextInfo.fromJson(Map json) + CiphertextInfo.fromJson(Map json) : body = json['body'] as String, type = json['type'] as int; - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['body'] = body; data['type'] = type; return data; diff --git a/lib/src/model/events/room_encryption_content.dart b/lib/src/model/events/room_encryption_content.dart index 24262320..15ed3763 100644 --- a/lib/src/model/events/room_encryption_content.dart +++ b/lib/src/model/events/room_encryption_content.dart @@ -34,13 +34,13 @@ class RoomEncryptionContent { int? rotationPeriodMs; int? rotationPeriodMsgs; - RoomEncryptionContent.fromJson(Map json) + RoomEncryptionContent.fromJson(Map json) : algorithm = json.tryGet('algorithm', TryGet.required) ?? '', rotationPeriodMs = json.tryGet('rotation_period_ms'), rotationPeriodMsgs = json.tryGet('rotation_period_msgs'); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['algorithm'] = algorithm; if (rotationPeriodMs != null) { data['rotation_period_ms'] = rotationPeriodMs; diff --git a/lib/src/model/events/room_key_content.dart b/lib/src/model/events/room_key_content.dart index e8c69893..a710523b 100644 --- a/lib/src/model/events/room_key_content.dart +++ b/lib/src/model/events/room_key_content.dart @@ -40,14 +40,14 @@ class RoomKeyContent { required this.sessionId, required this.sessionKey}); - RoomKeyContent.fromJson(Map json) + RoomKeyContent.fromJson(Map json) : algorithm = json.tryGet('algorithm', TryGet.required) ?? '', roomId = json.tryGet('room_id', TryGet.required) ?? '', sessionId = json.tryGet('session_id', TryGet.required) ?? '', sessionKey = json.tryGet('session_key', TryGet.required) ?? ''; - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['algorithm'] = algorithm; data['room_id'] = roomId; data['session_id'] = sessionId; diff --git a/lib/src/model/events/room_key_request_content.dart b/lib/src/model/events/room_key_request_content.dart index bddaeff3..ec6162d4 100644 --- a/lib/src/model/events/room_key_request_content.dart +++ b/lib/src/model/events/room_key_request_content.dart @@ -35,8 +35,8 @@ class RoomKeyRequestContent { String requestingDeviceId; String requestId; - RoomKeyRequestContent.fromJson(Map json) - : body = ((Map? x) => x != null + RoomKeyRequestContent.fromJson(Map json) + : body = ((Map? x) => x != null ? RequestedKeyInfo.fromJson(x) : null)(json.tryGet('body')), action = json.tryGet('action', TryGet.required) ?? '', @@ -44,8 +44,8 @@ class RoomKeyRequestContent { json.tryGet('requesting_device_id', TryGet.required) ?? '', requestId = json.tryGet('request_id', TryGet.required) ?? ''; - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (body != null) data['body'] = body!.toJson(); data['action'] = action; data['requesting_device_id'] = requestingDeviceId; @@ -66,14 +66,14 @@ class RequestedKeyInfo { required this.sessionId, required this.senderKey}); - RequestedKeyInfo.fromJson(Map json) + RequestedKeyInfo.fromJson(Map json) : algorithm = json.tryGet('algorithm', TryGet.required) ?? '', roomId = json.tryGet('room_id', TryGet.required) ?? '', sessionId = json.tryGet('session_id', TryGet.required) ?? '', senderKey = json.tryGet('sender_key', TryGet.required) ?? ''; - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['algorithm'] = algorithm; data['room_id'] = roomId; data['session_id'] = sessionId; diff --git a/lib/src/model/events/secret_storage_default_key_content.dart b/lib/src/model/events/secret_storage_default_key_content.dart index 198f6e7d..7623bcdd 100644 --- a/lib/src/model/events/secret_storage_default_key_content.dart +++ b/lib/src/model/events/secret_storage_default_key_content.dart @@ -35,11 +35,11 @@ class SecretStorageDefaultKeyContent { SecretStorageDefaultKeyContent({required this.key}); - SecretStorageDefaultKeyContent.fromJson(Map json) + SecretStorageDefaultKeyContent.fromJson(Map json) : key = json.tryGet('key', TryGet.required); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (key != null) data['key'] = key; return data; } diff --git a/lib/src/model/events/secret_storage_key_content.dart b/lib/src/model/events/secret_storage_key_content.dart index 5f3529e3..42019615 100644 --- a/lib/src/model/events/secret_storage_key_content.dart +++ b/lib/src/model/events/secret_storage_key_content.dart @@ -37,16 +37,16 @@ class SecretStorageKeyContent { SecretStorageKeyContent(); - SecretStorageKeyContent.fromJson(Map json) - : passphrase = ((Map? x) => x != null + SecretStorageKeyContent.fromJson(Map json) + : passphrase = ((Map? x) => x != null ? PassphraseInfo.fromJson(x) : null)(json.tryGet('passphrase')), iv = json.tryGet('iv'), mac = json.tryGet('mac'), algorithm = json.tryGet('algorithm'); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (passphrase != null) data['passphrase'] = passphrase!.toJson(); if (iv != null) data['iv'] = iv; if (mac != null) data['mac'] = mac; @@ -69,14 +69,14 @@ class PassphraseInfo { required this.iterations, this.bits}); - PassphraseInfo.fromJson(Map json) + PassphraseInfo.fromJson(Map json) : algorithm = json.tryGet('algorithm', TryGet.required), salt = json.tryGet('salt', TryGet.required), iterations = json.tryGet('iterations', TryGet.required), bits = json.tryGet('bits'); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['algorithm'] = algorithm; data['salt'] = salt; data['iterations'] = iterations; diff --git a/lib/src/model/events/tombstone_content.dart b/lib/src/model/events/tombstone_content.dart index 926db2fc..b3dccbec 100644 --- a/lib/src/model/events/tombstone_content.dart +++ b/lib/src/model/events/tombstone_content.dart @@ -33,13 +33,13 @@ class TombstoneContent { String body; String replacementRoom; - TombstoneContent.fromJson(Map json) + TombstoneContent.fromJson(Map json) : body = json.tryGet('body', TryGet.required) ?? '', replacementRoom = json.tryGet('replacement_room', TryGet.required) ?? ''; - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['body'] = body; data['replacement_room'] = replacementRoom; return data; diff --git a/lib/src/model/matrix_event.dart b/lib/src/model/matrix_event.dart index b0ed6ee7..6d3c6cc9 100644 --- a/lib/src/model/matrix_event.dart +++ b/lib/src/model/matrix_event.dart @@ -28,13 +28,13 @@ class MatrixEvent extends StrippedStateEvent { String eventId; String? roomId; DateTime originServerTs; - Map? unsigned; - Map? prevContent; + Map? unsigned; + Map? prevContent; String? redacts; MatrixEvent({ required String type, - required Map content, + required Map content, required String senderId, String? stateKey, required this.eventId, @@ -49,18 +49,18 @@ class MatrixEvent extends StrippedStateEvent { senderId: senderId, stateKey: stateKey); - MatrixEvent.fromJson(Map json) + MatrixEvent.fromJson(Map json) : eventId = json['event_id'] as String, roomId = json['room_id'] as String?, originServerTs = DateTime.fromMillisecondsSinceEpoch( json['origin_server_ts'] as int), - unsigned = (json['unsigned'] as Map?)?.copy(), - prevContent = (json['prev_content'] as Map?)?.copy(), + unsigned = (json['unsigned'] as Map?)?.copy(), + prevContent = (json['prev_content'] as Map?)?.copy(), redacts = json['redacts'] as String?, super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['event_id'] = eventId; data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch; diff --git a/lib/src/model/matrix_exception.dart b/lib/src/model/matrix_exception.dart index 0f20c674..811b1e13 100644 --- a/lib/src/model/matrix_exception.dart +++ b/lib/src/model/matrix_exception.dart @@ -63,7 +63,7 @@ enum MatrixError { /// Represents a special response from the Homeserver for errors. class MatrixException implements Exception { - final Map raw; + final Map raw; /// The unique identifier for this error. String get errcode => @@ -81,9 +81,9 @@ class MatrixException implements Exception { http.Response? response; MatrixException(http.Response this.response) - : raw = json.decode(response.body) as Map; + : raw = json.decode(response.body) as Map; - MatrixException.fromJson(Map content) : raw = content; + MatrixException.fromJson(Map content) : raw = content; @override String toString() => '$errcode: $errorMessage'; @@ -110,7 +110,7 @@ class MatrixException implements Exception { /// doesn't need additional authentication, then this is null. List? get authenticationFlows => raw .tryGet>('flows') - ?.whereType>() + ?.whereType>() .map((flow) => flow['stages']) .whereType>() .map((stages) => @@ -120,8 +120,8 @@ class MatrixException implements Exception { /// This section contains any information that the client will need to know in order to use a given type /// of authentication. For each authentication type presented, that type may be present as a key in this /// dictionary. For example, the public part of an OAuth client ID could be given here. - Map? get authenticationParams => - raw.tryGetMap('params'); + Map? get authenticationParams => + raw.tryGetMap('params'); /// Returns the list of already completed authentication flows from previous requests. List get completedAuthenticationFlows => diff --git a/lib/src/model/matrix_keys.dart b/lib/src/model/matrix_keys.dart index ca25a197..d6a8fde8 100644 --- a/lib/src/model/matrix_keys.dart +++ b/lib/src/model/matrix_keys.dart @@ -30,25 +30,25 @@ abstract class MatrixSignableKey { Map keys; Map>? signatures; - Map? unsigned; + Map? unsigned; MatrixSignableKey(this.userId, this.keys, this.signatures, {this.unsigned}); // This object is used for signing so we need the raw json too - Map? _json; + Map? _json; - MatrixSignableKey.fromJson(Map json) + MatrixSignableKey.fromJson(Map json) : _json = json, userId = json['user_id'] as String, - keys = Map.from(json['keys'] as Map), + keys = Map.from(json['keys'] as Map), // we need to manually copy to ensure that our map is Map> signatures = (() { - final orig = json.tryGetMap('signatures'); + final orig = json.tryGetMap('signatures'); final res = >{}; for (final entry - in (orig?.entries ?? >[])) { + in (orig?.entries ?? >[])) { final deviceSigs = entry.value; - if (deviceSigs is Map) { + if (deviceSigs is Map) { for (final nestedEntry in deviceSigs.entries) { final nestedValue = nestedEntry.value; if (nestedValue is String) { @@ -60,10 +60,10 @@ abstract class MatrixSignableKey { } return res; }()), - unsigned = json.tryGetMap('unsigned')?.copy(); + unsigned = json.tryGetMap('unsigned')?.copy(); - Map toJson() { - final data = _json ?? {}; + Map toJson() { + final data = _json ?? {}; data['user_id'] = userId; data['keys'] = keys; @@ -87,19 +87,19 @@ class MatrixCrossSigningKey extends MatrixSignableKey { this.usage, Map keys, Map> signatures, { - Map? unsigned, + Map? unsigned, }) : super(userId, keys, signatures, unsigned: unsigned); @override String? get identifier => keys.values.first; @override - MatrixCrossSigningKey.fromJson(Map json) + MatrixCrossSigningKey.fromJson(Map json) : usage = json.tryGetList('usage') ?? [], super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['usage'] = usage; return data; @@ -119,20 +119,20 @@ class MatrixDeviceKeys extends MatrixSignableKey { this.algorithms, Map keys, Map> signatures, { - Map? unsigned, + Map? unsigned, }) : super(userId, keys, signatures, unsigned: unsigned); @override String? get identifier => deviceId; @override - MatrixDeviceKeys.fromJson(Map json) + MatrixDeviceKeys.fromJson(Map json) : algorithms = json.tryGetList('algorithms') ?? [], deviceId = json['device_id'] as String, super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['device_id'] = deviceId; data['algorithms'] = algorithms; diff --git a/lib/src/model/presence.dart b/lib/src/model/presence.dart index 37b33f3d..90e42cc5 100644 --- a/lib/src/model/presence.dart +++ b/lib/src/model/presence.dart @@ -27,8 +27,8 @@ import 'presence_content.dart'; class Presence extends BasicEventWithSender { PresenceContent presence; - Presence.fromJson(Map json) + Presence.fromJson(Map json) : presence = - PresenceContent.fromJson(json['content'] as Map), + PresenceContent.fromJson(json['content'] as Map), super.fromJson(json); } diff --git a/lib/src/model/presence_content.dart b/lib/src/model/presence_content.dart index 8f80851e..25665960 100644 --- a/lib/src/model/presence_content.dart +++ b/lib/src/model/presence_content.dart @@ -29,15 +29,15 @@ class PresenceContent { String? statusMsg; bool? currentlyActive; - PresenceContent.fromJson(Map json) + PresenceContent.fromJson(Map json) : presence = PresenceType.values.firstWhere( (p) => p.toString().split('.').last == json['presence']), lastActiveAgo = json.tryGet('last_active_ago'), statusMsg = json.tryGet('status_msg'), currentlyActive = json.tryGet('currently_active'); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['presence'] = presence.toString().split('.').last; if (lastActiveAgo != null) { data['last_active_ago'] = lastActiveAgo; diff --git a/lib/src/model/room_keys_keys.dart b/lib/src/model/room_keys_keys.dart index ce148bc1..6a3762ef 100644 --- a/lib/src/model/room_keys_keys.dart +++ b/lib/src/model/room_keys_keys.dart @@ -27,7 +27,7 @@ class RoomKeysSingleKey { int firstMessageIndex; int forwardedCount; bool isVerified; - Map sessionData; + Map sessionData; RoomKeysSingleKey( {required this.firstMessageIndex, @@ -35,14 +35,14 @@ class RoomKeysSingleKey { required this.isVerified, required this.sessionData}); - RoomKeysSingleKey.fromJson(Map json) + RoomKeysSingleKey.fromJson(Map json) : firstMessageIndex = json['first_message_index'] as int, forwardedCount = json['forwarded_count'] as int, isVerified = json['is_verified'] as bool, - sessionData = json['session_data'] as Map; + sessionData = json['session_data'] as Map; - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['first_message_index'] = firstMessageIndex; data['forwarded_count'] = forwardedCount; data['is_verified'] = isVerified; @@ -56,12 +56,12 @@ class RoomKeysRoom { RoomKeysRoom({required this.sessions}); - RoomKeysRoom.fromJson(Map json) - : sessions = (json['sessions'] as Map).map((k, v) => - MapEntry(k, RoomKeysSingleKey.fromJson(v as Map))); + RoomKeysRoom.fromJson(Map json) + : sessions = (json['sessions'] as Map).map((k, v) => + MapEntry(k, RoomKeysSingleKey.fromJson(v as Map))); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['sessions'] = sessions.map((k, v) => MapEntry(k, v.toJson())); return data; } @@ -71,13 +71,13 @@ class RoomKeysUpdateResponse { String etag; int count; - RoomKeysUpdateResponse.fromJson(Map json) + RoomKeysUpdateResponse.fromJson(Map json) : etag = json.tryGet('etag') ?? '', // synapse replies an int but docs say string? count = json.tryGet('count') ?? 0; - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['etag'] = etag; data['count'] = count; return data; diff --git a/lib/src/model/room_summary.dart b/lib/src/model/room_summary.dart index 0f19836d..d0300b89 100644 --- a/lib/src/model/room_summary.dart +++ b/lib/src/model/room_summary.dart @@ -26,15 +26,15 @@ class RoomSummary { int? mJoinedMemberCount; int? mInvitedMemberCount; - RoomSummary.fromJson(Map json) + RoomSummary.fromJson(Map json) : mHeroes = json['m.heroes'] != null ? List.from(json['m.heroes'] as List) : null, mJoinedMemberCount = json['m.joined_member_count'] as int?, mInvitedMemberCount = json['m.invited_member_count'] as int?; - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (mHeroes != null) { data['m.heroes'] = mHeroes; } diff --git a/lib/src/model/stripped_state_event.dart b/lib/src/model/stripped_state_event.dart index 9fbabb37..dd78184d 100644 --- a/lib/src/model/stripped_state_event.dart +++ b/lib/src/model/stripped_state_event.dart @@ -28,17 +28,17 @@ class StrippedStateEvent extends BasicEventWithSender { StrippedStateEvent( {required String type, - required Map content, + required Map content, required String senderId, this.stateKey}) : super(type: type, content: content, senderId: senderId); - StrippedStateEvent.fromJson(Map json) + StrippedStateEvent.fromJson(Map json) : stateKey = json.tryGet('state_key'), super.fromJson(json); @override - Map toJson() { + Map toJson() { final data = super.toJson(); data['state_key'] = stateKey; return data; diff --git a/lib/src/model/sync_update.dart b/lib/src/model/sync_update.dart index a435894a..176379f0 100644 --- a/lib/src/model/sync_update.dart +++ b/lib/src/model/sync_update.dart @@ -44,27 +44,27 @@ class SyncUpdate { this.deviceUnusedFallbackKeyTypes, }); - SyncUpdate.fromJson(Map json) + SyncUpdate.fromJson(Map json) : nextBatch = json['next_batch'] as String, rooms = (() { - final temp = json.tryGetMap('rooms'); + final temp = json.tryGetMap('rooms'); return temp != null ? RoomsUpdate.fromJson(temp) : null; }()), presence = json .tryGetMap>('presence')?['events'] - ?.map((i) => Presence.fromJson(i as Map)) + ?.map((i) => Presence.fromJson(i as Map)) .toList(), accountData = json .tryGetMap>('account_data')?['events'] - ?.map((i) => BasicEvent.fromJson(i as Map)) + ?.map((i) => BasicEvent.fromJson(i as Map)) .toList(), toDevice = json .tryGetMap>('to_device')?['events'] ?.map( - (i) => BasicEventWithSender.fromJson(i as Map)) + (i) => BasicEventWithSender.fromJson(i as Map)) .toList(), deviceLists = (() { - final temp = json.tryGetMap('device_lists'); + final temp = json.tryGetMap('device_lists'); return temp != null ? DeviceListsUpdate.fromJson(temp) : null; }()), deviceOneTimeKeysCount = @@ -74,8 +74,8 @@ class SyncUpdate { json.tryGetList( 'org.matrix.msc2732.device_unused_fallback_key_types'); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; data['next_batch'] = nextBatch; if (rooms != null) { data['rooms'] = rooms!.toJson(); @@ -121,17 +121,17 @@ class RoomsUpdate { this.leave, }); - RoomsUpdate.fromJson(Map json) { - join = json.tryGetMap('join')?.catchMap((k, v) => - MapEntry(k, JoinedRoomUpdate.fromJson(v as Map))); - invite = json.tryGetMap('invite')?.catchMap((k, v) => - MapEntry(k, InvitedRoomUpdate.fromJson(v as Map))); - leave = json.tryGetMap('leave')?.catchMap((k, v) => - MapEntry(k, LeftRoomUpdate.fromJson(v as Map))); + RoomsUpdate.fromJson(Map json) { + join = json.tryGetMap('join')?.catchMap((k, v) => + MapEntry(k, JoinedRoomUpdate.fromJson(v as Map))); + invite = json.tryGetMap('invite')?.catchMap((k, v) => + MapEntry(k, InvitedRoomUpdate.fromJson(v as Map))); + leave = json.tryGetMap('leave')?.catchMap((k, v) => + MapEntry(k, LeftRoomUpdate.fromJson(v as Map))); } - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (join != null) { data['join'] = join!.map((k, v) => MapEntry(k, v.toJson())); } @@ -164,26 +164,26 @@ class JoinedRoomUpdate extends SyncRoomUpdate { this.unreadNotifications, }); - JoinedRoomUpdate.fromJson(Map json) + JoinedRoomUpdate.fromJson(Map json) : summary = json.tryGetFromJson('summary', RoomSummary.fromJson), state = json .tryGetMap>('state')?['events'] - ?.map((i) => MatrixEvent.fromJson(i as Map)) + ?.map((i) => MatrixEvent.fromJson(i as Map)) .toList(), timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson), ephemeral = json .tryGetMap>('ephemeral')?['events'] - ?.map((i) => BasicRoomEvent.fromJson(i as Map)) + ?.map((i) => BasicRoomEvent.fromJson(i as Map)) .toList(), accountData = json .tryGetMap>('account_data')?['events'] - ?.map((i) => BasicRoomEvent.fromJson(i as Map)) + ?.map((i) => BasicRoomEvent.fromJson(i as Map)) .toList(), unreadNotifications = json.tryGetFromJson( 'unread_notifications', UnreadNotificationCounts.fromJson); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (summary != null) { data['summary'] = summary!.toJson(); } @@ -217,14 +217,14 @@ class InvitedRoomUpdate extends SyncRoomUpdate { InvitedRoomUpdate({this.inviteState}); - InvitedRoomUpdate.fromJson(Map json) + InvitedRoomUpdate.fromJson(Map json) : inviteState = json .tryGetMap>('invite_state')?['events'] - ?.map((i) => StrippedStateEvent.fromJson(i as Map)) + ?.map((i) => StrippedStateEvent.fromJson(i as Map)) .toList(); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (inviteState != null) { data['invite_state'] = { 'events': inviteState!.map((i) => i.toJson()).toList(), @@ -245,19 +245,19 @@ class LeftRoomUpdate extends SyncRoomUpdate { this.accountData, }); - LeftRoomUpdate.fromJson(Map json) + LeftRoomUpdate.fromJson(Map json) : state = json .tryGetMap>('state')?['events'] - ?.map((i) => MatrixEvent.fromJson(i as Map)) + ?.map((i) => MatrixEvent.fromJson(i as Map)) .toList(), timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson), accountData = json .tryGetMap>('account_data')?['events'] - ?.map((i) => BasicRoomEvent.fromJson(i as Map)) + ?.map((i) => BasicRoomEvent.fromJson(i as Map)) .toList(); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (state != null) { data['state'] = { 'events': state!.map((i) => i.toJson()).toList(), @@ -286,16 +286,16 @@ class TimelineUpdate { this.prevBatch, }); - TimelineUpdate.fromJson(Map json) + TimelineUpdate.fromJson(Map json) : events = json - .tryGetList>('events') + .tryGetList>('events') ?.map((v) => MatrixEvent.fromJson(v)) .toList(), limited = json.tryGet('limited'), prevBatch = json.tryGet('prev_batch'); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (events != null) { data['events'] = events!.map((i) => i.toJson()).toList(); } @@ -318,12 +318,12 @@ class UnreadNotificationCounts { this.highlightCount, }); - UnreadNotificationCounts.fromJson(Map json) + UnreadNotificationCounts.fromJson(Map json) : highlightCount = json.tryGet('highlight_count'), notificationCount = json.tryGet('notification_count'); - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (highlightCount != null) { data['highlight_count'] = highlightCount; } @@ -343,12 +343,12 @@ class DeviceListsUpdate { this.left, }); - DeviceListsUpdate.fromJson(Map json) + DeviceListsUpdate.fromJson(Map json) : changed = json.tryGetList('changed') ?? [], left = json.tryGetList('left') ?? []; - Map toJson() { - final data = {}; + Map toJson() { + final data = {}; if (changed != null) { data['changed'] = changed; } diff --git a/lib/src/utils/map_copy_extension.dart b/lib/src/utils/map_copy_extension.dart index 2cf95989..6ece67d3 100644 --- a/lib/src/utils/map_copy_extension.dart +++ b/lib/src/utils/map_copy_extension.dart @@ -21,9 +21,9 @@ * SOFTWARE. */ -extension MapCopyExtension on Map { +extension MapCopyExtension on Map { dynamic _copyValue(dynamic value) { - if (value is Map) { + if (value is Map) { return value.copy(); } if (value is List) { @@ -33,8 +33,8 @@ extension MapCopyExtension on Map { } /// Deep-copies a given json map - Map copy() { - final copy = Map.from(this); + Map copy() { + final copy = Map.from(this); for (final entry in copy.entries) { copy[entry.key] = _copyValue(entry.value); } diff --git a/lib/src/utils/try_get_map_extension.dart b/lib/src/utils/try_get_map_extension.dart index 02dc2743..5a9cf7a8 100644 --- a/lib/src/utils/try_get_map_extension.dart +++ b/lib/src/utils/try_get_map_extension.dart @@ -59,7 +59,7 @@ class _SilentLog implements TryGet { void call(String key, Type expected, Type actual) {} } -extension TryGetMapExtension on Map { +extension TryGetMapExtension on Map { T? tryGet(String key, [TryGet log = TryGet.optional]) { final Object? value = this[key]; if (value is! T) { @@ -101,9 +101,9 @@ extension TryGetMapExtension on Map { } } - A? tryGetFromJson(String key, A Function(Map) fromJson, + A? tryGetFromJson(String key, A Function(Map) fromJson, [TryGet log = TryGet.optional]) { - final value = tryGetMap(key, log); + final value = tryGetMap(key, log); return value != null ? fromJson(value) : null; } diff --git a/test/event_content_test.dart b/test/event_content_test.dart index b6124ce7..6b769ba0 100644 --- a/test/event_content_test.dart +++ b/test/event_content_test.dart @@ -30,7 +30,7 @@ import 'package:matrix_api_lite/matrix_api_lite.dart'; void main() { group('Event Content tests', () { test('Room Encryption Content', () { - Map? json = { + Map? json = { 'content': { 'algorithm': 'm.megolm.v1.aes-sha2', 'rotation_period_ms': 604800000, @@ -44,12 +44,12 @@ void main() { 'type': 'm.room.encryption', 'unsigned': {'age': 1234} }; - json = jsonDecode(jsonEncode(json)) as Map?; + json = jsonDecode(jsonEncode(json)) as Map?; expect(MatrixEvent.fromJson(json!).parsedRoomEncryptionContent.toJson(), json['content']); }); test('Room Encrypted Content', () { - Map? json = { + Map? json = { 'content': { 'algorithm': 'm.megolm.v1.aes-sha2', 'ciphertext': 'AwgAEnACgAkLmt6qF84IK++J7UDH2Za1YVchHyprqTqsg...', @@ -64,10 +64,10 @@ void main() { 'type': 'm.room.encrypted', 'unsigned': {'age': 1234} }; - json = jsonDecode(jsonEncode(json)) as Map?; + json = jsonDecode(jsonEncode(json)) as Map?; expect(MatrixEvent.fromJson(json!).parsedRoomEncryptedContent.toJson(), json['content']); - json = { + json = { 'content': { 'algorithm': 'm.olm.v1.curve25519-aes-sha2', 'ciphertext': { @@ -85,12 +85,12 @@ void main() { 'type': 'm.room.encrypted', 'unsigned': {'age': 1234} }; - json = jsonDecode(jsonEncode(json)) as Map?; + json = jsonDecode(jsonEncode(json)) as Map?; expect(MatrixEvent.fromJson(json!).parsedRoomEncryptedContent.toJson(), json['content']); }); test('Room Key Content', () { - Map? json = { + Map? json = { 'content': { 'algorithm': 'm.megolm.v1.aes-sha2', 'room_id': '!Cuyf34gef24t:localhost', @@ -99,12 +99,12 @@ void main() { }, 'type': 'm.room_key' }; - json = jsonDecode(jsonEncode(json)) as Map?; + json = jsonDecode(jsonEncode(json)) as Map?; expect(BasicEvent.fromJson(json!).parsedRoomKeyContent.toJson(), json['content']); }); test('Room Key Request Content', () { - Map? json = { + Map? json = { 'content': { 'action': 'request_cancellation', 'request_id': '1495474790150.19', @@ -112,10 +112,10 @@ void main() { }, 'type': 'm.room_key_request' }; - json = jsonDecode(jsonEncode(json)) as Map?; + json = jsonDecode(jsonEncode(json)) as Map?; expect(BasicEvent.fromJson(json!).parsedRoomKeyRequestContent.toJson(), json['content']); - json = { + json = { 'content': { 'action': 'request', 'body': { @@ -129,12 +129,12 @@ void main() { }, 'type': 'm.room_key_request' }; - json = jsonDecode(jsonEncode(json)) as Map?; + json = jsonDecode(jsonEncode(json)) as Map?; expect(BasicEvent.fromJson(json!).parsedRoomKeyRequestContent.toJson(), json['content']); }); test('Forwarded Room Key Content', () { - Map? json = { + Map? json = { 'content': { 'algorithm': 'm.megolm.v1.aes-sha2', 'forwarding_curve25519_key_chain': [ @@ -149,14 +149,14 @@ void main() { }, 'type': 'm.forwarded_room_key' }; - json = jsonDecode(jsonEncode(json)) as Map?; + json = jsonDecode(jsonEncode(json)) as Map?; expect(BasicEvent.fromJson(json!).parsedForwardedRoomKeyContent.toJson(), json['content']); }); test('OLM Plaintext Payload', () { - Map? json = { + Map? json = { 'type': '', - 'content': { + 'content': { 'msgtype': 'm.text', 'body': 'Hello world', }, @@ -165,12 +165,12 @@ void main() { 'recipient_keys': {'ed25519': ''}, 'keys': {'ed25519': ''} }; - json = jsonDecode(jsonEncode(json)) as Map?; + json = jsonDecode(jsonEncode(json)) as Map?; expect(OlmPlaintextPayload.fromJson(json!).toJson(), json); }); test('Image Pack Content', () { // basic parse / unparse - var json = { + var json = { 'type': 'some type', 'content': { 'images': { @@ -191,12 +191,12 @@ void main() { 'org.custom': 'blah', }, }; - json = jsonDecode(jsonEncode(json)) as Map; + json = jsonDecode(jsonEncode(json)) as Map; expect(BasicEvent.fromJson(json).parsedImagePackContent.toJson(), json['content']); // emoticons migration - json = { + json = { 'type': 'some type', 'content': { 'emoticons': { @@ -206,7 +206,7 @@ void main() { }, }, }; - json = jsonDecode(jsonEncode(json)) as Map; + json = jsonDecode(jsonEncode(json)) as Map; expect( BasicEvent.fromJson(json) .parsedImagePackContent @@ -216,7 +216,7 @@ void main() { 'url': 'mxc://example.org/beep', }); - json = { + json = { 'type': 'some type', 'content': { 'short': { @@ -224,7 +224,7 @@ void main() { }, }, }; - json = jsonDecode(jsonEncode(json)) as Map; + json = jsonDecode(jsonEncode(json)) as Map; expect( BasicEvent.fromJson(json) .parsedImagePackContent @@ -235,15 +235,15 @@ void main() { }); // invalid url for image - json = { + json = { 'type': 'some type', 'content': { 'images': { - 'emote': {}, + 'emote': {}, }, }, }; - json = jsonDecode(jsonEncode(json)) as Map; + json = jsonDecode(jsonEncode(json)) as Map; expect(BasicEvent.fromJson(json).parsedImagePackContent.images['emote'], null); }); diff --git a/test/map_copy_extension_test.dart b/test/map_copy_extension_test.dart index 188a18ee..d20b61e8 100644 --- a/test/map_copy_extension_test.dart +++ b/test/map_copy_extension_test.dart @@ -28,21 +28,21 @@ import 'package:matrix_api_lite/matrix_api_lite.dart'; void main() { group('Map-copy-extension', () { test('it should work', () { - final original = { + final original = { 'attr': 'fox', - 'child': { + 'child': { 'attr': 'bunny', 'list': [1, 2], }, }; final copy = original.copy(); - (original['child'] as Map)['attr'] = 'raccoon'; - expect((copy['child'] as Map)['attr'], 'bunny'); - ((original['child'] as Map)['list'] as List).add(3); - expect((copy['child'] as Map)['list'], [1, 2]); + (original['child'] as Map)['attr'] = 'raccoon'; + expect((copy['child'] as Map)['attr'], 'bunny'); + ((original['child'] as Map)['list'] as List).add(3); + expect((copy['child'] as Map)['list'], [1, 2]); }); test('should do arrays', () { - final original = { + final original = { 'arr': [ [1, 2], {'beep': 'boop'}, @@ -51,9 +51,9 @@ void main() { final copy = original.copy(); ((original['arr'] as List)[0] as List).add(3); expect((copy['arr'] as List)[0], [1, 2]); - ((original['arr'] as List)[1] as Map)['beep'] = 'blargh'; + ((original['arr'] as List)[1] as Map)['beep'] = 'blargh'; expect( - ((copy['arr'] as List)[1] as Map)['beep'], 'boop'); + ((copy['arr'] as List)[1] as Map)['beep'], 'boop'); }); }); } diff --git a/test/matrix_api_test.dart b/test/matrix_api_test.dart index 0306ad28..9b6943c0 100644 --- a/test/matrix_api_test.dart +++ b/test/matrix_api_test.dart @@ -28,7 +28,7 @@ import 'package:test/test.dart'; import 'package:matrix_api_lite/fake_matrix_api.dart'; import 'package:matrix_api_lite/matrix_api_lite.dart'; -const emptyRequest = {}; +const emptyRequest = {}; void main() { /// All Tests related to device keys @@ -435,8 +435,8 @@ void main() { 'types': ['type1'], }, 'include_leave': true, - 'state': {}, - 'timeline': {}, + 'state': {}, + 'timeline': {}, }, 'presence': { 'limit': 10, @@ -1082,7 +1082,7 @@ void main() { final devices = await matrixApi.getDevices(); expect( (FakeMatrixApi.api['GET']!['/client/v3/devices']!.call(emptyRequest) - as Map?)?['devices'], + as Map?)?['devices'], devices?.map((i) => i.toJson()).toList()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1229,7 +1229,7 @@ void main() { final response = await matrixApi.getPushers(); expect( FakeMatrixApi.api['GET']!['/client/v3/pushers']! - .call({}), + .call({}), {'pushers': response?.map((i) => i.toJson()).toList()}, ); @@ -1268,7 +1268,7 @@ void main() { expect( FakeMatrixApi.api['GET']![ '/client/v3/notifications?from=1234&limit=10&only=1234']! - .call({}), + .call({}), response.toJson(), ); @@ -1281,7 +1281,7 @@ void main() { final response = await matrixApi.getPushRules(); expect( FakeMatrixApi.api['GET']!['/client/v3/pushrules']! - .call({}), + .call({}), {'global': response.toJson()}, ); @@ -1295,7 +1295,7 @@ void main() { await matrixApi.getPushRule('global', PushRuleKind.content, 'nocake'); expect( FakeMatrixApi.api['GET']!['/client/v3/pushrules/global/content/nocake']! - .call({}), + .call({}), response.toJson(), ); @@ -1396,7 +1396,7 @@ void main() { expect( FakeMatrixApi.api['GET']![ '/client/v3/events?from=1234&timeout=10&room_id=%211234']! - .call({}), + .call({}), response.toJson(), ); @@ -1411,7 +1411,7 @@ void main() { expect( FakeMatrixApi.api['GET']![ '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags']! - .call({}), + .call({}), {'tags': response?.map((k, v) => MapEntry(k, v.toJson()))}, ); @@ -1636,14 +1636,14 @@ void main() { matrixApi.accessToken = '1234'; final algorithm = BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2; - final authData = { + final authData = { 'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM', 'signatures': >{}, }; final ret = await matrixApi.postRoomKeysVersion(algorithm, authData); expect( (FakeMatrixApi.api['POST']!['/client/v3/room_keys/version']! - .call(emptyRequest) as Map)['version'], + .call(emptyRequest) as Map)['version'], ret); }); test('getRoomKeysVersionCurrent', () async { @@ -1661,7 +1661,7 @@ void main() { matrixApi.accessToken = '1234'; final algorithm = BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2; - final authData = { + final authData = { 'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM', 'signatures': >{}, }; diff --git a/test/try_get_map_extension_test.dart b/test/try_get_map_extension_test.dart index 13e60c51..9f1a51d2 100644 --- a/test/try_get_map_extension_test.dart +++ b/test/try_get_map_extension_test.dart @@ -29,11 +29,11 @@ void main() { group('Try-get-map-extension', () { Logs().level = Level.verbose; test('it should work', () { - final data = { + final data = { 'str': 'foxies', 'int': 42, 'list': [2, 3, 4], - 'map': { + 'map': { 'beep': 'boop', }, }; @@ -41,12 +41,12 @@ void main() { expect(data.tryGet('str'), null); expect(data.tryGet('int'), 42); expect(data.tryGet>('list'), [2, 3, 4]); - expect(data.tryGetMap('map')?.tryGet('beep'), + expect(data.tryGetMap('map')?.tryGet('beep'), 'boop'); expect( - data.tryGetMap('map')?.tryGet('meep'), null); + data.tryGetMap('map')?.tryGet('meep'), null); expect( - data.tryGetMap('pam')?.tryGet('beep'), null); + data.tryGetMap('pam')?.tryGet('beep'), null); }); }); }