refactor: Changed Map<String, dynamic> to Map<String, Object?>

- contains breaking changes because some type casts will be needed in
  Matrix SDK
This commit is contained in:
Malin Errenst 2023-06-09 09:49:24 +02:00
parent cf984d61f9
commit 06d587e64f
No known key found for this signature in database
40 changed files with 363 additions and 363 deletions

View File

@ -30,14 +30,14 @@ import 'package:http/testing.dart';
import 'package:matrix_api_lite/matrix_api_lite.dart'; import 'package:matrix_api_lite/matrix_api_lite.dart';
Map<String, dynamic> decodeJson(dynamic data) { Map<String, Object?> decodeJson(dynamic data) {
if (data is String) { if (data is String) {
return json.decode(data) as Map<String, dynamic>; return json.decode(data) as Map<String, Object?>;
} }
if (data is Map && data.isEmpty) { if (data is Map && data.isEmpty) {
return <String, dynamic>{}; return <String, Object?>{};
} }
return data as Map<String, dynamic>; return data as Map<String, Object?>;
} }
T? tryCast<T>(dynamic object) => object is T ? object : null; T? tryCast<T>(dynamic object) => object is T ? object : null;
@ -65,13 +65,13 @@ class FakeMatrixApi extends MockClient {
final method = request.method; final method = request.method;
final dynamic data = final dynamic data =
method == 'GET' ? request.url.queryParameters : request.body; method == 'GET' ? request.url.queryParameters : request.body;
dynamic res = <String, dynamic>{}; dynamic res = <String, Object?>{};
var statusCode = 200; var statusCode = 200;
//print('\$method request to $action with Data: $data'); //print('\$method request to $action with Data: $data');
// Sync requests with timeout // Sync requests with timeout
if (data is Map<String, dynamic> && data['timeout'] is String) { if (data is Map<String, Object?> && data['timeout'] is String) {
await Future<void>.delayed(Duration(seconds: 5)); await Future<void>.delayed(Duration(seconds: 5));
} }
@ -92,7 +92,7 @@ class FakeMatrixApi extends MockClient {
} }
} else if (method == 'PUT' && } else if (method == 'PUT' &&
action.contains('/client/v3/sendToDevice/')) { action.contains('/client/v3/sendToDevice/')) {
res = <String, dynamic>{}; res = <String, Object?>{};
} else if (method == 'GET' && } else if (method == 'GET' &&
action.contains('/client/v3/rooms/') && action.contains('/client/v3/rooms/') &&
action.contains('/state/m.room.member/')) { action.contains('/state/m.room.member/')) {
@ -116,7 +116,7 @@ class FakeMatrixApi extends MockClient {
return Response.bytes(utf8.encode(json.encode(res)), statusCode); return Response.bytes(utf8.encode(json.encode(res)), statusCode);
}); });
static Map<String, dynamic> messagesResponse = { static Map<String, Object?> messagesResponse = {
'start': 't47429-4392820_219380_26003_2265', 'start': 't47429-4392820_219380_26003_2265',
'end': 't47409-4357353_219380_26003_2265', 'end': 't47409-4357353_219380_26003_2265',
'chunk': [ 'chunk': [
@ -172,10 +172,10 @@ class FakeMatrixApi extends MockClient {
'unsigned': {'age': 1234} 'unsigned': {'age': 1234}
} }
], ],
'state': <Map<String, dynamic>>[], 'state': <Map<String, Object?>>[],
}; };
static Map<String, dynamic> syncResponse = { static Map<String, Object?> syncResponse = {
'next_batch': Random().nextDouble().toString(), 'next_batch': Random().nextDouble().toString(),
'rooms': { 'rooms': {
'join': { 'join': {
@ -394,7 +394,7 @@ class FakeMatrixApi extends MockClient {
'override': [ 'override': [
{ {
'actions': ['dont_notify'], 'actions': ['dont_notify'],
'conditions': <Map<String, dynamic>>[], 'conditions': <Map<String, Object?>>[],
'default': true, 'default': true,
'enabled': false, 'enabled': false,
'rule_id': '.m.rule.master' 'rule_id': '.m.rule.master'
@ -428,7 +428,7 @@ class FakeMatrixApi extends MockClient {
'rule_id': '!localpart:server.abc' 'rule_id': '!localpart:server.abc'
} }
], ],
'sender': <Map<String, dynamic>>[], 'sender': <Map<String, Object?>>[],
'underride': [ 'underride': [
{ {
'actions': [ 'actions': [
@ -676,14 +676,14 @@ class FakeMatrixApi extends MockClient {
'device_one_time_keys_count': {'curve25519': 10, 'signed_curve25519': 20}, 'device_one_time_keys_count': {'curve25519': 10, 'signed_curve25519': 20},
}; };
static Map<String, dynamic> archiveSyncResponse = { static Map<String, Object?> archiveSyncResponse = {
'next_batch': Random().nextDouble().toString(), 'next_batch': Random().nextDouble().toString(),
'presence': {'events': <Map<String, dynamic>>[]}, 'presence': {'events': <Map<String, Object?>>[]},
'account_data': {'events': <Map<String, dynamic>>[]}, 'account_data': {'events': <Map<String, Object?>>[]},
'to_device': {'events': <Map<String, dynamic>>[]}, 'to_device': {'events': <Map<String, Object?>>[]},
'rooms': { 'rooms': {
'join': <String, dynamic>{}, 'join': <String, Object?>{},
'invite': <String, dynamic>{}, 'invite': <String, Object?>{},
'leave': { 'leave': {
'!5345234234:example.com': { '!5345234234:example.com': {
'timeline': { 'timeline': {
@ -728,7 +728,7 @@ class FakeMatrixApi extends MockClient {
}, },
}, },
'!5345234235:example.com': { '!5345234235:example.com': {
'timeline': {'events': <Map<String, dynamic>>[]}, 'timeline': {'events': <Map<String, Object?>>[]},
'state': { 'state': {
'events': [ 'events': [
{ {
@ -748,7 +748,7 @@ class FakeMatrixApi extends MockClient {
} }
}; };
static Map<String, dynamic> spaceHierarchyResponse = { static Map<String, Object?> spaceHierarchyResponse = {
'rooms': [ 'rooms': [
{ {
'room_id': '!gPxZhKUssFZKZcoCKY:neko.dev', 'room_id': '!gPxZhKUssFZKZcoCKY:neko.dev',
@ -864,7 +864,7 @@ class FakeMatrixApi extends MockClient {
'join_rule': 'public', 'join_rule': 'public',
'world_readable': true, 'world_readable': true,
'guest_can_join': true, 'guest_can_join': true,
'children_state': <Map<String, dynamic>>[] 'children_state': <Map<String, Object?>>[]
}, },
{ {
'room_id': '!aZUzMIEZvEwnDquxLf:neko.dev', 'room_id': '!aZUzMIEZvEwnDquxLf:neko.dev',
@ -877,7 +877,7 @@ class FakeMatrixApi extends MockClient {
'join_rule': 'public', 'join_rule': 'public',
'world_readable': true, 'world_readable': true,
'guest_can_join': true, 'guest_can_join': true,
'children_state': <Map<String, dynamic>>[] 'children_state': <Map<String, Object?>>[]
}, },
{ {
'room_id': '!aRzRZBvOAkHMcEjAPS:libera.chat', 'room_id': '!aRzRZBvOAkHMcEjAPS:libera.chat',
@ -889,7 +889,7 @@ class FakeMatrixApi extends MockClient {
'join_rule': 'public', 'join_rule': 'public',
'world_readable': false, 'world_readable': false,
'guest_can_join': false, 'guest_can_join': false,
'children_state': <Map<String, dynamic>>[] 'children_state': <Map<String, Object?>>[]
}, },
{ {
'room_id': '!DXsRRxkqqDhDkAyXfL:matrix.org', 'room_id': '!DXsRRxkqqDhDkAyXfL:matrix.org',
@ -902,7 +902,7 @@ class FakeMatrixApi extends MockClient {
'join_rule': 'public', 'join_rule': 'public',
'world_readable': false, 'world_readable': false,
'guest_can_join': false, 'guest_can_join': false,
'children_state': <Map<String, dynamic>>[] 'children_state': <Map<String, Object?>>[]
}, },
{ {
'room_id': '!tbCRpmsMiwMBlIThOd:matrix.org', 'room_id': '!tbCRpmsMiwMBlIThOd:matrix.org',
@ -914,7 +914,7 @@ class FakeMatrixApi extends MockClient {
'join_rule': 'public', 'join_rule': 'public',
'world_readable': false, 'world_readable': false,
'guest_can_join': false, 'guest_can_join': false,
'children_state': <Map<String, dynamic>>[] 'children_state': <Map<String, Object?>>[]
}, },
{ {
'room_id': '!LPpmvMsEgDwuSuHSpM:matrix.org', 'room_id': '!LPpmvMsEgDwuSuHSpM:matrix.org',
@ -926,7 +926,7 @@ class FakeMatrixApi extends MockClient {
'join_rule': 'public', 'join_rule': 'public',
'world_readable': true, 'world_readable': true,
'guest_can_join': true, 'guest_can_join': true,
'children_state': <Map<String, dynamic>>[] 'children_state': <Map<String, Object?>>[]
}, },
{ {
'room_id': '!prlZxmnmAGuCYHUNSw:neko.dev', 'room_id': '!prlZxmnmAGuCYHUNSw:neko.dev',
@ -939,7 +939,7 @@ class FakeMatrixApi extends MockClient {
'join_rule': 'public', 'join_rule': 'public',
'world_readable': true, 'world_readable': true,
'guest_can_join': false, 'guest_can_join': false,
'children_state': <Map<String, dynamic>>[] 'children_state': <Map<String, Object?>>[]
}, },
{ {
'room_id': '!ooHixUOgoLVUjCSMZC:matrix.org', 'room_id': '!ooHixUOgoLVUjCSMZC:matrix.org',
@ -951,12 +951,12 @@ class FakeMatrixApi extends MockClient {
'join_rule': 'public', 'join_rule': 'public',
'world_readable': true, 'world_readable': true,
'guest_can_join': true, 'guest_can_join': true,
'children_state': <Map<String, dynamic>>[] 'children_state': <Map<String, Object?>>[]
} }
] ]
}; };
static final Map<String, Map<String, dynamic Function(dynamic)>> api = { static final Map<String, Map<String, Object? Function(dynamic)>> api = {
'GET': { 'GET': {
'/path/to/auth/error': (var req) => { '/path/to/auth/error': (var req) => {
'errcode': 'M_FORBIDDEN', 'errcode': 'M_FORBIDDEN',
@ -983,7 +983,7 @@ class FakeMatrixApi extends MockClient {
'tags': { 'tags': {
'm.favourite': {'order': 0.1}, 'm.favourite': {'order': 0.1},
'u.Work': {'order': 0.7}, 'u.Work': {'order': 0.7},
'u.Customers': <String, dynamic>{}, 'u.Customers': <String, Object?>{},
} }
}, },
'/client/v3/events?from=1234&timeout=10&room_id=%211234': (var req) => { '/client/v3/events?from=1234&timeout=10&room_id=%211234': (var req) => {
@ -1093,7 +1093,7 @@ class FakeMatrixApi extends MockClient {
'network_id': 'gitter', 'network_id': 'gitter',
'desc': 'Gitter', 'desc': 'Gitter',
'icon': 'mxc://example.org/zXyWvUt', 'icon': 'mxc://example.org/zXyWvUt',
'fields': <String, dynamic>{} 'fields': <String, Object?>{}
} }
] ]
} }
@ -1611,7 +1611,7 @@ class FakeMatrixApi extends MockClient {
'override': [ 'override': [
{ {
'actions': ['dont_notify'], 'actions': ['dont_notify'],
'conditions': <Map<String, dynamic>>[], 'conditions': <Map<String, Object?>>[],
'default': true, 'default': true,
'enabled': false, 'enabled': false,
'rule_id': '.m.rule.master' 'rule_id': '.m.rule.master'
@ -1630,8 +1630,8 @@ class FakeMatrixApi extends MockClient {
'rule_id': '.m.rule.suppress_notices' 'rule_id': '.m.rule.suppress_notices'
} }
], ],
'room': <Map<String, dynamic>>[], 'room': <Map<String, Object?>>[],
'sender': <Map<String, dynamic>>[], 'sender': <Map<String, Object?>>[],
'underride': [ 'underride': [
{ {
'actions': [ 'actions': [
@ -1781,7 +1781,7 @@ class FakeMatrixApi extends MockClient {
'algorithm': AlgorithmTypes.megolmBackupV1Curve25519AesSha2, 'algorithm': AlgorithmTypes.megolmBackupV1Curve25519AesSha2,
'auth_data': { 'auth_data': {
'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM', 'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM',
'signatures': <String, dynamic>{}, 'signatures': <String, Object?>{},
}, },
'count': 0, 'count': 0,
'etag': '0', 'etag': '0',
@ -1840,15 +1840,15 @@ class FakeMatrixApi extends MockClient {
(var req) => spaceHierarchyResponse, (var req) => spaceHierarchyResponse,
}, },
'POST': { 'POST': {
'/client/v3/delete_devices': (var req) => <String, dynamic>{}, '/client/v3/delete_devices': (var req) => <String, Object?>{},
'/client/v3/account/3pid/add': (var req) => <String, dynamic>{}, '/client/v3/account/3pid/add': (var req) => <String, Object?>{},
'/client/v3/account/3pid/bind': (var req) => <String, dynamic>{}, '/client/v3/account/3pid/bind': (var req) => <String, Object?>{},
'/client/v3/account/3pid/delete': (var req) => '/client/v3/account/3pid/delete': (var req) =>
{'id_server_unbind_result': 'success'}, {'id_server_unbind_result': 'success'},
'/client/v3/account/3pid/unbind': (var req) => '/client/v3/account/3pid/unbind': (var req) =>
{'id_server_unbind_result': 'success'}, {'id_server_unbind_result': 'success'},
'/client/v3/account/password': (var req) => <String, dynamic>{}, '/client/v3/account/password': (var req) => <String, Object?>{},
'/client/v3/rooms/1234/report/1234': (var req) => <String, dynamic>{}, '/client/v3/rooms/1234/report/1234': (var req) => <String, Object?>{},
'/client/v3/search': (var req) => { '/client/v3/search': (var req) => {
'search_categories': { 'search_categories': {
'room_events': { 'room_events': {
@ -1924,9 +1924,9 @@ class FakeMatrixApi extends MockClient {
'submit_url': 'https://example.org/path/to/submitToken' 'submit_url': 'https://example.org/path/to/submitToken'
}, },
'/client/v3/rooms/!localpart%3Aexample.com/receipt/m.read/%241234%3Aexample.com': '/client/v3/rooms/!localpart%3Aexample.com/receipt/m.read/%241234%3Aexample.com':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/rooms/!localpart%3Aexample.com/read_markers': (var req) => '/client/v3/rooms/!localpart%3Aexample.com/read_markers': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/user/${Uri.encodeComponent('alice@example.com')}/filter': '/client/v3/user/${Uri.encodeComponent('alice@example.com')}/filter':
(var req) => {'filter_id': '1234'}, (var req) => {'filter_id': '1234'},
'/client/v3/publicRooms?server=example.com': (var req) => { '/client/v3/publicRooms?server=example.com': (var req) => {
@ -1948,11 +1948,11 @@ class FakeMatrixApi extends MockClient {
}, },
'/client/v3/keys/claim': (dynamic req) { '/client/v3/keys/claim': (dynamic req) {
final request = decodeJson(req)["one_time_keys"]; final request = decodeJson(req)["one_time_keys"];
final keys = (request is Map<String, dynamic>) final keys = (request is Map<String, Object?>)
? request["one_time_keys"] as Map<String, dynamic>? ? request["one_time_keys"] as Map<String, Object?>?
: null; : null;
return { return {
'failures': <String, dynamic>{}, 'failures': <String, Object?>{},
'one_time_keys': { 'one_time_keys': {
if (keys?['@alice:example.com'] != null) if (keys?['@alice:example.com'] != null)
'@alice:example.com': { '@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/invite': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aexample.com/leave': (var req) => '/client/v3/rooms/!localpart%3Aexample.com/leave': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aexample.com/forget': (var req) => '/client/v3/rooms/!localpart%3Aexample.com/forget': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/kick': (var req) => '/client/v3/rooms/!localpart%3Aserver.abc/kick': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aexample.com/kick': (var req) => '/client/v3/rooms/!localpart%3Aexample.com/kick': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aexample.com/ban': (var req) => '/client/v3/rooms/!localpart%3Aexample.com/ban': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aexample.com/unban': (var req) => '/client/v3/rooms/!localpart%3Aexample.com/unban': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aexample.com/join': (var req) => '/client/v3/rooms/!localpart%3Aexample.com/join': (var req) =>
{'room_id': '!localpart:example.com'}, {'room_id': '!localpart:example.com'},
'/client/v3/join/!localpart%3Aexample.com?server_name=example.com&server_name=example.abc': '/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) => { '/client/v3/keys/upload': (var req) => {
'one_time_key_counts': { 'one_time_key_counts': {
'curve25519': 10, 'curve25519': 10,
'signed_curve25519': tryCast<Map<String, Map<String, dynamic>>>( 'signed_curve25519': tryCast<Map<String, Map<String, Object?>>>(
decodeJson(req))?['one_time_keys'] decodeJson(req))?['one_time_keys']
?.keys ?.keys
.length ?? .length ??
@ -2014,7 +2014,7 @@ class FakeMatrixApi extends MockClient {
} }
}, },
'/client/v3/keys/query': (var req) => { '/client/v3/keys/query': (var req) => {
'failures': <String, dynamic>{}, 'failures': <String, Object?>{},
'device_keys': { 'device_keys': {
'@alice:example.com': { '@alice:example.com': {
'JLAFKJWSCS': { 'JLAFKJWSCS': {
@ -2136,7 +2136,7 @@ class FakeMatrixApi extends MockClient {
'ed25519:82mAXjsmbTbrE6zyShpR869jnrANO75H8nYY0nDLoJ8': 'ed25519:82mAXjsmbTbrE6zyShpR869jnrANO75H8nYY0nDLoJ8':
'82mAXjsmbTbrE6zyShpR869jnrANO75H8nYY0nDLoJ8', '82mAXjsmbTbrE6zyShpR869jnrANO75H8nYY0nDLoJ8',
}, },
'signatures': <String, dynamic>{}, 'signatures': <String, Object?>{},
}, },
'@othertest:fakeServer.notExisting': { '@othertest:fakeServer.notExisting': {
'user_id': '@othertest:fakeServer.notExisting', 'user_id': '@othertest:fakeServer.notExisting',
@ -2144,7 +2144,7 @@ class FakeMatrixApi extends MockClient {
'keys': { 'keys': {
'ed25519:master': 'master', 'ed25519:master': 'master',
}, },
'signatures': <String, dynamic>{}, 'signatures': <String, Object?>{},
}, },
}, },
'self_signing_keys': { 'self_signing_keys': {
@ -2168,7 +2168,7 @@ class FakeMatrixApi extends MockClient {
'keys': { 'keys': {
'ed25519:self_signing': 'self_signing', 'ed25519:self_signing': 'self_signing',
}, },
'signatures': <String, dynamic>{}, 'signatures': <String, Object?>{},
}, },
}, },
'user_signing_keys': { 'user_signing_keys': {
@ -2192,7 +2192,7 @@ class FakeMatrixApi extends MockClient {
'keys': { 'keys': {
'ed25519:user_signing': 'user_signing', 'ed25519:user_signing': 'user_signing',
}, },
'signatures': <String, dynamic>{}, 'signatures': <String, Object?>{},
}, },
}, },
}, },
@ -2232,64 +2232,64 @@ class FakeMatrixApi extends MockClient {
}, },
'/media/v3/upload?filename=file.jpeg': (var req) => '/media/v3/upload?filename=file.jpeg': (var req) =>
{'content_uri': 'mxc://example.com/AQwafuaFswefuhsfAFAgsw'}, {'content_uri': 'mxc://example.com/AQwafuaFswefuhsfAFAgsw'},
'/client/v3/logout': (var reqI) => <String, dynamic>{}, '/client/v3/logout': (var reqI) => <String, Object?>{},
'/client/v3/pushers/set': (var reqI) => <String, dynamic>{}, '/client/v3/pushers/set': (var reqI) => <String, Object?>{},
'/client/v3/join/1234': (var reqI) => {'room_id': '1234'}, '/client/v3/join/1234': (var reqI) => {'room_id': '1234'},
'/client/v3/logout/all': (var reqI) => <String, dynamic>{}, '/client/v3/logout/all': (var reqI) => <String, Object?>{},
'/client/v3/createRoom': (var reqI) => { '/client/v3/createRoom': (var reqI) => {
'room_id': '!1234:fakeServer.notExisting', 'room_id': '!1234:fakeServer.notExisting',
}, },
'/client/v3/rooms/!localpart%3Aserver.abc/read_markers': (var reqI) => '/client/v3/rooms/!localpart%3Aserver.abc/read_markers': (var reqI) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart:server.abc/kick': (var reqI) => '/client/v3/rooms/!localpart:server.abc/kick': (var reqI) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/ban': (var reqI) => '/client/v3/rooms/!localpart%3Aserver.abc/ban': (var reqI) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/unban': (var reqI) => '/client/v3/rooms/!localpart%3Aserver.abc/unban': (var reqI) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/invite': (var reqI) => '/client/v3/rooms/!localpart%3Aserver.abc/invite': (var reqI) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/keys/device_signing/upload': (var reqI) { '/client/v3/keys/device_signing/upload': (var reqI) {
return <String, dynamic>{}; return <String, Object?>{};
}, },
'/client/v3/keys/signatures/upload': (var reqI) => '/client/v3/keys/signatures/upload': (var reqI) =>
{'failures': <String, dynamic>{}}, {'failures': <String, Object?>{}},
'/client/v3/room_keys/version': (var reqI) => {'version': '5'}, '/client/v3/room_keys/version': (var reqI) => {'version': '5'},
}, },
'PUT': { 'PUT': {
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.ignored_user_list': '/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.ignored_user_list':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/presence/${Uri.encodeComponent('@alice:example.com')}/status': '/client/v3/presence/${Uri.encodeComponent('@alice:example.com')}/status':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/pushrules/global/content/nocake/enabled': (var req) => '/client/v3/pushrules/global/content/nocake/enabled': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/pushrules/global/content/nocake/actions': (var req) => '/client/v3/pushrules/global/content/nocake/actions': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.history_visibility': '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.history_visibility':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.join_rules': '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.join_rules':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.guest_access': '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.guest_access':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.invite/1234': '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.invite/1234':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.answer/1234': '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.answer/1234':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.candidates/1234': '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.candidates/1234':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.hangup/1234': '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.hangup/1234':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/rooms/!1234%3Aexample.com/redact/1143273582443PhrSn%3Aexample.org/1234': '/client/v3/rooms/!1234%3Aexample.com/redact/1143273582443PhrSn%3Aexample.org/1234':
(var req) => {'event_id': '1234'}, (var req) => {'event_id': '1234'},
'/client/v3/pushrules/global/room/!localpart%3Aserver.abc': (var req) => '/client/v3/pushrules/global/room/!localpart%3Aserver.abc': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/pushrules/global/override/.m.rule.master/enabled': '/client/v3/pushrules/global/override/.m.rule.master/enabled':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/pushrules/global/content/nocake?before=1&after=2': '/client/v3/pushrules/global/content/nocake?before=1&after=2':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/devices/QBUAZIFURK': (var req) => <String, dynamic>{}, '/client/v3/devices/QBUAZIFURK': (var req) => <String, Object?>{},
'/client/v3/directory/room/%23testalias%3Aexample.com': (var reqI) => '/client/v3/directory/room/%23testalias%3Aexample.com': (var reqI) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/send/m.room.message/testtxid': '/client/v3/rooms/!localpart%3Aserver.abc/send/m.room.message/testtxid':
(var reqI) => { (var reqI) => {
'event_id': '\$event${FakeMatrixApi.eventCounter++}', 'event_id': '\$event${FakeMatrixApi.eventCounter++}',
@ -2299,7 +2299,7 @@ class FakeMatrixApi extends MockClient {
'event_id': '\$event${FakeMatrixApi.eventCounter++}', 'event_id': '\$event${FakeMatrixApi.eventCounter++}',
}, },
'/client/v3/rooms/!localpart%3Aexample.com/typing/%40alice%3Aexample.com': '/client/v3/rooms/!localpart%3Aexample.com/typing/%40alice%3Aexample.com':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/rooms/!1234%3Aexample.com/send/m.room.message/1234': '/client/v3/rooms/!1234%3Aexample.com/send/m.room.message/1234':
(var reqI) => { (var reqI) => {
'event_id': '\$event${FakeMatrixApi.eventCounter++}', 'event_id': '\$event${FakeMatrixApi.eventCounter++}',
@ -2309,27 +2309,27 @@ class FakeMatrixApi extends MockClient {
'event_id': '\$event${FakeMatrixApi.eventCounter++}', 'event_id': '\$event${FakeMatrixApi.eventCounter++}',
}, },
'/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/tags/m.favourite': '/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/tags/m.favourite':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags/testtag': '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags/testtag':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/user/%40alice%3Aexample.com/account_data/test.account.data': '/client/v3/user/%40alice%3Aexample.com/account_data/test.account.data':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/best%20animal': '/client/v3/user/%40test%3AfakeServer.notExisting/account_data/best%20animal':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/user/%40alice%3Aexample.com/rooms/1234/account_data/test.account.data': '/client/v3/user/%40alice%3Aexample.com/rooms/1234/account_data/test.account.data':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/account_data/com.famedly.marked_unread': '/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/account_data/com.famedly.marked_unread':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct': '/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/user/%40othertest%3AfakeServer.notExisting/account_data/m.direct': '/client/v3/user/%40othertest%3AfakeServer.notExisting/account_data/m.direct':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/profile/%40alice%3Aexample.com/displayname': (var reqI) => '/client/v3/profile/%40alice%3Aexample.com/displayname': (var reqI) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/profile/%40alice%3Aexample.com/avatar_url': (var reqI) => '/client/v3/profile/%40alice%3Aexample.com/avatar_url': (var reqI) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/profile/%40test%3AfakeServer.notExisting/avatar_url': '/client/v3/profile/%40test%3AfakeServer.notExisting/avatar_url':
(var reqI) => <String, dynamic>{}, (var reqI) => <String, Object?>{},
'/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.encryption': '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.encryption':
(var reqI) => {'event_id': 'YUwRidLecu:example.com'}, (var reqI) => {'event_id': 'YUwRidLecu:example.com'},
'/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.avatar': '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.avatar':
@ -2355,8 +2355,8 @@ class FakeMatrixApi extends MockClient {
'event_id': '42', 'event_id': '42',
}, },
'/client/v3/directory/list/room/!localpart%3Aexample.com': (var req) => '/client/v3/directory/list/room/!localpart%3Aexample.com': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/room_keys/version/5': (var req) => <String, dynamic>{}, '/client/v3/room_keys/version/5': (var req) => <String, Object?>{},
'/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5': '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5':
(var req) => { (var req) => {
'etag': 'asdf', 'etag': 'asdf',
@ -2374,18 +2374,18 @@ class FakeMatrixApi extends MockClient {
}, },
'DELETE': { 'DELETE': {
'/unknown/token': (var req) => {'errcode': 'M_UNKNOWN_TOKEN'}, '/unknown/token': (var req) => {'errcode': 'M_UNKNOWN_TOKEN'},
'/client/v3/devices/QBUAZIFURK': (var req) => <String, dynamic>{}, '/client/v3/devices/QBUAZIFURK': (var req) => <String, Object?>{},
'/client/v3/directory/room/%23testalias%3Aexample.com': (var reqI) => '/client/v3/directory/room/%23testalias%3Aexample.com': (var reqI) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/pushrules/global/content/nocake': (var req) => '/client/v3/pushrules/global/content/nocake': (var req) =>
<String, dynamic>{}, <String, Object?>{},
'/client/v3/pushrules/global/override/!localpart%3Aserver.abc': '/client/v3/pushrules/global/override/!localpart%3Aserver.abc':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/tags/m.favourite': '/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/tags/m.favourite':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags/testtag': '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags/testtag':
(var req) => <String, dynamic>{}, (var req) => <String, Object?>{},
'/client/v3/room_keys/version/5': (var req) => <String, dynamic>{}, '/client/v3/room_keys/version/5': (var req) => <String, Object?>{},
'/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5': '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5':
(var req) => { (var req) => {
'etag': 'asdf', 'etag': 'asdf',

View File

@ -48,7 +48,7 @@ class MatrixApi extends Api {
Never unexpectedResponse(http.BaseResponse response, Uint8List body) { Never unexpectedResponse(http.BaseResponse response, Uint8List body) {
if (response.statusCode >= 400 && response.statusCode < 500) { if (response.statusCode >= 400 && response.statusCode < 500) {
final resp = json.decode(utf8.decode(body)); final resp = json.decode(utf8.decode(body));
if (resp is Map<String, dynamic>) { if (resp is Map<String, Object?>) {
throw MatrixException.fromJson(resp); throw MatrixException.fromJson(resp);
} }
} }
@ -82,12 +82,12 @@ class MatrixApi extends Api {
/// ); /// );
/// ``` /// ```
/// ///
Future<Map<String, dynamic>> request( Future<Map<String, Object?>> request(
RequestType type, RequestType type,
String action, { String action, {
dynamic data = '', dynamic data = '',
String contentType = 'application/json', String contentType = 'application/json',
Map<String, dynamic>? query, Map<String, Object?>? query,
}) async { }) async {
if (homeserver == null) { if (homeserver == null) {
throw ('No homeserver specified.'); throw ('No homeserver specified.');
@ -108,7 +108,7 @@ class MatrixApi extends Api {
} }
late http.Response resp; late http.Response resp;
Map<String, dynamic>? jsonResp = <String, dynamic>{}; Map<String, Object?>? jsonResp = <String, Object?>{};
try { try {
switch (type) { switch (type) {
case RequestType.GET: case RequestType.GET:
@ -138,7 +138,7 @@ class MatrixApi extends Api {
jsonString = '{"chunk":$jsonString}'; jsonString = '{"chunk":$jsonString}';
} }
jsonResp = jsonDecode(jsonString) jsonResp = jsonDecode(jsonString)
as Map<String, dynamic>?; // May throw FormatException as Map<String, Object?>?; // May throw FormatException
} catch (e, s) { } catch (e, s) {
throw MatrixConnectionException(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 /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-query
Future<Map<String, int>> uploadKeys( Future<Map<String, int>> uploadKeys(
{MatrixDeviceKeys? deviceKeys, {MatrixDeviceKeys? deviceKeys,
Map<String, dynamic>? oneTimeKeys, Map<String, Object?>? oneTimeKeys,
Map<String, dynamic>? fallbackKeys}) async { Map<String, Object?>? fallbackKeys}) async {
final response = await request( final response = await request(
RequestType.POST, RequestType.POST,
'/client/v3/keys/upload', '/client/v3/keys/upload',

View File

@ -29,12 +29,12 @@ class AuthenticationData {
AuthenticationData({this.type, this.session}); AuthenticationData({this.type, this.session});
AuthenticationData.fromJson(Map<String, dynamic> json) AuthenticationData.fromJson(Map<String, Object?> json)
: type = json['type'] as String?, : type = json['type'] as String?,
session = json['session'] as String?; session = json['session'] as String?;
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (type != null) data['type'] = type; if (type != null) data['type'] = type;
if (session != null) data['session'] = session; if (session != null) data['session'] = session;
return data; return data;

View File

@ -31,10 +31,10 @@ class AuthenticationIdentifier {
AuthenticationIdentifier({required this.type}); AuthenticationIdentifier({required this.type});
AuthenticationIdentifier.fromJson(Map<String, dynamic> json) AuthenticationIdentifier.fromJson(Map<String, Object?> json)
: type = json['type'] as String; : type = json['type'] as String;
factory AuthenticationIdentifier.subFromJson(Map<String, dynamic> json) { factory AuthenticationIdentifier.subFromJson(Map<String, Object?> json) {
switch (json['type']) { switch (json['type']) {
case AuthenticationIdentifierTypes.userId: case AuthenticationIdentifierTypes.userId:
return AuthenticationUserIdentifier.fromJson(json); return AuthenticationUserIdentifier.fromJson(json);
@ -47,8 +47,8 @@ class AuthenticationIdentifier {
} }
} }
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['type'] = type; data['type'] = type;
return data; return data;
} }

View File

@ -40,14 +40,14 @@ class AuthenticationPassword extends AuthenticationData {
session: session, session: session,
); );
AuthenticationPassword.fromJson(Map<String, dynamic> json) AuthenticationPassword.fromJson(Map<String, Object?> json)
: password = json['password'] as String, : password = json['password'] as String,
identifier = AuthenticationIdentifier.subFromJson( identifier = AuthenticationIdentifier.subFromJson(
json['identifier'] as Map<String, dynamic>), json['identifier'] as Map<String, Object?>),
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['password'] = password; data['password'] = password;
data['identifier'] = identifier.toJson(); data['identifier'] = identifier.toJson();

View File

@ -31,13 +31,13 @@ class AuthenticationPhoneIdentifier extends AuthenticationIdentifier {
AuthenticationPhoneIdentifier({required this.country, required this.phone}) AuthenticationPhoneIdentifier({required this.country, required this.phone})
: super(type: AuthenticationIdentifierTypes.phone); : super(type: AuthenticationIdentifierTypes.phone);
AuthenticationPhoneIdentifier.fromJson(Map<String, dynamic> json) AuthenticationPhoneIdentifier.fromJson(Map<String, Object?> json)
: country = json['country'] as String, : country = json['country'] as String,
phone = json['phone'] as String, phone = json['phone'] as String,
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['country'] = country; data['country'] = country;
data['phone'] = phone; data['phone'] = phone;

View File

@ -33,12 +33,12 @@ class AuthenticationRecaptcha extends AuthenticationData {
session: session, session: session,
); );
AuthenticationRecaptcha.fromJson(Map<String, dynamic> json) AuthenticationRecaptcha.fromJson(Map<String, Object?> json)
: response = json['response'] as String, : response = json['response'] as String,
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['response'] = response; data['response'] = response;
return data; return data;

View File

@ -32,13 +32,13 @@ class AuthenticationThirdPartyIdentifier extends AuthenticationIdentifier {
{required this.medium, required this.address}) {required this.medium, required this.address})
: super(type: AuthenticationIdentifierTypes.thirdParty); : super(type: AuthenticationIdentifierTypes.thirdParty);
AuthenticationThirdPartyIdentifier.fromJson(Map<String, dynamic> json) AuthenticationThirdPartyIdentifier.fromJson(Map<String, Object?> json)
: medium = json['medium'] as String, : medium = json['medium'] as String,
address = json['address'] as String, address = json['address'] as String,
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['medium'] = medium; data['medium'] = medium;
data['address'] = address; data['address'] = address;

View File

@ -37,16 +37,16 @@ class AuthenticationThreePidCreds extends AuthenticationData {
session: session, session: session,
); );
AuthenticationThreePidCreds.fromJson(Map<String, dynamic> json) AuthenticationThreePidCreds.fromJson(Map<String, Object?> json)
: super.fromJson(json) { : super.fromJson(json) {
final creds = json['threepid_creds']; final creds = json['threepid_creds'];
if (creds is Map<String, dynamic>) { if (creds is Map<String, Object?>) {
threepidCreds = ThreepidCreds.fromJson(creds); threepidCreds = ThreepidCreds.fromJson(creds);
} }
} }
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['threepid_creds'] = threepidCreds.toJson(); data['threepid_creds'] = threepidCreds.toJson();
return data; return data;
@ -65,14 +65,14 @@ class ThreepidCreds {
this.idServer, this.idServer,
this.idAccessToken}); this.idAccessToken});
ThreepidCreds.fromJson(Map<String, dynamic> json) ThreepidCreds.fromJson(Map<String, Object?> json)
: sid = json['sid'] as String, : sid = json['sid'] as String,
clientSecret = json['client_secret'] as String, clientSecret = json['client_secret'] as String,
idServer = json['id_server'] as String?, idServer = json['id_server'] as String?,
idAccessToken = json['id_access_token'] as String?; idAccessToken = json['id_access_token'] as String?;
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['sid'] = sid; data['sid'] = sid;
data['client_secret'] = clientSecret; data['client_secret'] = clientSecret;
if (idServer != null) data['id_server'] = idServer; if (idServer != null) data['id_server'] = idServer;

View File

@ -36,13 +36,13 @@ class AuthenticationToken extends AuthenticationData {
session: session, session: session,
); );
AuthenticationToken.fromJson(Map<String, dynamic> json) AuthenticationToken.fromJson(Map<String, Object?> json)
: token = json['token'] as String, : token = json['token'] as String,
txnId = json['txn_id'] as String?, txnId = json['txn_id'] as String?,
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['token'] = token; data['token'] = token;
data['txn_id'] = txnId; data['txn_id'] = txnId;

View File

@ -30,12 +30,12 @@ class AuthenticationUserIdentifier extends AuthenticationIdentifier {
AuthenticationUserIdentifier({required this.user}) AuthenticationUserIdentifier({required this.user})
: super(type: AuthenticationIdentifierTypes.userId); : super(type: AuthenticationIdentifierTypes.userId);
AuthenticationUserIdentifier.fromJson(Map<String, dynamic> json) AuthenticationUserIdentifier.fromJson(Map<String, Object?> json)
: user = json['user'] as String, : user = json['user'] as String,
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['user'] = user; data['user'] = user;
return data; return data;

View File

@ -25,19 +25,19 @@ import '../utils/map_copy_extension.dart';
class BasicEvent { class BasicEvent {
String type; String type;
Map<String, dynamic> content; Map<String, Object?> content;
BasicEvent({ BasicEvent({
required this.type, required this.type,
required this.content, required this.content,
}); });
BasicEvent.fromJson(Map<String, dynamic> json) BasicEvent.fromJson(Map<String, Object?> json)
: type = json['type'] as String, : type = json['type'] as String,
content = (json['content'] as Map<String, dynamic>).copy(); content = (json['content'] as Map<String, Object?>).copy();
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['type'] = type; data['type'] = type;
data['content'] = content; data['content'] = content;
return data; return data;

View File

@ -28,16 +28,16 @@ class BasicEventWithSender extends BasicEvent {
BasicEventWithSender( BasicEventWithSender(
{required String type, {required String type,
required Map<String, dynamic> content, required Map<String, Object?> content,
required this.senderId}) required this.senderId})
: super(type: type, content: content); : super(type: type, content: content);
BasicEventWithSender.fromJson(Map<String, dynamic> json) BasicEventWithSender.fromJson(Map<String, Object?> json)
: senderId = json['sender'] as String, : senderId = json['sender'] as String,
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['sender'] = senderId; data['sender'] = senderId;
return data; return data;

View File

@ -28,19 +28,19 @@ class BasicRoomEvent extends BasicEvent {
BasicRoomEvent({ BasicRoomEvent({
this.roomId, this.roomId,
required Map<String, dynamic> content, required Map<String, Object?> content,
required String type, required String type,
}) : super( }) : super(
content: content, content: content,
type: type, type: type,
); );
BasicRoomEvent.fromJson(Map<String, dynamic> json) BasicRoomEvent.fromJson(Map<String, Object?> json)
: roomId = json['room_id'] as String?, : roomId = json['room_id'] as String?,
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
if (roomId != null) data['room_id'] = roomId; if (roomId != null) data['room_id'] = roomId;
return data; return data;

View File

@ -28,7 +28,7 @@ class ChildrenState extends StrippedStateEvent {
ChildrenState({ ChildrenState({
required String type, required String type,
required Map<String, dynamic> content, required Map<String, Object?> content,
required String senderId, required String senderId,
required String stateKey, required String stateKey,
required this.originServerTs, required this.originServerTs,
@ -38,13 +38,13 @@ class ChildrenState extends StrippedStateEvent {
senderId: senderId, senderId: senderId,
stateKey: stateKey); stateKey: stateKey);
ChildrenState.fromJson(Map<String, dynamic> json) ChildrenState.fromJson(Map<String, Object?> json)
: originServerTs = DateTime.fromMillisecondsSinceEpoch( : originServerTs = DateTime.fromMillisecondsSinceEpoch(
json['origin_server_ts'] as int), json['origin_server_ts'] as int),
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch; data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch;
return data; return data;

View File

@ -35,7 +35,7 @@ class ForwardedRoomKeyContent extends RoomKeyContent {
String senderClaimedEd25519Key; String senderClaimedEd25519Key;
List<String> forwardingCurve25519KeyChain; List<String> forwardingCurve25519KeyChain;
ForwardedRoomKeyContent.fromJson(Map<String, dynamic> json) ForwardedRoomKeyContent.fromJson(Map<String, Object?> json)
: senderKey = json.tryGet('sender_key', TryGet.required) ?? '', : senderKey = json.tryGet('sender_key', TryGet.required) ?? '',
senderClaimedEd25519Key = senderClaimedEd25519Key =
json.tryGet('sender_claimed_ed25519_key', TryGet.required) ?? '', json.tryGet('sender_claimed_ed25519_key', TryGet.required) ?? '',
@ -45,7 +45,7 @@ class ForwardedRoomKeyContent extends RoomKeyContent {
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['sender_key'] = senderKey; data['sender_key'] = senderKey;
data['sender_claimed_ed25519_key'] = senderClaimedEd25519Key; data['sender_claimed_ed25519_key'] = senderClaimedEd25519Key;

View File

@ -66,31 +66,31 @@ List<String> imagePackUsageToJson(
class ImagePackContent { class ImagePackContent {
// we want to preserve potential custom keys in this object // we want to preserve potential custom keys in this object
final Map<String, dynamic> _json; final Map<String, Object?> _json;
Map<String, ImagePackImageContent> images; Map<String, ImagePackImageContent> images;
ImagePackPackContent pack; ImagePackPackContent pack;
ImagePackContent({required this.images, required this.pack}) : _json = {}; ImagePackContent({required this.images, required this.pack}) : _json = {};
ImagePackContent.fromJson(Map<String, dynamic> json) ImagePackContent.fromJson(Map<String, Object?> json)
: _json = Map.fromEntries(json.entries.where( : _json = Map.fromEntries(json.entries.where(
(e) => !['images', 'pack', 'emoticons', 'short'].contains(e.key))), (e) => !['images', 'pack', 'emoticons', 'short'].contains(e.key))),
pack = ImagePackPackContent.fromJson( pack = ImagePackPackContent.fromJson(
json.tryGetMap<String, dynamic>('pack') ?? {}), json.tryGetMap<String, Object?>('pack') ?? {}),
images = json.tryGetMap<String, dynamic>('images')?.catchMap((k, v) => images = json.tryGetMap<String, Object?>('images')?.catchMap((k, v) =>
MapEntry( MapEntry(
k, k,
ImagePackImageContent.fromJson( ImagePackImageContent.fromJson(
v as Map<String, dynamic>))) ?? v as Map<String, Object?>))) ??
// the "emoticons" key needs a small migration on the key, ":string:" --> "string" // the "emoticons" key needs a small migration on the key, ":string:" --> "string"
json.tryGetMap<String, dynamic>('emoticons')?.catchMap((k, v) => json.tryGetMap<String, Object?>('emoticons')?.catchMap((k, v) =>
MapEntry( MapEntry(
k.startsWith(':') && k.endsWith(':') k.startsWith(':') && k.endsWith(':')
? k.substring(1, k.length - 1) ? k.substring(1, k.length - 1)
: k, : k,
ImagePackImageContent.fromJson( ImagePackImageContent.fromJson(
v as Map<String, dynamic>))) ?? v as Map<String, Object?>))) ??
// the "short" key was still just a map from shortcode to mxc uri // the "short" key was still just a map from shortcode to mxc uri
json.tryGetMap<String, String>('short')?.catchMap((k, v) => json.tryGetMap<String, String>('short')?.catchMap((k, v) =>
MapEntry( MapEntry(
@ -100,7 +100,7 @@ class ImagePackContent {
ImagePackImageContent(url: Uri.parse(v)))) ?? ImagePackImageContent(url: Uri.parse(v)))) ??
{}; {};
Map<String, dynamic> toJson() => { Map<String, Object?> toJson() => {
..._json, ..._json,
'images': images.map((k, v) => MapEntry(k, v.toJson())), 'images': images.map((k, v) => MapEntry(k, v.toJson())),
'pack': pack.toJson(), 'pack': pack.toJson(),
@ -109,25 +109,25 @@ class ImagePackContent {
class ImagePackImageContent { class ImagePackImageContent {
// we want to preserve potential custom keys in this object // we want to preserve potential custom keys in this object
final Map<String, dynamic> _json; final Map<String, Object?> _json;
Uri url; Uri url;
String? body; String? body;
Map<String, dynamic>? info; Map<String, Object?>? info;
List<ImagePackUsage>? usage; List<ImagePackUsage>? usage;
ImagePackImageContent({required this.url, this.body, this.info, this.usage}) ImagePackImageContent({required this.url, this.body, this.info, this.usage})
: _json = {}; : _json = {};
ImagePackImageContent.fromJson(Map<String, dynamic> json) ImagePackImageContent.fromJson(Map<String, Object?> json)
: _json = Map.fromEntries(json.entries : _json = Map.fromEntries(json.entries
.where((e) => !['url', 'body', 'info'].contains(e.key))), .where((e) => !['url', 'body', 'info'].contains(e.key))),
url = Uri.parse(json['url'] as String), url = Uri.parse(json['url'] as String),
body = json.tryGet('body'), body = json.tryGet('body'),
info = json.tryGetMap<String, dynamic>('info'), info = json.tryGetMap<String, Object?>('info'),
usage = imagePackUsageFromJson(json.tryGetList<String>('usage')); usage = imagePackUsageFromJson(json.tryGetList<String>('usage'));
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
return { return {
...Map.from(_json)..remove('usage'), ...Map.from(_json)..remove('usage'),
'url': url.toString(), 'url': url.toString(),
@ -141,7 +141,7 @@ class ImagePackImageContent {
class ImagePackPackContent { class ImagePackPackContent {
// we want to preserve potential custom keys in this object // we want to preserve potential custom keys in this object
final Map<String, dynamic> _json; final Map<String, Object?> _json;
String? displayName; String? displayName;
Uri? avatarUrl; Uri? avatarUrl;
@ -152,7 +152,7 @@ class ImagePackPackContent {
{this.displayName, this.avatarUrl, this.usage, this.attribution}) {this.displayName, this.avatarUrl, this.usage, this.attribution})
: _json = {}; : _json = {};
ImagePackPackContent.fromJson(Map<String, dynamic> json) ImagePackPackContent.fromJson(Map<String, Object?> json)
: _json = Map.fromEntries(json.entries.where((e) => : _json = Map.fromEntries(json.entries.where((e) =>
!['display_name', 'avatar_url', 'attribution'].contains(e.key))), !['display_name', 'avatar_url', 'attribution'].contains(e.key))),
displayName = json.tryGet('display_name'), displayName = json.tryGet('display_name'),
@ -161,7 +161,7 @@ class ImagePackPackContent {
usage = imagePackUsageFromJson(json.tryGetList<String>('usage')), usage = imagePackUsageFromJson(json.tryGetList<String>('usage')),
attribution = json.tryGet('attribution'); attribution = json.tryGet('attribution');
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
return { return {
...Map.from(_json)..remove('usage'), ...Map.from(_json)..remove('usage'),
if (displayName != null) 'display_name': displayName, if (displayName != null) 'display_name': displayName,

View File

@ -25,7 +25,7 @@ import '../../utils/try_get_map_extension.dart';
class OlmPlaintextPayload { class OlmPlaintextPayload {
String? type; String? type;
Map<String, dynamic>? content; Map<String, Object?>? content;
String? sender; String? sender;
String? recipient; String? recipient;
Map<String, String>? recipientKeys; Map<String, String>? recipientKeys;
@ -40,7 +40,7 @@ class OlmPlaintextPayload {
this.keys, this.keys,
}) : super(); }) : super();
factory OlmPlaintextPayload.fromJson(Map<String, dynamic> json) => factory OlmPlaintextPayload.fromJson(Map<String, Object?> json) =>
OlmPlaintextPayload( OlmPlaintextPayload(
sender: json.tryGet('sender', TryGet.required), sender: json.tryGet('sender', TryGet.required),
type: json.tryGet('type', TryGet.required), type: json.tryGet('type', TryGet.required),
@ -50,8 +50,8 @@ class OlmPlaintextPayload {
keys: json.tryGetMap('keys', TryGet.required), keys: json.tryGetMap('keys', TryGet.required),
); );
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (type != null) data['type'] = type; if (type != null) data['type'] = type;
if (sender != null) data['sender'] = sender; if (sender != null) data['sender'] = sender;
if (content != null) data['content'] = content; if (content != null) data['content'] = content;

View File

@ -39,7 +39,7 @@ class RoomEncryptedContent {
String? ciphertextMegolm; String? ciphertextMegolm;
Map<String, CiphertextInfo>? ciphertextOlm; Map<String, CiphertextInfo>? ciphertextOlm;
RoomEncryptedContent.fromJson(Map<String, dynamic> json) RoomEncryptedContent.fromJson(Map<String, Object?> json)
: algorithm = json.tryGet('algorithm', TryGet.required) ?? '', : algorithm = json.tryGet('algorithm', TryGet.required) ?? '',
senderKey = json.tryGet('sender_key', TryGet.required) ?? '', senderKey = json.tryGet('sender_key', TryGet.required) ?? '',
deviceId = json.tryGet('device_id'), deviceId = json.tryGet('device_id'),
@ -47,12 +47,12 @@ class RoomEncryptedContent {
ciphertextMegolm = json.tryGet('ciphertext', TryGet.silent), ciphertextMegolm = json.tryGet('ciphertext', TryGet.silent),
// filter out invalid/incomplete CiphertextInfos // filter out invalid/incomplete CiphertextInfos
ciphertextOlm = json ciphertextOlm = json
.tryGet<Map<String, dynamic>>('ciphertext', TryGet.silent) .tryGet<Map<String, Object?>>('ciphertext', TryGet.silent)
?.catchMap((k, v) => MapEntry( ?.catchMap((k, v) => MapEntry(
k, CiphertextInfo.fromJson(v as Map<String, dynamic>))); k, CiphertextInfo.fromJson(v as Map<String, Object?>)));
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['algorithm'] = algorithm; data['algorithm'] = algorithm;
data['sender_key'] = senderKey; data['sender_key'] = senderKey;
if (deviceId != null) { if (deviceId != null) {
@ -80,12 +80,12 @@ class CiphertextInfo {
String body; String body;
int type; int type;
CiphertextInfo.fromJson(Map<String, dynamic> json) CiphertextInfo.fromJson(Map<String, Object?> json)
: body = json['body'] as String, : body = json['body'] as String,
type = json['type'] as int; type = json['type'] as int;
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['body'] = body; data['body'] = body;
data['type'] = type; data['type'] = type;
return data; return data;

View File

@ -34,13 +34,13 @@ class RoomEncryptionContent {
int? rotationPeriodMs; int? rotationPeriodMs;
int? rotationPeriodMsgs; int? rotationPeriodMsgs;
RoomEncryptionContent.fromJson(Map<String, dynamic> json) RoomEncryptionContent.fromJson(Map<String, Object?> json)
: algorithm = json.tryGet('algorithm', TryGet.required) ?? '', : algorithm = json.tryGet('algorithm', TryGet.required) ?? '',
rotationPeriodMs = json.tryGet('rotation_period_ms'), rotationPeriodMs = json.tryGet('rotation_period_ms'),
rotationPeriodMsgs = json.tryGet('rotation_period_msgs'); rotationPeriodMsgs = json.tryGet('rotation_period_msgs');
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['algorithm'] = algorithm; data['algorithm'] = algorithm;
if (rotationPeriodMs != null) { if (rotationPeriodMs != null) {
data['rotation_period_ms'] = rotationPeriodMs; data['rotation_period_ms'] = rotationPeriodMs;

View File

@ -40,14 +40,14 @@ class RoomKeyContent {
required this.sessionId, required this.sessionId,
required this.sessionKey}); required this.sessionKey});
RoomKeyContent.fromJson(Map<String, dynamic> json) RoomKeyContent.fromJson(Map<String, Object?> json)
: algorithm = json.tryGet('algorithm', TryGet.required) ?? '', : algorithm = json.tryGet('algorithm', TryGet.required) ?? '',
roomId = json.tryGet('room_id', TryGet.required) ?? '', roomId = json.tryGet('room_id', TryGet.required) ?? '',
sessionId = json.tryGet('session_id', TryGet.required) ?? '', sessionId = json.tryGet('session_id', TryGet.required) ?? '',
sessionKey = json.tryGet('session_key', TryGet.required) ?? ''; sessionKey = json.tryGet('session_key', TryGet.required) ?? '';
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['algorithm'] = algorithm; data['algorithm'] = algorithm;
data['room_id'] = roomId; data['room_id'] = roomId;
data['session_id'] = sessionId; data['session_id'] = sessionId;

View File

@ -35,8 +35,8 @@ class RoomKeyRequestContent {
String requestingDeviceId; String requestingDeviceId;
String requestId; String requestId;
RoomKeyRequestContent.fromJson(Map<String, dynamic> json) RoomKeyRequestContent.fromJson(Map<String, Object?> json)
: body = ((Map<String, dynamic>? x) => x != null : body = ((Map<String, Object?>? x) => x != null
? RequestedKeyInfo.fromJson(x) ? RequestedKeyInfo.fromJson(x)
: null)(json.tryGet('body')), : null)(json.tryGet('body')),
action = json.tryGet('action', TryGet.required) ?? '', action = json.tryGet('action', TryGet.required) ?? '',
@ -44,8 +44,8 @@ class RoomKeyRequestContent {
json.tryGet('requesting_device_id', TryGet.required) ?? '', json.tryGet('requesting_device_id', TryGet.required) ?? '',
requestId = json.tryGet('request_id', TryGet.required) ?? ''; requestId = json.tryGet('request_id', TryGet.required) ?? '';
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (body != null) data['body'] = body!.toJson(); if (body != null) data['body'] = body!.toJson();
data['action'] = action; data['action'] = action;
data['requesting_device_id'] = requestingDeviceId; data['requesting_device_id'] = requestingDeviceId;
@ -66,14 +66,14 @@ class RequestedKeyInfo {
required this.sessionId, required this.sessionId,
required this.senderKey}); required this.senderKey});
RequestedKeyInfo.fromJson(Map<String, dynamic> json) RequestedKeyInfo.fromJson(Map<String, Object?> json)
: algorithm = json.tryGet('algorithm', TryGet.required) ?? '', : algorithm = json.tryGet('algorithm', TryGet.required) ?? '',
roomId = json.tryGet('room_id', TryGet.required) ?? '', roomId = json.tryGet('room_id', TryGet.required) ?? '',
sessionId = json.tryGet('session_id', TryGet.required) ?? '', sessionId = json.tryGet('session_id', TryGet.required) ?? '',
senderKey = json.tryGet('sender_key', TryGet.required) ?? ''; senderKey = json.tryGet('sender_key', TryGet.required) ?? '';
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['algorithm'] = algorithm; data['algorithm'] = algorithm;
data['room_id'] = roomId; data['room_id'] = roomId;
data['session_id'] = sessionId; data['session_id'] = sessionId;

View File

@ -35,11 +35,11 @@ class SecretStorageDefaultKeyContent {
SecretStorageDefaultKeyContent({required this.key}); SecretStorageDefaultKeyContent({required this.key});
SecretStorageDefaultKeyContent.fromJson(Map<String, dynamic> json) SecretStorageDefaultKeyContent.fromJson(Map<String, Object?> json)
: key = json.tryGet('key', TryGet.required); : key = json.tryGet('key', TryGet.required);
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (key != null) data['key'] = key; if (key != null) data['key'] = key;
return data; return data;
} }

View File

@ -37,16 +37,16 @@ class SecretStorageKeyContent {
SecretStorageKeyContent(); SecretStorageKeyContent();
SecretStorageKeyContent.fromJson(Map<String, dynamic> json) SecretStorageKeyContent.fromJson(Map<String, Object?> json)
: passphrase = ((Map<String, dynamic>? x) => x != null : passphrase = ((Map<String, Object?>? x) => x != null
? PassphraseInfo.fromJson(x) ? PassphraseInfo.fromJson(x)
: null)(json.tryGet('passphrase')), : null)(json.tryGet('passphrase')),
iv = json.tryGet('iv'), iv = json.tryGet('iv'),
mac = json.tryGet('mac'), mac = json.tryGet('mac'),
algorithm = json.tryGet('algorithm'); algorithm = json.tryGet('algorithm');
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (passphrase != null) data['passphrase'] = passphrase!.toJson(); if (passphrase != null) data['passphrase'] = passphrase!.toJson();
if (iv != null) data['iv'] = iv; if (iv != null) data['iv'] = iv;
if (mac != null) data['mac'] = mac; if (mac != null) data['mac'] = mac;
@ -69,14 +69,14 @@ class PassphraseInfo {
required this.iterations, required this.iterations,
this.bits}); this.bits});
PassphraseInfo.fromJson(Map<String, dynamic> json) PassphraseInfo.fromJson(Map<String, Object?> json)
: algorithm = json.tryGet('algorithm', TryGet.required), : algorithm = json.tryGet('algorithm', TryGet.required),
salt = json.tryGet('salt', TryGet.required), salt = json.tryGet('salt', TryGet.required),
iterations = json.tryGet('iterations', TryGet.required), iterations = json.tryGet('iterations', TryGet.required),
bits = json.tryGet('bits'); bits = json.tryGet('bits');
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['algorithm'] = algorithm; data['algorithm'] = algorithm;
data['salt'] = salt; data['salt'] = salt;
data['iterations'] = iterations; data['iterations'] = iterations;

View File

@ -33,13 +33,13 @@ class TombstoneContent {
String body; String body;
String replacementRoom; String replacementRoom;
TombstoneContent.fromJson(Map<String, dynamic> json) TombstoneContent.fromJson(Map<String, Object?> json)
: body = json.tryGet('body', TryGet.required) ?? '', : body = json.tryGet('body', TryGet.required) ?? '',
replacementRoom = replacementRoom =
json.tryGet('replacement_room', TryGet.required) ?? ''; json.tryGet('replacement_room', TryGet.required) ?? '';
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['body'] = body; data['body'] = body;
data['replacement_room'] = replacementRoom; data['replacement_room'] = replacementRoom;
return data; return data;

View File

@ -28,13 +28,13 @@ class MatrixEvent extends StrippedStateEvent {
String eventId; String eventId;
String? roomId; String? roomId;
DateTime originServerTs; DateTime originServerTs;
Map<String, dynamic>? unsigned; Map<String, Object?>? unsigned;
Map<String, dynamic>? prevContent; Map<String, Object?>? prevContent;
String? redacts; String? redacts;
MatrixEvent({ MatrixEvent({
required String type, required String type,
required Map<String, dynamic> content, required Map<String, Object?> content,
required String senderId, required String senderId,
String? stateKey, String? stateKey,
required this.eventId, required this.eventId,
@ -49,18 +49,18 @@ class MatrixEvent extends StrippedStateEvent {
senderId: senderId, senderId: senderId,
stateKey: stateKey); stateKey: stateKey);
MatrixEvent.fromJson(Map<String, dynamic> json) MatrixEvent.fromJson(Map<String, Object?> json)
: eventId = json['event_id'] as String, : eventId = json['event_id'] as String,
roomId = json['room_id'] as String?, roomId = json['room_id'] as String?,
originServerTs = DateTime.fromMillisecondsSinceEpoch( originServerTs = DateTime.fromMillisecondsSinceEpoch(
json['origin_server_ts'] as int), json['origin_server_ts'] as int),
unsigned = (json['unsigned'] as Map<String, dynamic>?)?.copy(), unsigned = (json['unsigned'] as Map<String, Object?>?)?.copy(),
prevContent = (json['prev_content'] as Map<String, dynamic>?)?.copy(), prevContent = (json['prev_content'] as Map<String, Object?>?)?.copy(),
redacts = json['redacts'] as String?, redacts = json['redacts'] as String?,
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['event_id'] = eventId; data['event_id'] = eventId;
data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch; data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch;

View File

@ -63,7 +63,7 @@ enum MatrixError {
/// Represents a special response from the Homeserver for errors. /// Represents a special response from the Homeserver for errors.
class MatrixException implements Exception { class MatrixException implements Exception {
final Map<String, dynamic> raw; final Map<String, Object?> raw;
/// The unique identifier for this error. /// The unique identifier for this error.
String get errcode => String get errcode =>
@ -81,9 +81,9 @@ class MatrixException implements Exception {
http.Response? response; http.Response? response;
MatrixException(http.Response this.response) MatrixException(http.Response this.response)
: raw = json.decode(response.body) as Map<String, dynamic>; : raw = json.decode(response.body) as Map<String, Object?>;
MatrixException.fromJson(Map<String, dynamic> content) : raw = content; MatrixException.fromJson(Map<String, Object?> content) : raw = content;
@override @override
String toString() => '$errcode: $errorMessage'; String toString() => '$errcode: $errorMessage';
@ -110,7 +110,7 @@ class MatrixException implements Exception {
/// doesn't need additional authentication, then this is null. /// doesn't need additional authentication, then this is null.
List<AuthenticationFlow>? get authenticationFlows => raw List<AuthenticationFlow>? get authenticationFlows => raw
.tryGet<List<dynamic>>('flows') .tryGet<List<dynamic>>('flows')
?.whereType<Map<String, dynamic>>() ?.whereType<Map<String, Object?>>()
.map((flow) => flow['stages']) .map((flow) => flow['stages'])
.whereType<List<dynamic>>() .whereType<List<dynamic>>()
.map((stages) => .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 /// 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 /// 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. /// dictionary. For example, the public part of an OAuth client ID could be given here.
Map<String, dynamic>? get authenticationParams => Map<String, Object?>? get authenticationParams =>
raw.tryGetMap<String, dynamic>('params'); raw.tryGetMap<String, Object?>('params');
/// Returns the list of already completed authentication flows from previous requests. /// Returns the list of already completed authentication flows from previous requests.
List<String> get completedAuthenticationFlows => List<String> get completedAuthenticationFlows =>

View File

@ -30,25 +30,25 @@ abstract class MatrixSignableKey {
Map<String, String> keys; Map<String, String> keys;
Map<String, Map<String, String>>? signatures; Map<String, Map<String, String>>? signatures;
Map<String, dynamic>? unsigned; Map<String, Object?>? unsigned;
MatrixSignableKey(this.userId, this.keys, this.signatures, {this.unsigned}); MatrixSignableKey(this.userId, this.keys, this.signatures, {this.unsigned});
// This object is used for signing so we need the raw json too // This object is used for signing so we need the raw json too
Map<String, dynamic>? _json; Map<String, Object?>? _json;
MatrixSignableKey.fromJson(Map<String, dynamic> json) MatrixSignableKey.fromJson(Map<String, Object?> json)
: _json = json, : _json = json,
userId = json['user_id'] as String, userId = json['user_id'] as String,
keys = Map<String, String>.from(json['keys'] as Map<String, dynamic>), keys = Map<String, String>.from(json['keys'] as Map<String, Object?>),
// we need to manually copy to ensure that our map is Map<String, Map<String, String>> // we need to manually copy to ensure that our map is Map<String, Map<String, String>>
signatures = (() { signatures = (() {
final orig = json.tryGetMap<String, dynamic>('signatures'); final orig = json.tryGetMap<String, Object?>('signatures');
final res = <String, Map<String, String>>{}; final res = <String, Map<String, String>>{};
for (final entry for (final entry
in (orig?.entries ?? <MapEntry<String, dynamic>>[])) { in (orig?.entries ?? <MapEntry<String, Object?>>[])) {
final deviceSigs = entry.value; final deviceSigs = entry.value;
if (deviceSigs is Map<String, dynamic>) { if (deviceSigs is Map<String, Object?>) {
for (final nestedEntry in deviceSigs.entries) { for (final nestedEntry in deviceSigs.entries) {
final nestedValue = nestedEntry.value; final nestedValue = nestedEntry.value;
if (nestedValue is String) { if (nestedValue is String) {
@ -60,10 +60,10 @@ abstract class MatrixSignableKey {
} }
return res; return res;
}()), }()),
unsigned = json.tryGetMap<String, dynamic>('unsigned')?.copy(); unsigned = json.tryGetMap<String, Object?>('unsigned')?.copy();
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = _json ?? <String, dynamic>{}; final data = _json ?? <String, Object?>{};
data['user_id'] = userId; data['user_id'] = userId;
data['keys'] = keys; data['keys'] = keys;
@ -87,19 +87,19 @@ class MatrixCrossSigningKey extends MatrixSignableKey {
this.usage, this.usage,
Map<String, String> keys, Map<String, String> keys,
Map<String, Map<String, String>> signatures, { Map<String, Map<String, String>> signatures, {
Map<String, dynamic>? unsigned, Map<String, Object?>? unsigned,
}) : super(userId, keys, signatures, unsigned: unsigned); }) : super(userId, keys, signatures, unsigned: unsigned);
@override @override
String? get identifier => keys.values.first; String? get identifier => keys.values.first;
@override @override
MatrixCrossSigningKey.fromJson(Map<String, dynamic> json) MatrixCrossSigningKey.fromJson(Map<String, Object?> json)
: usage = json.tryGetList<String>('usage') ?? [], : usage = json.tryGetList<String>('usage') ?? [],
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['usage'] = usage; data['usage'] = usage;
return data; return data;
@ -119,20 +119,20 @@ class MatrixDeviceKeys extends MatrixSignableKey {
this.algorithms, this.algorithms,
Map<String, String> keys, Map<String, String> keys,
Map<String, Map<String, String>> signatures, { Map<String, Map<String, String>> signatures, {
Map<String, dynamic>? unsigned, Map<String, Object?>? unsigned,
}) : super(userId, keys, signatures, unsigned: unsigned); }) : super(userId, keys, signatures, unsigned: unsigned);
@override @override
String? get identifier => deviceId; String? get identifier => deviceId;
@override @override
MatrixDeviceKeys.fromJson(Map<String, dynamic> json) MatrixDeviceKeys.fromJson(Map<String, Object?> json)
: algorithms = json.tryGetList<String>('algorithms') ?? [], : algorithms = json.tryGetList<String>('algorithms') ?? [],
deviceId = json['device_id'] as String, deviceId = json['device_id'] as String,
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['device_id'] = deviceId; data['device_id'] = deviceId;
data['algorithms'] = algorithms; data['algorithms'] = algorithms;

View File

@ -27,8 +27,8 @@ import 'presence_content.dart';
class Presence extends BasicEventWithSender { class Presence extends BasicEventWithSender {
PresenceContent presence; PresenceContent presence;
Presence.fromJson(Map<String, dynamic> json) Presence.fromJson(Map<String, Object?> json)
: presence = : presence =
PresenceContent.fromJson(json['content'] as Map<String, dynamic>), PresenceContent.fromJson(json['content'] as Map<String, Object?>),
super.fromJson(json); super.fromJson(json);
} }

View File

@ -29,15 +29,15 @@ class PresenceContent {
String? statusMsg; String? statusMsg;
bool? currentlyActive; bool? currentlyActive;
PresenceContent.fromJson(Map<String, dynamic> json) PresenceContent.fromJson(Map<String, Object?> json)
: presence = PresenceType.values.firstWhere( : presence = PresenceType.values.firstWhere(
(p) => p.toString().split('.').last == json['presence']), (p) => p.toString().split('.').last == json['presence']),
lastActiveAgo = json.tryGet<int>('last_active_ago'), lastActiveAgo = json.tryGet<int>('last_active_ago'),
statusMsg = json.tryGet<String>('status_msg'), statusMsg = json.tryGet<String>('status_msg'),
currentlyActive = json.tryGet<bool>('currently_active'); currentlyActive = json.tryGet<bool>('currently_active');
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['presence'] = presence.toString().split('.').last; data['presence'] = presence.toString().split('.').last;
if (lastActiveAgo != null) { if (lastActiveAgo != null) {
data['last_active_ago'] = lastActiveAgo; data['last_active_ago'] = lastActiveAgo;

View File

@ -27,7 +27,7 @@ class RoomKeysSingleKey {
int firstMessageIndex; int firstMessageIndex;
int forwardedCount; int forwardedCount;
bool isVerified; bool isVerified;
Map<String, dynamic> sessionData; Map<String, Object?> sessionData;
RoomKeysSingleKey( RoomKeysSingleKey(
{required this.firstMessageIndex, {required this.firstMessageIndex,
@ -35,14 +35,14 @@ class RoomKeysSingleKey {
required this.isVerified, required this.isVerified,
required this.sessionData}); required this.sessionData});
RoomKeysSingleKey.fromJson(Map<String, dynamic> json) RoomKeysSingleKey.fromJson(Map<String, Object?> json)
: firstMessageIndex = json['first_message_index'] as int, : firstMessageIndex = json['first_message_index'] as int,
forwardedCount = json['forwarded_count'] as int, forwardedCount = json['forwarded_count'] as int,
isVerified = json['is_verified'] as bool, isVerified = json['is_verified'] as bool,
sessionData = json['session_data'] as Map<String, dynamic>; sessionData = json['session_data'] as Map<String, Object?>;
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['first_message_index'] = firstMessageIndex; data['first_message_index'] = firstMessageIndex;
data['forwarded_count'] = forwardedCount; data['forwarded_count'] = forwardedCount;
data['is_verified'] = isVerified; data['is_verified'] = isVerified;
@ -56,12 +56,12 @@ class RoomKeysRoom {
RoomKeysRoom({required this.sessions}); RoomKeysRoom({required this.sessions});
RoomKeysRoom.fromJson(Map<String, dynamic> json) RoomKeysRoom.fromJson(Map<String, Object?> json)
: sessions = (json['sessions'] as Map<String, dynamic>).map((k, v) => : sessions = (json['sessions'] as Map<String, Object?>).map((k, v) =>
MapEntry(k, RoomKeysSingleKey.fromJson(v as Map<String, dynamic>))); MapEntry(k, RoomKeysSingleKey.fromJson(v as Map<String, Object?>)));
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['sessions'] = sessions.map((k, v) => MapEntry(k, v.toJson())); data['sessions'] = sessions.map((k, v) => MapEntry(k, v.toJson()));
return data; return data;
} }
@ -71,13 +71,13 @@ class RoomKeysUpdateResponse {
String etag; String etag;
int count; int count;
RoomKeysUpdateResponse.fromJson(Map<String, dynamic> json) RoomKeysUpdateResponse.fromJson(Map<String, Object?> json)
: etag = json.tryGet<String>('etag') ?? : etag = json.tryGet<String>('etag') ??
'', // synapse replies an int but docs say string? '', // synapse replies an int but docs say string?
count = json.tryGet<int>('count') ?? 0; count = json.tryGet<int>('count') ?? 0;
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['etag'] = etag; data['etag'] = etag;
data['count'] = count; data['count'] = count;
return data; return data;

View File

@ -26,15 +26,15 @@ class RoomSummary {
int? mJoinedMemberCount; int? mJoinedMemberCount;
int? mInvitedMemberCount; int? mInvitedMemberCount;
RoomSummary.fromJson(Map<String, dynamic> json) RoomSummary.fromJson(Map<String, Object?> json)
: mHeroes = json['m.heroes'] != null : mHeroes = json['m.heroes'] != null
? List<String>.from(json['m.heroes'] as List) ? List<String>.from(json['m.heroes'] as List)
: null, : null,
mJoinedMemberCount = json['m.joined_member_count'] as int?, mJoinedMemberCount = json['m.joined_member_count'] as int?,
mInvitedMemberCount = json['m.invited_member_count'] as int?; mInvitedMemberCount = json['m.invited_member_count'] as int?;
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (mHeroes != null) { if (mHeroes != null) {
data['m.heroes'] = mHeroes; data['m.heroes'] = mHeroes;
} }

View File

@ -28,17 +28,17 @@ class StrippedStateEvent extends BasicEventWithSender {
StrippedStateEvent( StrippedStateEvent(
{required String type, {required String type,
required Map<String, dynamic> content, required Map<String, Object?> content,
required String senderId, required String senderId,
this.stateKey}) this.stateKey})
: super(type: type, content: content, senderId: senderId); : super(type: type, content: content, senderId: senderId);
StrippedStateEvent.fromJson(Map<String, dynamic> json) StrippedStateEvent.fromJson(Map<String, Object?> json)
: stateKey = json.tryGet<String>('state_key'), : stateKey = json.tryGet<String>('state_key'),
super.fromJson(json); super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = super.toJson(); final data = super.toJson();
data['state_key'] = stateKey; data['state_key'] = stateKey;
return data; return data;

View File

@ -44,27 +44,27 @@ class SyncUpdate {
this.deviceUnusedFallbackKeyTypes, this.deviceUnusedFallbackKeyTypes,
}); });
SyncUpdate.fromJson(Map<String, dynamic> json) SyncUpdate.fromJson(Map<String, Object?> json)
: nextBatch = json['next_batch'] as String, : nextBatch = json['next_batch'] as String,
rooms = (() { rooms = (() {
final temp = json.tryGetMap<String, dynamic>('rooms'); final temp = json.tryGetMap<String, Object?>('rooms');
return temp != null ? RoomsUpdate.fromJson(temp) : null; return temp != null ? RoomsUpdate.fromJson(temp) : null;
}()), }()),
presence = json presence = json
.tryGetMap<String, List<dynamic>>('presence')?['events'] .tryGetMap<String, List<dynamic>>('presence')?['events']
?.map((i) => Presence.fromJson(i as Map<String, dynamic>)) ?.map((i) => Presence.fromJson(i as Map<String, Object?>))
.toList(), .toList(),
accountData = json accountData = json
.tryGetMap<String, List<dynamic>>('account_data')?['events'] .tryGetMap<String, List<dynamic>>('account_data')?['events']
?.map((i) => BasicEvent.fromJson(i as Map<String, dynamic>)) ?.map((i) => BasicEvent.fromJson(i as Map<String, Object?>))
.toList(), .toList(),
toDevice = json toDevice = json
.tryGetMap<String, List<dynamic>>('to_device')?['events'] .tryGetMap<String, List<dynamic>>('to_device')?['events']
?.map( ?.map(
(i) => BasicEventWithSender.fromJson(i as Map<String, dynamic>)) (i) => BasicEventWithSender.fromJson(i as Map<String, Object?>))
.toList(), .toList(),
deviceLists = (() { deviceLists = (() {
final temp = json.tryGetMap<String, dynamic>('device_lists'); final temp = json.tryGetMap<String, Object?>('device_lists');
return temp != null ? DeviceListsUpdate.fromJson(temp) : null; return temp != null ? DeviceListsUpdate.fromJson(temp) : null;
}()), }()),
deviceOneTimeKeysCount = deviceOneTimeKeysCount =
@ -74,8 +74,8 @@ class SyncUpdate {
json.tryGetList<String>( json.tryGetList<String>(
'org.matrix.msc2732.device_unused_fallback_key_types'); 'org.matrix.msc2732.device_unused_fallback_key_types');
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
data['next_batch'] = nextBatch; data['next_batch'] = nextBatch;
if (rooms != null) { if (rooms != null) {
data['rooms'] = rooms!.toJson(); data['rooms'] = rooms!.toJson();
@ -121,17 +121,17 @@ class RoomsUpdate {
this.leave, this.leave,
}); });
RoomsUpdate.fromJson(Map<String, dynamic> json) { RoomsUpdate.fromJson(Map<String, Object?> json) {
join = json.tryGetMap<String, dynamic>('join')?.catchMap((k, v) => join = json.tryGetMap<String, Object?>('join')?.catchMap((k, v) =>
MapEntry(k, JoinedRoomUpdate.fromJson(v as Map<String, dynamic>))); MapEntry(k, JoinedRoomUpdate.fromJson(v as Map<String, Object?>)));
invite = json.tryGetMap<String, dynamic>('invite')?.catchMap((k, v) => invite = json.tryGetMap<String, Object?>('invite')?.catchMap((k, v) =>
MapEntry(k, InvitedRoomUpdate.fromJson(v as Map<String, dynamic>))); MapEntry(k, InvitedRoomUpdate.fromJson(v as Map<String, Object?>)));
leave = json.tryGetMap<String, dynamic>('leave')?.catchMap((k, v) => leave = json.tryGetMap<String, Object?>('leave')?.catchMap((k, v) =>
MapEntry(k, LeftRoomUpdate.fromJson(v as Map<String, dynamic>))); MapEntry(k, LeftRoomUpdate.fromJson(v as Map<String, Object?>)));
} }
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (join != null) { if (join != null) {
data['join'] = join!.map((k, v) => MapEntry(k, v.toJson())); data['join'] = join!.map((k, v) => MapEntry(k, v.toJson()));
} }
@ -164,26 +164,26 @@ class JoinedRoomUpdate extends SyncRoomUpdate {
this.unreadNotifications, this.unreadNotifications,
}); });
JoinedRoomUpdate.fromJson(Map<String, dynamic> json) JoinedRoomUpdate.fromJson(Map<String, Object?> json)
: summary = json.tryGetFromJson('summary', RoomSummary.fromJson), : summary = json.tryGetFromJson('summary', RoomSummary.fromJson),
state = json state = json
.tryGetMap<String, List<dynamic>>('state')?['events'] .tryGetMap<String, List<dynamic>>('state')?['events']
?.map((i) => MatrixEvent.fromJson(i as Map<String, dynamic>)) ?.map((i) => MatrixEvent.fromJson(i as Map<String, Object?>))
.toList(), .toList(),
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson), timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
ephemeral = json ephemeral = json
.tryGetMap<String, List<dynamic>>('ephemeral')?['events'] .tryGetMap<String, List<dynamic>>('ephemeral')?['events']
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, dynamic>)) ?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
.toList(), .toList(),
accountData = json accountData = json
.tryGetMap<String, List<dynamic>>('account_data')?['events'] .tryGetMap<String, List<dynamic>>('account_data')?['events']
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, dynamic>)) ?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
.toList(), .toList(),
unreadNotifications = json.tryGetFromJson( unreadNotifications = json.tryGetFromJson(
'unread_notifications', UnreadNotificationCounts.fromJson); 'unread_notifications', UnreadNotificationCounts.fromJson);
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (summary != null) { if (summary != null) {
data['summary'] = summary!.toJson(); data['summary'] = summary!.toJson();
} }
@ -217,14 +217,14 @@ class InvitedRoomUpdate extends SyncRoomUpdate {
InvitedRoomUpdate({this.inviteState}); InvitedRoomUpdate({this.inviteState});
InvitedRoomUpdate.fromJson(Map<String, dynamic> json) InvitedRoomUpdate.fromJson(Map<String, Object?> json)
: inviteState = json : inviteState = json
.tryGetMap<String, List<dynamic>>('invite_state')?['events'] .tryGetMap<String, List<dynamic>>('invite_state')?['events']
?.map((i) => StrippedStateEvent.fromJson(i as Map<String, dynamic>)) ?.map((i) => StrippedStateEvent.fromJson(i as Map<String, Object?>))
.toList(); .toList();
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (inviteState != null) { if (inviteState != null) {
data['invite_state'] = { data['invite_state'] = {
'events': inviteState!.map((i) => i.toJson()).toList(), 'events': inviteState!.map((i) => i.toJson()).toList(),
@ -245,19 +245,19 @@ class LeftRoomUpdate extends SyncRoomUpdate {
this.accountData, this.accountData,
}); });
LeftRoomUpdate.fromJson(Map<String, dynamic> json) LeftRoomUpdate.fromJson(Map<String, Object?> json)
: state = json : state = json
.tryGetMap<String, List<dynamic>>('state')?['events'] .tryGetMap<String, List<dynamic>>('state')?['events']
?.map((i) => MatrixEvent.fromJson(i as Map<String, dynamic>)) ?.map((i) => MatrixEvent.fromJson(i as Map<String, Object?>))
.toList(), .toList(),
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson), timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
accountData = json accountData = json
.tryGetMap<String, List<dynamic>>('account_data')?['events'] .tryGetMap<String, List<dynamic>>('account_data')?['events']
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, dynamic>)) ?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
.toList(); .toList();
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (state != null) { if (state != null) {
data['state'] = { data['state'] = {
'events': state!.map((i) => i.toJson()).toList(), 'events': state!.map((i) => i.toJson()).toList(),
@ -286,16 +286,16 @@ class TimelineUpdate {
this.prevBatch, this.prevBatch,
}); });
TimelineUpdate.fromJson(Map<String, dynamic> json) TimelineUpdate.fromJson(Map<String, Object?> json)
: events = json : events = json
.tryGetList<Map<String, dynamic>>('events') .tryGetList<Map<String, Object?>>('events')
?.map((v) => MatrixEvent.fromJson(v)) ?.map((v) => MatrixEvent.fromJson(v))
.toList(), .toList(),
limited = json.tryGet<bool>('limited'), limited = json.tryGet<bool>('limited'),
prevBatch = json.tryGet<String>('prev_batch'); prevBatch = json.tryGet<String>('prev_batch');
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (events != null) { if (events != null) {
data['events'] = events!.map((i) => i.toJson()).toList(); data['events'] = events!.map((i) => i.toJson()).toList();
} }
@ -318,12 +318,12 @@ class UnreadNotificationCounts {
this.highlightCount, this.highlightCount,
}); });
UnreadNotificationCounts.fromJson(Map<String, dynamic> json) UnreadNotificationCounts.fromJson(Map<String, Object?> json)
: highlightCount = json.tryGet<int>('highlight_count'), : highlightCount = json.tryGet<int>('highlight_count'),
notificationCount = json.tryGet<int>('notification_count'); notificationCount = json.tryGet<int>('notification_count');
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (highlightCount != null) { if (highlightCount != null) {
data['highlight_count'] = highlightCount; data['highlight_count'] = highlightCount;
} }
@ -343,12 +343,12 @@ class DeviceListsUpdate {
this.left, this.left,
}); });
DeviceListsUpdate.fromJson(Map<String, dynamic> json) DeviceListsUpdate.fromJson(Map<String, Object?> json)
: changed = json.tryGetList<String>('changed') ?? [], : changed = json.tryGetList<String>('changed') ?? [],
left = json.tryGetList<String>('left') ?? []; left = json.tryGetList<String>('left') ?? [];
Map<String, dynamic> toJson() { Map<String, Object?> toJson() {
final data = <String, dynamic>{}; final data = <String, Object?>{};
if (changed != null) { if (changed != null) {
data['changed'] = changed; data['changed'] = changed;
} }

View File

@ -21,9 +21,9 @@
* SOFTWARE. * SOFTWARE.
*/ */
extension MapCopyExtension on Map<String, dynamic> { extension MapCopyExtension on Map<String, Object?> {
dynamic _copyValue(dynamic value) { dynamic _copyValue(dynamic value) {
if (value is Map<String, dynamic>) { if (value is Map<String, Object?>) {
return value.copy(); return value.copy();
} }
if (value is List) { if (value is List) {
@ -33,8 +33,8 @@ extension MapCopyExtension on Map<String, dynamic> {
} }
/// Deep-copies a given json map /// Deep-copies a given json map
Map<String, dynamic> copy() { Map<String, Object?> copy() {
final copy = Map<String, dynamic>.from(this); final copy = Map<String, Object?>.from(this);
for (final entry in copy.entries) { for (final entry in copy.entries) {
copy[entry.key] = _copyValue(entry.value); copy[entry.key] = _copyValue(entry.value);
} }

View File

@ -59,7 +59,7 @@ class _SilentLog implements TryGet {
void call(String key, Type expected, Type actual) {} void call(String key, Type expected, Type actual) {}
} }
extension TryGetMapExtension on Map<String, dynamic> { extension TryGetMapExtension on Map<String, Object?> {
T? tryGet<T extends Object>(String key, [TryGet log = TryGet.optional]) { T? tryGet<T extends Object>(String key, [TryGet log = TryGet.optional]) {
final Object? value = this[key]; final Object? value = this[key];
if (value is! T) { if (value is! T) {
@ -101,9 +101,9 @@ extension TryGetMapExtension on Map<String, dynamic> {
} }
} }
A? tryGetFromJson<A>(String key, A Function(Map<String, dynamic>) fromJson, A? tryGetFromJson<A>(String key, A Function(Map<String, Object?>) fromJson,
[TryGet log = TryGet.optional]) { [TryGet log = TryGet.optional]) {
final value = tryGetMap<String, dynamic>(key, log); final value = tryGetMap<String, Object?>(key, log);
return value != null ? fromJson(value) : null; return value != null ? fromJson(value) : null;
} }

View File

@ -30,7 +30,7 @@ import 'package:matrix_api_lite/matrix_api_lite.dart';
void main() { void main() {
group('Event Content tests', () { group('Event Content tests', () {
test('Room Encryption Content', () { test('Room Encryption Content', () {
Map<String, dynamic>? json = <String, dynamic>{ Map<String, Object?>? json = <String, Object?>{
'content': { 'content': {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': 'm.megolm.v1.aes-sha2',
'rotation_period_ms': 604800000, 'rotation_period_ms': 604800000,
@ -44,12 +44,12 @@ void main() {
'type': 'm.room.encryption', 'type': 'm.room.encryption',
'unsigned': {'age': 1234} 'unsigned': {'age': 1234}
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>?; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>?;
expect(MatrixEvent.fromJson(json!).parsedRoomEncryptionContent.toJson(), expect(MatrixEvent.fromJson(json!).parsedRoomEncryptionContent.toJson(),
json['content']); json['content']);
}); });
test('Room Encrypted Content', () { test('Room Encrypted Content', () {
Map<String, dynamic>? json = <String, dynamic>{ Map<String, Object?>? json = <String, Object?>{
'content': { 'content': {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': 'm.megolm.v1.aes-sha2',
'ciphertext': 'AwgAEnACgAkLmt6qF84IK++J7UDH2Za1YVchHyprqTqsg...', 'ciphertext': 'AwgAEnACgAkLmt6qF84IK++J7UDH2Za1YVchHyprqTqsg...',
@ -64,10 +64,10 @@ void main() {
'type': 'm.room.encrypted', 'type': 'm.room.encrypted',
'unsigned': {'age': 1234} 'unsigned': {'age': 1234}
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>?; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>?;
expect(MatrixEvent.fromJson(json!).parsedRoomEncryptedContent.toJson(), expect(MatrixEvent.fromJson(json!).parsedRoomEncryptedContent.toJson(),
json['content']); json['content']);
json = <String, dynamic>{ json = <String, Object?>{
'content': { 'content': {
'algorithm': 'm.olm.v1.curve25519-aes-sha2', 'algorithm': 'm.olm.v1.curve25519-aes-sha2',
'ciphertext': { 'ciphertext': {
@ -85,12 +85,12 @@ void main() {
'type': 'm.room.encrypted', 'type': 'm.room.encrypted',
'unsigned': {'age': 1234} 'unsigned': {'age': 1234}
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>?; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>?;
expect(MatrixEvent.fromJson(json!).parsedRoomEncryptedContent.toJson(), expect(MatrixEvent.fromJson(json!).parsedRoomEncryptedContent.toJson(),
json['content']); json['content']);
}); });
test('Room Key Content', () { test('Room Key Content', () {
Map<String, dynamic>? json = <String, dynamic>{ Map<String, Object?>? json = <String, Object?>{
'content': { 'content': {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': 'm.megolm.v1.aes-sha2',
'room_id': '!Cuyf34gef24t:localhost', 'room_id': '!Cuyf34gef24t:localhost',
@ -99,12 +99,12 @@ void main() {
}, },
'type': 'm.room_key' 'type': 'm.room_key'
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>?; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>?;
expect(BasicEvent.fromJson(json!).parsedRoomKeyContent.toJson(), expect(BasicEvent.fromJson(json!).parsedRoomKeyContent.toJson(),
json['content']); json['content']);
}); });
test('Room Key Request Content', () { test('Room Key Request Content', () {
Map<String, dynamic>? json = <String, dynamic>{ Map<String, Object?>? json = <String, Object?>{
'content': { 'content': {
'action': 'request_cancellation', 'action': 'request_cancellation',
'request_id': '1495474790150.19', 'request_id': '1495474790150.19',
@ -112,10 +112,10 @@ void main() {
}, },
'type': 'm.room_key_request' 'type': 'm.room_key_request'
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>?; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>?;
expect(BasicEvent.fromJson(json!).parsedRoomKeyRequestContent.toJson(), expect(BasicEvent.fromJson(json!).parsedRoomKeyRequestContent.toJson(),
json['content']); json['content']);
json = <String, dynamic>{ json = <String, Object?>{
'content': { 'content': {
'action': 'request', 'action': 'request',
'body': { 'body': {
@ -129,12 +129,12 @@ void main() {
}, },
'type': 'm.room_key_request' 'type': 'm.room_key_request'
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>?; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>?;
expect(BasicEvent.fromJson(json!).parsedRoomKeyRequestContent.toJson(), expect(BasicEvent.fromJson(json!).parsedRoomKeyRequestContent.toJson(),
json['content']); json['content']);
}); });
test('Forwarded Room Key Content', () { test('Forwarded Room Key Content', () {
Map<String, dynamic>? json = <String, dynamic>{ Map<String, Object?>? json = <String, Object?>{
'content': { 'content': {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': 'm.megolm.v1.aes-sha2',
'forwarding_curve25519_key_chain': [ 'forwarding_curve25519_key_chain': [
@ -149,14 +149,14 @@ void main() {
}, },
'type': 'm.forwarded_room_key' 'type': 'm.forwarded_room_key'
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>?; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>?;
expect(BasicEvent.fromJson(json!).parsedForwardedRoomKeyContent.toJson(), expect(BasicEvent.fromJson(json!).parsedForwardedRoomKeyContent.toJson(),
json['content']); json['content']);
}); });
test('OLM Plaintext Payload', () { test('OLM Plaintext Payload', () {
Map<String, dynamic>? json = <String, dynamic>{ Map<String, Object?>? json = <String, Object?>{
'type': '<type of the plaintext event>', 'type': '<type of the plaintext event>',
'content': <String, dynamic>{ 'content': <String, Object?>{
'msgtype': 'm.text', 'msgtype': 'm.text',
'body': 'Hello world', 'body': 'Hello world',
}, },
@ -165,12 +165,12 @@ void main() {
'recipient_keys': {'ed25519': '<our_ed25519_key>'}, 'recipient_keys': {'ed25519': '<our_ed25519_key>'},
'keys': {'ed25519': '<sender_ed25519_key>'} 'keys': {'ed25519': '<sender_ed25519_key>'}
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>?; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>?;
expect(OlmPlaintextPayload.fromJson(json!).toJson(), json); expect(OlmPlaintextPayload.fromJson(json!).toJson(), json);
}); });
test('Image Pack Content', () { test('Image Pack Content', () {
// basic parse / unparse // basic parse / unparse
var json = <String, dynamic>{ var json = <String, Object?>{
'type': 'some type', 'type': 'some type',
'content': { 'content': {
'images': { 'images': {
@ -191,12 +191,12 @@ void main() {
'org.custom': 'blah', 'org.custom': 'blah',
}, },
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>;
expect(BasicEvent.fromJson(json).parsedImagePackContent.toJson(), expect(BasicEvent.fromJson(json).parsedImagePackContent.toJson(),
json['content']); json['content']);
// emoticons migration // emoticons migration
json = <String, dynamic>{ json = <String, Object?>{
'type': 'some type', 'type': 'some type',
'content': { 'content': {
'emoticons': { 'emoticons': {
@ -206,7 +206,7 @@ void main() {
}, },
}, },
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>;
expect( expect(
BasicEvent.fromJson(json) BasicEvent.fromJson(json)
.parsedImagePackContent .parsedImagePackContent
@ -216,7 +216,7 @@ void main() {
'url': 'mxc://example.org/beep', 'url': 'mxc://example.org/beep',
}); });
json = <String, dynamic>{ json = <String, Object?>{
'type': 'some type', 'type': 'some type',
'content': { 'content': {
'short': { 'short': {
@ -224,7 +224,7 @@ void main() {
}, },
}, },
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>;
expect( expect(
BasicEvent.fromJson(json) BasicEvent.fromJson(json)
.parsedImagePackContent .parsedImagePackContent
@ -235,15 +235,15 @@ void main() {
}); });
// invalid url for image // invalid url for image
json = <String, dynamic>{ json = <String, Object?>{
'type': 'some type', 'type': 'some type',
'content': { 'content': {
'images': { 'images': {
'emote': <String, dynamic>{}, 'emote': <String, Object?>{},
}, },
}, },
}; };
json = jsonDecode(jsonEncode(json)) as Map<String, dynamic>; json = jsonDecode(jsonEncode(json)) as Map<String, Object?>;
expect(BasicEvent.fromJson(json).parsedImagePackContent.images['emote'], expect(BasicEvent.fromJson(json).parsedImagePackContent.images['emote'],
null); null);
}); });

View File

@ -28,21 +28,21 @@ import 'package:matrix_api_lite/matrix_api_lite.dart';
void main() { void main() {
group('Map-copy-extension', () { group('Map-copy-extension', () {
test('it should work', () { test('it should work', () {
final original = <String, dynamic>{ final original = <String, Object?>{
'attr': 'fox', 'attr': 'fox',
'child': <String, dynamic>{ 'child': <String, Object?>{
'attr': 'bunny', 'attr': 'bunny',
'list': [1, 2], 'list': [1, 2],
}, },
}; };
final copy = original.copy(); final copy = original.copy();
(original['child'] as Map<String, dynamic>)['attr'] = 'raccoon'; (original['child'] as Map<String, Object?>)['attr'] = 'raccoon';
expect((copy['child'] as Map<String, dynamic>)['attr'], 'bunny'); expect((copy['child'] as Map<String, Object?>)['attr'], 'bunny');
((original['child'] as Map<String, dynamic>)['list'] as List<int>).add(3); ((original['child'] as Map<String, Object?>)['list'] as List<int>).add(3);
expect((copy['child'] as Map<String, dynamic>)['list'], [1, 2]); expect((copy['child'] as Map<String, Object?>)['list'], [1, 2]);
}); });
test('should do arrays', () { test('should do arrays', () {
final original = <String, dynamic>{ final original = <String, Object?>{
'arr': [ 'arr': [
[1, 2], [1, 2],
{'beep': 'boop'}, {'beep': 'boop'},
@ -51,9 +51,9 @@ void main() {
final copy = original.copy(); final copy = original.copy();
((original['arr'] as List)[0] as List<int>).add(3); ((original['arr'] as List)[0] as List<int>).add(3);
expect((copy['arr'] as List)[0], [1, 2]); expect((copy['arr'] as List)[0], [1, 2]);
((original['arr'] as List)[1] as Map<String, dynamic>)['beep'] = 'blargh'; ((original['arr'] as List)[1] as Map<String, Object?>)['beep'] = 'blargh';
expect( expect(
((copy['arr'] as List)[1] as Map<String, dynamic>)['beep'], 'boop'); ((copy['arr'] as List)[1] as Map<String, Object?>)['beep'], 'boop');
}); });
}); });
} }

View File

@ -28,7 +28,7 @@ import 'package:test/test.dart';
import 'package:matrix_api_lite/fake_matrix_api.dart'; import 'package:matrix_api_lite/fake_matrix_api.dart';
import 'package:matrix_api_lite/matrix_api_lite.dart'; import 'package:matrix_api_lite/matrix_api_lite.dart';
const emptyRequest = <String, dynamic>{}; const emptyRequest = <String, Object?>{};
void main() { void main() {
/// All Tests related to device keys /// All Tests related to device keys
@ -435,8 +435,8 @@ void main() {
'types': ['type1'], 'types': ['type1'],
}, },
'include_leave': true, 'include_leave': true,
'state': <String, dynamic>{}, 'state': <String, Object?>{},
'timeline': <String, dynamic>{}, 'timeline': <String, Object?>{},
}, },
'presence': { 'presence': {
'limit': 10, 'limit': 10,
@ -1082,7 +1082,7 @@ void main() {
final devices = await matrixApi.getDevices(); final devices = await matrixApi.getDevices();
expect( expect(
(FakeMatrixApi.api['GET']!['/client/v3/devices']!.call(emptyRequest) (FakeMatrixApi.api['GET']!['/client/v3/devices']!.call(emptyRequest)
as Map<String, dynamic>?)?['devices'], as Map<String, Object?>?)?['devices'],
devices?.map((i) => i.toJson()).toList()); devices?.map((i) => i.toJson()).toList());
matrixApi.homeserver = matrixApi.accessToken = null; matrixApi.homeserver = matrixApi.accessToken = null;
@ -1229,7 +1229,7 @@ void main() {
final response = await matrixApi.getPushers(); final response = await matrixApi.getPushers();
expect( expect(
FakeMatrixApi.api['GET']!['/client/v3/pushers']! FakeMatrixApi.api['GET']!['/client/v3/pushers']!
.call(<String, dynamic>{}), .call(<String, Object?>{}),
{'pushers': response?.map((i) => i.toJson()).toList()}, {'pushers': response?.map((i) => i.toJson()).toList()},
); );
@ -1268,7 +1268,7 @@ void main() {
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/notifications?from=1234&limit=10&only=1234']! '/client/v3/notifications?from=1234&limit=10&only=1234']!
.call(<String, dynamic>{}), .call(<String, Object?>{}),
response.toJson(), response.toJson(),
); );
@ -1281,7 +1281,7 @@ void main() {
final response = await matrixApi.getPushRules(); final response = await matrixApi.getPushRules();
expect( expect(
FakeMatrixApi.api['GET']!['/client/v3/pushrules']! FakeMatrixApi.api['GET']!['/client/v3/pushrules']!
.call(<String, dynamic>{}), .call(<String, Object?>{}),
{'global': response.toJson()}, {'global': response.toJson()},
); );
@ -1295,7 +1295,7 @@ void main() {
await matrixApi.getPushRule('global', PushRuleKind.content, 'nocake'); await matrixApi.getPushRule('global', PushRuleKind.content, 'nocake');
expect( expect(
FakeMatrixApi.api['GET']!['/client/v3/pushrules/global/content/nocake']! FakeMatrixApi.api['GET']!['/client/v3/pushrules/global/content/nocake']!
.call(<String, dynamic>{}), .call(<String, Object?>{}),
response.toJson(), response.toJson(),
); );
@ -1396,7 +1396,7 @@ void main() {
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/events?from=1234&timeout=10&room_id=%211234']! '/client/v3/events?from=1234&timeout=10&room_id=%211234']!
.call(<String, dynamic>{}), .call(<String, Object?>{}),
response.toJson(), response.toJson(),
); );
@ -1411,7 +1411,7 @@ void main() {
expect( expect(
FakeMatrixApi.api['GET']![ FakeMatrixApi.api['GET']![
'/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags']! '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags']!
.call(<String, dynamic>{}), .call(<String, Object?>{}),
{'tags': response?.map((k, v) => MapEntry(k, v.toJson()))}, {'tags': response?.map((k, v) => MapEntry(k, v.toJson()))},
); );
@ -1636,14 +1636,14 @@ void main() {
matrixApi.accessToken = '1234'; matrixApi.accessToken = '1234';
final algorithm = BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2; final algorithm = BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2;
final authData = <String, dynamic>{ final authData = <String, Object?>{
'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM', 'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM',
'signatures': <String, Map<String, String>>{}, 'signatures': <String, Map<String, String>>{},
}; };
final ret = await matrixApi.postRoomKeysVersion(algorithm, authData); final ret = await matrixApi.postRoomKeysVersion(algorithm, authData);
expect( expect(
(FakeMatrixApi.api['POST']!['/client/v3/room_keys/version']! (FakeMatrixApi.api['POST']!['/client/v3/room_keys/version']!
.call(emptyRequest) as Map<String, dynamic>)['version'], .call(emptyRequest) as Map<String, Object?>)['version'],
ret); ret);
}); });
test('getRoomKeysVersionCurrent', () async { test('getRoomKeysVersionCurrent', () async {
@ -1661,7 +1661,7 @@ void main() {
matrixApi.accessToken = '1234'; matrixApi.accessToken = '1234';
final algorithm = BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2; final algorithm = BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2;
final authData = <String, dynamic>{ final authData = <String, Object?>{
'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM', 'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM',
'signatures': <String, Map<String, String>>{}, 'signatures': <String, Map<String, String>>{},
}; };

View File

@ -29,11 +29,11 @@ void main() {
group('Try-get-map-extension', () { group('Try-get-map-extension', () {
Logs().level = Level.verbose; Logs().level = Level.verbose;
test('it should work', () { test('it should work', () {
final data = <String, dynamic>{ final data = <String, Object?>{
'str': 'foxies', 'str': 'foxies',
'int': 42, 'int': 42,
'list': [2, 3, 4], 'list': [2, 3, 4],
'map': <String, dynamic>{ 'map': <String, Object?>{
'beep': 'boop', 'beep': 'boop',
}, },
}; };
@ -41,12 +41,12 @@ void main() {
expect(data.tryGet<int>('str'), null); expect(data.tryGet<int>('str'), null);
expect(data.tryGet<int>('int'), 42); expect(data.tryGet<int>('int'), 42);
expect(data.tryGet<List<int>>('list'), [2, 3, 4]); expect(data.tryGet<List<int>>('list'), [2, 3, 4]);
expect(data.tryGetMap<String, dynamic>('map')?.tryGet<String>('beep'), expect(data.tryGetMap<String, Object?>('map')?.tryGet<String>('beep'),
'boop'); 'boop');
expect( expect(
data.tryGetMap<String, dynamic>('map')?.tryGet<String>('meep'), null); data.tryGetMap<String, Object?>('map')?.tryGet<String>('meep'), null);
expect( expect(
data.tryGetMap<String, dynamic>('pam')?.tryGet<String>('beep'), null); data.tryGetMap<String, Object?>('pam')?.tryGet<String>('beep'), null);
}); });
}); });
} }