diff --git a/lib/src/model/auth/authentication_data.dart b/lib/src/model/auth/authentication_data.dart index 565c2dbd..2d8e0632 100644 --- a/lib/src/model/auth/authentication_data.dart +++ b/lib/src/model/auth/authentication_data.dart @@ -27,10 +27,9 @@ class AuthenticationData { AuthenticationData({this.type, this.session}); - AuthenticationData.fromJson(Map json) { - type = json['type']; - session = json['session']; - } + AuthenticationData.fromJson(Map json) + : type = json['type'], + session = json['session']; Map toJson() { final data = {}; diff --git a/lib/src/model/auth/authentication_identifier.dart b/lib/src/model/auth/authentication_identifier.dart index 5c6bec93..e46613b8 100644 --- a/lib/src/model/auth/authentication_identifier.dart +++ b/lib/src/model/auth/authentication_identifier.dart @@ -26,9 +26,8 @@ class AuthenticationIdentifier { AuthenticationIdentifier({this.type}); - AuthenticationIdentifier.fromJson(Map json) { - type = json['type']; - } + AuthenticationIdentifier.fromJson(Map json) + : type = json['type']; Map toJson() { final data = {}; diff --git a/lib/src/model/auth/authentication_password.dart b/lib/src/model/auth/authentication_password.dart index 6600a4f1..bfc85546 100644 --- a/lib/src/model/auth/authentication_password.dart +++ b/lib/src/model/auth/authentication_password.dart @@ -45,10 +45,10 @@ class AuthenticationPassword extends AuthenticationData { ); AuthenticationPassword.fromJson(Map json) - : super.fromJson(json) { - user = json['user']; - password = json['password']; - identifier = AuthenticationIdentifier.fromJson(json['identifier']); + : user = json['user'], + password = json['password'], + identifier = AuthenticationIdentifier.fromJson(json['identifier']), + super.fromJson(json) { switch (identifier.type) { case AuthenticationIdentifierTypes.userId: identifier = AuthenticationUserIdentifier.fromJson(json['identifier']); diff --git a/lib/src/model/auth/authentication_phone_identifier.dart b/lib/src/model/auth/authentication_phone_identifier.dart index 8ae4d06a..d45a3eab 100644 --- a/lib/src/model/auth/authentication_phone_identifier.dart +++ b/lib/src/model/auth/authentication_phone_identifier.dart @@ -32,10 +32,9 @@ class AuthenticationPhoneIdentifier extends AuthenticationIdentifier { : super(type: AuthenticationIdentifierTypes.phone); AuthenticationPhoneIdentifier.fromJson(Map json) - : super.fromJson(json) { - country = json['country']; - phone = json['phone']; - } + : country = json['country'], + phone = json['phone'], + super.fromJson(json); @override Map toJson() { diff --git a/lib/src/model/auth/authentication_recaptcha.dart b/lib/src/model/auth/authentication_recaptcha.dart index f37526f9..a98ec159 100644 --- a/lib/src/model/auth/authentication_recaptcha.dart +++ b/lib/src/model/auth/authentication_recaptcha.dart @@ -34,9 +34,8 @@ class AuthenticationRecaptcha extends AuthenticationData { ); AuthenticationRecaptcha.fromJson(Map json) - : super.fromJson(json) { - response = json['response']; - } + : response = json['response'], + super.fromJson(json); @override Map toJson() { diff --git a/lib/src/model/auth/authentication_third_party_identifier.dart b/lib/src/model/auth/authentication_third_party_identifier.dart index 742248ff..e8dabf3b 100644 --- a/lib/src/model/auth/authentication_third_party_identifier.dart +++ b/lib/src/model/auth/authentication_third_party_identifier.dart @@ -32,10 +32,9 @@ class AuthenticationThirdPartyIdentifier extends AuthenticationIdentifier { : super(type: AuthenticationIdentifierTypes.thirdParty); AuthenticationThirdPartyIdentifier.fromJson(Map json) - : super.fromJson(json) { - medium = json['medium']; - address = json['address']; - } + : medium = json['medium'], + address = json['address'], + super.fromJson(json); @override Map toJson() { diff --git a/lib/src/model/auth/authentication_three_pid_creds.dart b/lib/src/model/auth/authentication_three_pid_creds.dart index 37e7ba97..41c04d6c 100644 --- a/lib/src/model/auth/authentication_three_pid_creds.dart +++ b/lib/src/model/auth/authentication_three_pid_creds.dart @@ -72,12 +72,11 @@ class ThreepidCreds { ThreepidCreds( {this.sid, this.clientSecret, this.idServer, this.idAccessToken}); - ThreepidCreds.fromJson(Map json) { - sid = json['sid']; - clientSecret = json['client_secret']; - idServer = json['id_server']; - idAccessToken = json['id_access_token']; - } + ThreepidCreds.fromJson(Map json) + : sid = json['sid'], + clientSecret = json['client_secret'], + idServer = json['id_server'], + idAccessToken = json['id_access_token']; Map toJson() { final data = {}; diff --git a/lib/src/model/auth/authentication_token.dart b/lib/src/model/auth/authentication_token.dart index f182c2dc..d8e96301 100644 --- a/lib/src/model/auth/authentication_token.dart +++ b/lib/src/model/auth/authentication_token.dart @@ -35,10 +35,9 @@ class AuthenticationToken extends AuthenticationData { ); AuthenticationToken.fromJson(Map json) - : super.fromJson(json) { - token = json['token']; - txnId = json['txn_id']; - } + : token = json['token'], + txnId = json['txn_id'], + super.fromJson(json); @override Map toJson() { diff --git a/lib/src/model/auth/authentication_user_identifier.dart b/lib/src/model/auth/authentication_user_identifier.dart index 28491a6b..7531bdd8 100644 --- a/lib/src/model/auth/authentication_user_identifier.dart +++ b/lib/src/model/auth/authentication_user_identifier.dart @@ -31,9 +31,8 @@ class AuthenticationUserIdentifier extends AuthenticationIdentifier { : super(type: AuthenticationIdentifierTypes.userId); AuthenticationUserIdentifier.fromJson(Map json) - : super.fromJson(json) { - user = json['user']; - } + : user = json['user'], + super.fromJson(json); @override Map toJson() { diff --git a/lib/src/model/basic_event.dart b/lib/src/model/basic_event.dart index 48ea0c1a..cd708d48 100644 --- a/lib/src/model/basic_event.dart +++ b/lib/src/model/basic_event.dart @@ -32,10 +32,10 @@ class BasicEvent { this.content, }); - BasicEvent.fromJson(Map json) { - type = json['type']; - content = (json['content'] as Map).copy(); - } + BasicEvent.fromJson(Map json) + : type = json['type'], + content = (json['content'] as Map).copy(); + Map toJson() { final data = {}; data['type'] = type; diff --git a/lib/src/model/basic_event_with_sender.dart b/lib/src/model/basic_event_with_sender.dart index 6c90e8c9..8a99781c 100644 --- a/lib/src/model/basic_event_with_sender.dart +++ b/lib/src/model/basic_event_with_sender.dart @@ -29,9 +29,8 @@ class BasicEventWithSender extends BasicEvent { BasicEventWithSender(); BasicEventWithSender.fromJson(Map json) - : super.fromJson(json) { - senderId = json['sender']; - } + : senderId = json['sender'], + super.fromJson(json); @override Map toJson() { diff --git a/lib/src/model/basic_room_event.dart b/lib/src/model/basic_room_event.dart index 27f28e8f..3a3dbb86 100644 --- a/lib/src/model/basic_room_event.dart +++ b/lib/src/model/basic_room_event.dart @@ -35,9 +35,9 @@ class BasicRoomEvent extends BasicEvent { type: type, ); - BasicRoomEvent.fromJson(Map json) : super.fromJson(json) { - roomId = json['room_id']; - } + BasicRoomEvent.fromJson(Map json) + : roomId = json['room_id'], + super.fromJson(json); @override Map toJson() { diff --git a/lib/src/model/device.dart b/lib/src/model/device.dart index 01b027b2..825c828d 100644 --- a/lib/src/model/device.dart +++ b/lib/src/model/device.dart @@ -27,12 +27,12 @@ class Device { String lastSeenIp; DateTime lastSeenTs; - Device.fromJson(Map json) { - deviceId = json['device_id']; - displayName = json['display_name']; - lastSeenIp = json['last_seen_ip']; - lastSeenTs = DateTime.fromMillisecondsSinceEpoch(json['last_seen_ts'] ?? 0); - } + Device.fromJson(Map json) + : deviceId = json['device_id'], + displayName = json['display_name'], + lastSeenIp = json['last_seen_ip'], + lastSeenTs = + DateTime.fromMillisecondsSinceEpoch(json['last_seen_ts'] ?? 0); Map toJson() { final data = {}; diff --git a/lib/src/model/event_context.dart b/lib/src/model/event_context.dart index aeee869e..90620915 100644 --- a/lib/src/model/event_context.dart +++ b/lib/src/model/event_context.dart @@ -31,25 +31,26 @@ class EventContext { String start; List state; - EventContext.fromJson(Map json) { - end = json['end']; - if (json['events_after'] != null) { - eventsAfter = (json['events_after'] as List) - .map((v) => MatrixEvent.fromJson(v)) - .toList(); - } - event = json['event'] != null ? MatrixEvent.fromJson(json['event']) : null; - if (json['events_before'] != null) { - eventsBefore = (json['events_before'] as List) - .map((v) => MatrixEvent.fromJson(v)) - .toList(); - } - start = json['start']; - if (json['state'] != null) { - state = - (json['state'] as List).map((v) => MatrixEvent.fromJson(v)).toList(); - } - } + EventContext.fromJson(Map json) + : end = json['end'], + eventsAfter = (json['events_after'] != null) + ? (json['events_after'] as List) + .map((v) => MatrixEvent.fromJson(v)) + .toList() + : null, + event = + json['event'] != null ? MatrixEvent.fromJson(json['event']) : null, + eventsBefore = (json['events_before'] != null) + ? (json['events_before'] as List) + .map((v) => MatrixEvent.fromJson(v)) + .toList() + : null, + start = json['start'], + state = (json['state'] != null) + ? (json['state'] as List) + .map((v) => MatrixEvent.fromJson(v)) + .toList() + : null; Map toJson() { final data = {}; diff --git a/lib/src/model/events_sync_update.dart b/lib/src/model/events_sync_update.dart index 6ea08df5..1e53d9ee 100644 --- a/lib/src/model/events_sync_update.dart +++ b/lib/src/model/events_sync_update.dart @@ -28,13 +28,14 @@ class EventsSyncUpdate { String end; List chunk; - EventsSyncUpdate.fromJson(Map json) { - start = json['start']; - end = json['end']; - chunk = json['chunk'] != null - ? (json['chunk'] as List).map((i) => MatrixEvent.fromJson(i)).toList() - : null; - } + EventsSyncUpdate.fromJson(Map json) + : start = json['start'], + end = json['end'], + chunk = json['chunk'] != null + ? (json['chunk'] as List) + .map((i) => MatrixEvent.fromJson(i)) + .toList() + : null; Map toJson() { final data = {}; diff --git a/lib/src/model/filter.dart b/lib/src/model/filter.dart index 391537cf..68146542 100644 --- a/lib/src/model/filter.dart +++ b/lib/src/model/filter.dart @@ -38,22 +38,21 @@ class Filter { this.eventFields, }); - Filter.fromJson(Map json) { - room = json['room'] != null ? RoomFilter.fromJson(json['room']) : null; - presence = json['presence'] != null - ? EventFilter.fromJson(json['presence']) - : null; - accountData = json['account_data'] != null - ? EventFilter.fromJson(json['account_data']) - : null; - eventFormat = json['event_format'] != null - ? EventFormat.values.firstWhere( - (e) => e.toString().split('.').last == json['event_format']) - : null; - eventFields = json['event_fields'] != null - ? json['event_fields'].cast() - : null; - } + Filter.fromJson(Map json) + : room = json['room'] != null ? RoomFilter.fromJson(json['room']) : null, + presence = json['presence'] != null + ? EventFilter.fromJson(json['presence']) + : null, + accountData = json['account_data'] != null + ? EventFilter.fromJson(json['account_data']) + : null, + eventFormat = json['event_format'] != null + ? EventFormat.values.firstWhere( + (e) => e.toString().split('.').last == json['event_format']) + : null, + eventFields = json['event_fields'] != null + ? json['event_fields'].cast() + : null; Map toJson() { final data = {}; diff --git a/lib/src/model/keys_query_response.dart b/lib/src/model/keys_query_response.dart index c705ab1b..ccbc80ff 100644 --- a/lib/src/model/keys_query_response.dart +++ b/lib/src/model/keys_query_response.dart @@ -31,48 +31,45 @@ class KeysQueryResponse { Map selfSigningKeys; Map userSigningKeys; - KeysQueryResponse.fromJson(Map json) { - failures = (json['failures'] as Map)?.copy(); - deviceKeys = json['device_keys'] != null - ? (json['device_keys'] as Map).map( - (k, v) => MapEntry( - k, - (v as Map).map( + KeysQueryResponse.fromJson(Map json) + : failures = (json['failures'] as Map)?.copy(), + deviceKeys = json['device_keys'] != null + ? (json['device_keys'] as Map).map( (k, v) => MapEntry( k, - MatrixDeviceKeys.fromJson(v), + (v as Map).map( + (k, v) => MapEntry( + k, + MatrixDeviceKeys.fromJson(v), + ), + ), ), - ), - ), - ) - : null; - masterKeys = json['master_keys'] != null - ? (json['master_keys'] as Map).map( - (k, v) => MapEntry( - k, - MatrixCrossSigningKey.fromJson(v), - ), - ) - : null; - - selfSigningKeys = json['self_signing_keys'] != null - ? (json['self_signing_keys'] as Map).map( - (k, v) => MapEntry( - k, - MatrixCrossSigningKey.fromJson(v), - ), - ) - : null; - - userSigningKeys = json['user_signing_keys'] != null - ? (json['user_signing_keys'] as Map).map( - (k, v) => MapEntry( - k, - MatrixCrossSigningKey.fromJson(v), - ), - ) - : null; - } + ) + : null, + masterKeys = json['master_keys'] != null + ? (json['master_keys'] as Map).map( + (k, v) => MapEntry( + k, + MatrixCrossSigningKey.fromJson(v), + ), + ) + : null, + selfSigningKeys = json['self_signing_keys'] != null + ? (json['self_signing_keys'] as Map).map( + (k, v) => MapEntry( + k, + MatrixCrossSigningKey.fromJson(v), + ), + ) + : null, + userSigningKeys = json['user_signing_keys'] != null + ? (json['user_signing_keys'] as Map).map( + (k, v) => MapEntry( + k, + MatrixCrossSigningKey.fromJson(v), + ), + ) + : null; Map toJson() { final data = {}; diff --git a/lib/src/model/login_response.dart b/lib/src/model/login_response.dart index d64b1cd2..625739e7 100644 --- a/lib/src/model/login_response.dart +++ b/lib/src/model/login_response.dart @@ -29,14 +29,13 @@ class LoginResponse { String deviceId; WellKnownInformation wellKnownInformation; - LoginResponse.fromJson(Map json) { - userId = json['user_id']; - accessToken = json['access_token']; - deviceId = json['device_id']; - if (json['well_known'] is Map) { - wellKnownInformation = WellKnownInformation.fromJson(json['well_known']); - } - } + LoginResponse.fromJson(Map json) + : userId = json['user_id'], + accessToken = json['access_token'], + deviceId = json['device_id'], + wellKnownInformation = (json['well_known'] is Map) + ? WellKnownInformation.fromJson(json['well_known']) + : null; Map toJson() { final data = {}; diff --git a/lib/src/model/matrix_event.dart b/lib/src/model/matrix_event.dart index 705f2f04..c45e2615 100644 --- a/lib/src/model/matrix_event.dart +++ b/lib/src/model/matrix_event.dart @@ -34,15 +34,15 @@ class MatrixEvent extends StrippedStateEvent { MatrixEvent(); - MatrixEvent.fromJson(Map json) : super.fromJson(json) { - eventId = json['event_id']; - roomId = json['room_id']; - originServerTs = - DateTime.fromMillisecondsSinceEpoch(json['origin_server_ts']); - unsigned = (json['unsigned'] as Map)?.copy(); - prevContent = (json['prev_content'] as Map)?.copy(); - redacts = json['redacts']; - } + MatrixEvent.fromJson(Map json) + : eventId = json['event_id'], + roomId = json['room_id'], + originServerTs = + DateTime.fromMillisecondsSinceEpoch(json['origin_server_ts']), + unsigned = (json['unsigned'] as Map)?.copy(), + prevContent = (json['prev_content'] as Map)?.copy(), + redacts = json['redacts'], + super.fromJson(json); @override Map toJson() { diff --git a/lib/src/model/matrix_keys.dart b/lib/src/model/matrix_keys.dart index 81819f78..44ebbc8e 100644 --- a/lib/src/model/matrix_keys.dart +++ b/lib/src/model/matrix_keys.dart @@ -36,17 +36,16 @@ class MatrixSignableKey { // This object is used for signing so we need the raw json too Map _json; - MatrixSignableKey.fromJson(Map json) { - _json = json; - userId = json['user_id']; - keys = Map.from(json['keys']); - // we need to manually copy to ensure that our map is Map> - signatures = json['signatures'] is Map - ? Map>.from((json['signatures'] as Map) - .map((k, v) => MapEntry(k, Map.from(v)))) - : null; - unsigned = (json['unsigned'] as Map)?.copy(); - } + MatrixSignableKey.fromJson(Map json) + : _json = json, + userId = json['user_id'], + keys = Map.from(json['keys']), + // we need to manually copy to ensure that our map is Map> + signatures = json['signatures'] is Map + ? Map>.from((json['signatures'] as Map) + .map((k, v) => MapEntry(k, Map.from(v)))) + : null, + unsigned = (json['unsigned'] as Map)?.copy(); Map toJson() { final data = _json ?? {}; diff --git a/lib/src/model/notifications_query_response.dart b/lib/src/model/notifications_query_response.dart index aaeadbda..83e0d767 100644 --- a/lib/src/model/notifications_query_response.dart +++ b/lib/src/model/notifications_query_response.dart @@ -27,12 +27,11 @@ class NotificationsQueryResponse { String nextToken; List notifications; - NotificationsQueryResponse.fromJson(Map json) { - nextToken = json['next_token']; - notifications = (json['notifications'] as List) - .map((v) => Notification.fromJson(v)) - .toList(); - } + NotificationsQueryResponse.fromJson(Map json) + : nextToken = json['next_token'], + notifications = (json['notifications'] as List) + .map((v) => Notification.fromJson(v)) + .toList(); Map toJson() { final data = {}; diff --git a/lib/src/model/one_time_keys_claim_response.dart b/lib/src/model/one_time_keys_claim_response.dart index b3bab36d..525d2c9c 100644 --- a/lib/src/model/one_time_keys_claim_response.dart +++ b/lib/src/model/one_time_keys_claim_response.dart @@ -27,12 +27,11 @@ class OneTimeKeysClaimResponse { Map failures; Map> oneTimeKeys; - OneTimeKeysClaimResponse.fromJson(Map json) { - failures = (json['failures'] as Map)?.copy() ?? {}; - // We still need a Map<...>.from(...) to ensure all second-level entries are also maps - oneTimeKeys = Map>.from( - (json['one_time_keys'] as Map).copy()); - } + OneTimeKeysClaimResponse.fromJson(Map json) + : failures = (json['failures'] as Map)?.copy() ?? {}, + // We still need a Map<...>.from(...) to ensure all second-level entries are also maps + oneTimeKeys = Map>.from( + (json['one_time_keys'] as Map).copy()); Map toJson() { final data = {}; diff --git a/lib/src/model/open_graph_data.dart b/lib/src/model/open_graph_data.dart index 7ba8f5aa..48a8b1f4 100644 --- a/lib/src/model/open_graph_data.dart +++ b/lib/src/model/open_graph_data.dart @@ -30,15 +30,14 @@ class OpenGraphData { int ogImageWidth; int matrixImageSize; - OpenGraphData.fromJson(Map json) { - ogTitle = json['og:title']; - ogDescription = json['og:description']; - ogImage = json['og:image']; - ogImageType = json['og:image:type']; - ogImageHeight = json['og:image:height']; - ogImageWidth = json['og:image:width']; - matrixImageSize = json['matrix:image:size']; - } + OpenGraphData.fromJson(Map json) + : ogTitle = json['og:title'], + ogDescription = json['og:description'], + ogImage = json['og:image'], + ogImageType = json['og:image:type'], + ogImageHeight = json['og:image:height'], + ogImageWidth = json['og:image:width'], + matrixImageSize = json['matrix:image:size']; Map toJson() { final data = {}; diff --git a/lib/src/model/open_id_credentials.dart b/lib/src/model/open_id_credentials.dart index 4ead2f91..e398ffa3 100644 --- a/lib/src/model/open_id_credentials.dart +++ b/lib/src/model/open_id_credentials.dart @@ -27,12 +27,11 @@ class OpenIdCredentials { String matrixServerName; double expiresIn; - OpenIdCredentials.fromJson(Map json) { - accessToken = json['access_token']; - tokenType = json['token_type']; - matrixServerName = json['matrix_server_name']; - expiresIn = json['expires_in']; - } + OpenIdCredentials.fromJson(Map json) + : accessToken = json['access_token'], + tokenType = json['token_type'], + matrixServerName = json['matrix_server_name'], + expiresIn = json['expires_in']; Map toJson() { final data = {}; diff --git a/lib/src/model/presence.dart b/lib/src/model/presence.dart index 7d9fb753..73848c2e 100644 --- a/lib/src/model/presence.dart +++ b/lib/src/model/presence.dart @@ -27,7 +27,7 @@ import 'presence_content.dart'; class Presence extends BasicEventWithSender { PresenceContent presence; - Presence.fromJson(Map json) : super.fromJson(json) { - presence = PresenceContent.fromJson(content); - } + Presence.fromJson(Map json) + : presence = PresenceContent.fromJson(json['content']), + super.fromJson(json); } diff --git a/lib/src/model/presence_content.dart b/lib/src/model/presence_content.dart index 99d926cf..597082f3 100644 --- a/lib/src/model/presence_content.dart +++ b/lib/src/model/presence_content.dart @@ -29,13 +29,12 @@ class PresenceContent { String statusMsg; bool currentlyActive; - PresenceContent.fromJson(Map json) { - presence = PresenceType.values - .firstWhere((p) => p.toString().split('.').last == json['presence']); - lastActiveAgo = json['last_active_ago']; - statusMsg = json['status_msg']; - currentlyActive = json['currently_active']; - } + PresenceContent.fromJson(Map json) + : presence = PresenceType.values.firstWhere( + (p) => p.toString().split('.').last == json['presence']), + lastActiveAgo = json['last_active_ago'], + statusMsg = json['status_msg'], + currentlyActive = json['currently_active']; Map toJson() { final data = {}; diff --git a/lib/src/model/public_rooms_response.dart b/lib/src/model/public_rooms_response.dart index 34ae0bf7..7fdfabdd 100644 --- a/lib/src/model/public_rooms_response.dart +++ b/lib/src/model/public_rooms_response.dart @@ -27,12 +27,12 @@ class PublicRoomsResponse { String prevBatch; int totalRoomCountEstimate; - PublicRoomsResponse.fromJson(Map json) { - chunk = (json['chunk'] as List).map((v) => PublicRoom.fromJson(v)).toList(); - nextBatch = json['next_batch']; - prevBatch = json['prev_batch']; - totalRoomCountEstimate = json['total_room_count_estimate']; - } + PublicRoomsResponse.fromJson(Map json) + : chunk = + (json['chunk'] as List).map((v) => PublicRoom.fromJson(v)).toList(), + nextBatch = json['next_batch'], + prevBatch = json['prev_batch'], + totalRoomCountEstimate = json['total_room_count_estimate']; Map toJson() { final data = {}; @@ -61,17 +61,16 @@ class PublicRoom { bool worldReadable; String canonicalAlias; - PublicRoom.fromJson(Map json) { - aliases = json['aliases']?.cast(); - avatarUrl = json['avatar_url']; - guestCanJoin = json['guest_can_join']; - canonicalAlias = json['canonical_alias']; - name = json['name']; - numJoinedMembers = json['num_joined_members']; - roomId = json['room_id']; - topic = json['topic']; - worldReadable = json['world_readable']; - } + PublicRoom.fromJson(Map json) + : aliases = json['aliases']?.cast(), + avatarUrl = json['avatar_url'], + guestCanJoin = json['guest_can_join'], + canonicalAlias = json['canonical_alias'], + name = json['name'], + numJoinedMembers = json['num_joined_members'], + roomId = json['room_id'], + topic = json['topic'], + worldReadable = json['world_readable']; Map toJson() { final data = {}; diff --git a/lib/src/model/pusher.dart b/lib/src/model/pusher.dart index 4068e2c9..08d36577 100644 --- a/lib/src/model/pusher.dart +++ b/lib/src/model/pusher.dart @@ -42,16 +42,15 @@ class Pusher { this.kind, }); - Pusher.fromJson(Map json) { - pushkey = json['pushkey']; - kind = json['kind']; - appId = json['app_id']; - appDisplayName = json['app_display_name']; - deviceDisplayName = json['device_display_name']; - profileTag = json['profile_tag']; - lang = json['lang']; - data = PusherData.fromJson(json['data']); - } + Pusher.fromJson(Map json) + : pushkey = json['pushkey'], + kind = json['kind'], + appId = json['app_id'], + appDisplayName = json['app_display_name'], + deviceDisplayName = json['device_display_name'], + profileTag = json['profile_tag'], + lang = json['lang'], + data = PusherData.fromJson(json['data']); Map toJson() { final data = {}; @@ -78,12 +77,9 @@ class PusherData { this.format, }); - PusherData.fromJson(Map json) { - if (json.containsKey('url')) { - url = Uri.parse(json['url']); - } - format = json['format']; - } + PusherData.fromJson(Map json) + : format = json['format'], + url = json.containsKey('url') ? Uri.parse(json['url']) : null; Map toJson() { final data = {}; diff --git a/lib/src/model/request_token_response.dart b/lib/src/model/request_token_response.dart index e7b41c7c..e2001826 100644 --- a/lib/src/model/request_token_response.dart +++ b/lib/src/model/request_token_response.dart @@ -25,10 +25,9 @@ class RequestTokenResponse { String sid; String submitUrl; - RequestTokenResponse.fromJson(Map json) { - sid = json['sid']; - submitUrl = json['submit_url']; - } + RequestTokenResponse.fromJson(Map json) + : sid = json['sid'], + submitUrl = json['submit_url']; Map toJson() { final data = {}; diff --git a/lib/src/model/room_alias_information.dart b/lib/src/model/room_alias_information.dart index ae675991..050b6b2c 100644 --- a/lib/src/model/room_alias_information.dart +++ b/lib/src/model/room_alias_information.dart @@ -25,10 +25,9 @@ class RoomAliasInformation { String roomId; List servers; - RoomAliasInformation.fromJson(Map json) { - roomId = json['room_id']; - servers = json['servers'].cast(); - } + RoomAliasInformation.fromJson(Map json) + : roomId = json['room_id'], + servers = json['servers'].cast(); Map toJson() { final data = {}; diff --git a/lib/src/model/room_keys_info.dart b/lib/src/model/room_keys_info.dart index 9deaea3d..c300b298 100644 --- a/lib/src/model/room_keys_info.dart +++ b/lib/src/model/room_keys_info.dart @@ -52,15 +52,14 @@ class RoomKeysVersionResponse { String etag; String version; - RoomKeysVersionResponse.fromJson(Map json) { - algorithm = - RoomKeysAlgorithmTypeExtension.fromAlgorithmString(json['algorithm']); - authData = json['auth_data']; - count = json['count']; - etag = - json['etag'].toString(); // synapse replies an int but docs say string? - version = json['version']; - } + RoomKeysVersionResponse.fromJson(Map json) + : algorithm = RoomKeysAlgorithmTypeExtension.fromAlgorithmString( + json['algorithm']), + authData = json['auth_data'], + count = json['count'], + etag = json['etag'] + .toString(), // synapse replies an int but docs say string? + version = json['version']; Map toJson() { final data = {}; diff --git a/lib/src/model/room_keys_keys.dart b/lib/src/model/room_keys_keys.dart index fb8c20fc..54c2f102 100644 --- a/lib/src/model/room_keys_keys.dart +++ b/lib/src/model/room_keys_keys.dart @@ -33,12 +33,11 @@ class RoomKeysSingleKey { this.isVerified, this.sessionData}); - RoomKeysSingleKey.fromJson(Map json) { - firstMessageIndex = json['first_message_index']; - forwardedCount = json['forwarded_count']; - isVerified = json['is_verified']; - sessionData = json['session_data']; - } + RoomKeysSingleKey.fromJson(Map json) + : firstMessageIndex = json['first_message_index'], + forwardedCount = json['forwarded_count'], + isVerified = json['is_verified'], + sessionData = json['session_data']; Map toJson() { final data = {}; @@ -57,10 +56,9 @@ class RoomKeysRoom { sessions ??= {}; } - RoomKeysRoom.fromJson(Map json) { - sessions = (json['sessions'] as Map) - .map((k, v) => MapEntry(k, RoomKeysSingleKey.fromJson(v))); - } + RoomKeysRoom.fromJson(Map json) + : sessions = (json['sessions'] as Map) + .map((k, v) => MapEntry(k, RoomKeysSingleKey.fromJson(v))); Map toJson() { final data = {}; @@ -76,10 +74,9 @@ class RoomKeys { rooms ??= {}; } - RoomKeys.fromJson(Map json) { - rooms = (json['rooms'] as Map) - .map((k, v) => MapEntry(k, RoomKeysRoom.fromJson(v))); - } + RoomKeys.fromJson(Map json) + : rooms = (json['rooms'] as Map) + .map((k, v) => MapEntry(k, RoomKeysRoom.fromJson(v))); Map toJson() { final data = {}; @@ -92,10 +89,9 @@ class RoomKeysUpdateResponse { String etag; int count; - RoomKeysUpdateResponse.fromJson(Map json) { - etag = json['etag']; // synapse replies an int but docs say string? - count = json['count']; - } + RoomKeysUpdateResponse.fromJson(Map json) + : etag = json['etag'], // synapse replies an int but docs say string? + count = json['count']; Map toJson() { final data = {}; diff --git a/lib/src/model/room_summary.dart b/lib/src/model/room_summary.dart index 78d505ee..664cd229 100644 --- a/lib/src/model/room_summary.dart +++ b/lib/src/model/room_summary.dart @@ -25,12 +25,13 @@ class RoomSummary { List mHeroes; int mJoinedMemberCount; int mInvitedMemberCount; - RoomSummary.fromJson(Map json) { - mHeroes = - json['m.heroes'] != null ? List.from(json['m.heroes']) : null; - mJoinedMemberCount = json['m.joined_member_count']; - mInvitedMemberCount = json['m.invited_member_count']; - } + RoomSummary.fromJson(Map json) + : mHeroes = json['m.heroes'] != null + ? List.from(json['m.heroes']) + : null, + mJoinedMemberCount = json['m.joined_member_count'], + mInvitedMemberCount = json['m.invited_member_count']; + Map toJson() { final data = {}; if (mHeroes != null) { diff --git a/lib/src/model/server_capabilities.dart b/lib/src/model/server_capabilities.dart index 0e11e1f9..b7053f84 100644 --- a/lib/src/model/server_capabilities.dart +++ b/lib/src/model/server_capabilities.dart @@ -30,17 +30,16 @@ class ServerCapabilities { MRoomVersions mRoomVersions; Map customCapabilities; - ServerCapabilities.fromJson(Map json) { - mChangePassword = json['m.change_password'] != null - ? MChangePassword.fromJson(json['m.change_password']) - : null; - mRoomVersions = json['m.room_versions'] != null - ? MRoomVersions.fromJson(json['m.room_versions']) - : null; - customCapabilities = json.copy() - ..remove('m.change_password') - ..remove('m.room_versions'); - } + ServerCapabilities.fromJson(Map json) + : mChangePassword = json['m.change_password'] != null + ? MChangePassword.fromJson(json['m.change_password']) + : null, + mRoomVersions = json['m.room_versions'] != null + ? MRoomVersions.fromJson(json['m.room_versions']) + : null, + customCapabilities = json.copy() + ..remove('m.change_password') + ..remove('m.room_versions'); Map toJson() { final data = {}; diff --git a/lib/src/model/stripped_state_event.dart b/lib/src/model/stripped_state_event.dart index e6d1edd5..bb8ad374 100644 --- a/lib/src/model/stripped_state_event.dart +++ b/lib/src/model/stripped_state_event.dart @@ -28,9 +28,8 @@ class StrippedStateEvent extends BasicEventWithSender { StrippedStateEvent(); StrippedStateEvent.fromJson(Map json) - : super.fromJson(json) { - stateKey = json['state_key']; - } + : stateKey = json['state_key'], + super.fromJson(json); @override Map toJson() { diff --git a/lib/src/model/supported_protocol.dart b/lib/src/model/supported_protocol.dart index a81c6bd8..b9e4ad35 100644 --- a/lib/src/model/supported_protocol.dart +++ b/lib/src/model/supported_protocol.dart @@ -28,16 +28,15 @@ class SupportedProtocol { Map fieldTypes; List instances; - SupportedProtocol.fromJson(Map json) { - userFields = json['user_fields'].cast(); - locationFields = json['location_fields'].cast(); - icon = json['icon']; - fieldTypes = (json['field_types'] as Map) - .map((k, v) => MapEntry(k, ProtocolFieldType.fromJson(v))); - instances = (json['instances'] as List) - .map((v) => ProtocolInstance.fromJson(v)) - .toList(); - } + SupportedProtocol.fromJson(Map json) + : userFields = json['user_fields'].cast(), + locationFields = json['location_fields'].cast(), + icon = json['icon'], + fieldTypes = (json['field_types'] as Map) + .map((k, v) => MapEntry(k, ProtocolFieldType.fromJson(v))), + instances = (json['instances'] as List) + .map((v) => ProtocolInstance.fromJson(v)) + .toList(); Map toJson() { final data = {}; diff --git a/lib/src/model/supported_versions.dart b/lib/src/model/supported_versions.dart index 92b5160f..42b8bc6b 100644 --- a/lib/src/model/supported_versions.dart +++ b/lib/src/model/supported_versions.dart @@ -25,10 +25,10 @@ class SupportedVersions { List versions; Map unstableFeatures; - SupportedVersions.fromJson(Map json) { - versions = json['versions'].cast(); - unstableFeatures = Map.from(json['unstable_features'] ?? {}); - } + SupportedVersions.fromJson(Map json) + : versions = json['versions'].cast(), + unstableFeatures = + Map.from(json['unstable_features'] ?? {}); Map toJson() { final data = {}; diff --git a/lib/src/model/sync_update.dart b/lib/src/model/sync_update.dart index 741b3405..a847eed5 100644 --- a/lib/src/model/sync_update.dart +++ b/lib/src/model/sync_update.dart @@ -41,39 +41,42 @@ class SyncUpdate { SyncUpdate(); - SyncUpdate.fromJson(Map json) { - nextBatch = json['next_batch']; - rooms = json['rooms'] != null ? RoomsUpdate.fromJson(json['rooms']) : null; - presence = (json['presence'] != null && json['presence']['events'] != null) - ? (json['presence']['events'] as List) - .map((i) => Presence.fromJson(i)) - .toList() - : null; - accountData = - (json['account_data'] != null && json['account_data']['events'] != null) + SyncUpdate.fromJson(Map json) + : nextBatch = json['next_batch'], + rooms = + json['rooms'] != null ? RoomsUpdate.fromJson(json['rooms']) : null, + presence = + (json['presence'] != null && json['presence']['events'] != null) + ? (json['presence']['events'] as List) + .map((i) => Presence.fromJson(i)) + .toList() + : null, + accountData = (json['account_data'] != null && + json['account_data']['events'] != null) ? (json['account_data']['events'] as List) .map((i) => BasicEvent.fromJson(i)) .toList() + : null, + toDevice = + (json['to_device'] != null && json['to_device']['events'] != null) + ? (json['to_device']['events'] as List) + .map((i) => BasicEventWithSender.fromJson(i)) + .toList() + : null, + deviceLists = json['device_lists'] != null + ? DeviceListsUpdate.fromJson(json['device_lists']) + : null, + deviceOneTimeKeysCount = json['device_one_time_keys_count'] != null + ? Map.from(json['device_one_time_keys_count']) + : null, + deviceUnusedFallbackKeyTypes = (json[ + 'device_unused_fallback_key_types'] ?? + json[ + 'org.matrix.msc2732.device_unused_fallback_key_types']) != + null + ? List.from(json['device_unused_fallback_key_types'] ?? + json['org.matrix.msc2732.device_unused_fallback_key_types']) : null; - toDevice = - (json['to_device'] != null && json['to_device']['events'] != null) - ? (json['to_device']['events'] as List) - .map((i) => BasicEventWithSender.fromJson(i)) - .toList() - : null; - deviceLists = json['device_lists'] != null - ? DeviceListsUpdate.fromJson(json['device_lists']) - : null; - deviceOneTimeKeysCount = json['device_one_time_keys_count'] != null - ? Map.from(json['device_one_time_keys_count']) - : null; - deviceUnusedFallbackKeyTypes = (json['device_unused_fallback_key_types'] ?? - json['org.matrix.msc2732.device_unused_fallback_key_types']) != - null - ? List.from(json['device_unused_fallback_key_types'] ?? - json['org.matrix.msc2732.device_unused_fallback_key_types']) - : null; - } Map toJson() { final data = {}; diff --git a/lib/src/model/tag.dart b/lib/src/model/tag.dart index 5b3968a1..3329b551 100644 --- a/lib/src/model/tag.dart +++ b/lib/src/model/tag.dart @@ -24,9 +24,8 @@ class Tag { double order; - Tag.fromJson(Map json) { - order = double.tryParse(json['order'].toString()); - } + Tag.fromJson(Map json) + : order = double.tryParse(json['order'].toString()); Map toJson() { final data = {}; diff --git a/lib/src/model/third_party_identifier.dart b/lib/src/model/third_party_identifier.dart index 7ca0c2ad..b6ab7b90 100644 --- a/lib/src/model/third_party_identifier.dart +++ b/lib/src/model/third_party_identifier.dart @@ -29,13 +29,12 @@ class ThirdPartyIdentifier { int validatedAt; int addedAt; - ThirdPartyIdentifier.fromJson(Map json) { - medium = ThirdPartyIdentifierMedium.values - .firstWhere((medium) => describeEnum(medium) == json['medium']); - address = json['address']; - validatedAt = json['validated_at']; - addedAt = json['added_at']; - } + ThirdPartyIdentifier.fromJson(Map json) + : medium = ThirdPartyIdentifierMedium.values + .firstWhere((medium) => describeEnum(medium) == json['medium']), + address = json['address'], + validatedAt = json['validated_at'], + addedAt = json['added_at']; Map toJson() { final data = {}; diff --git a/lib/src/model/third_party_location.dart b/lib/src/model/third_party_location.dart index 0206a283..a2271f9b 100644 --- a/lib/src/model/third_party_location.dart +++ b/lib/src/model/third_party_location.dart @@ -28,11 +28,10 @@ class ThirdPartyLocation { String protocol; Map fields; - ThirdPartyLocation.fromJson(Map json) { - alias = json['alias']; - protocol = json['protocol']; - fields = (json['fields'] as Map).copy(); - } + ThirdPartyLocation.fromJson(Map json) + : alias = json['alias'], + protocol = json['protocol'], + fields = (json['fields'] as Map).copy(); Map toJson() { final data = {}; diff --git a/lib/src/model/third_party_user.dart b/lib/src/model/third_party_user.dart index 40a67893..a4289b2a 100644 --- a/lib/src/model/third_party_user.dart +++ b/lib/src/model/third_party_user.dart @@ -28,11 +28,10 @@ class ThirdPartyUser { String protocol; Map fields; - ThirdPartyUser.fromJson(Map json) { - userId = json['userid']; - protocol = json['protocol']; - fields = (json['fields'] as Map).copy(); - } + ThirdPartyUser.fromJson(Map json) + : userId = json['userid'], + protocol = json['protocol'], + fields = (json['fields'] as Map).copy(); Map toJson() { final data = {}; diff --git a/lib/src/model/timeline_history_response.dart b/lib/src/model/timeline_history_response.dart index 84a68fb2..e9806b89 100644 --- a/lib/src/model/timeline_history_response.dart +++ b/lib/src/model/timeline_history_response.dart @@ -29,16 +29,19 @@ class TimelineHistoryResponse { List chunk; List state; - TimelineHistoryResponse.fromJson(Map json) { - start = json['start']; - end = json['end']; - chunk = json['chunk'] != null - ? (json['chunk'] as List).map((i) => MatrixEvent.fromJson(i)).toList() - : null; - state = json['state'] != null - ? (json['state'] as List).map((i) => MatrixEvent.fromJson(i)).toList() - : null; - } + TimelineHistoryResponse.fromJson(Map json) + : start = json['start'], + end = json['end'], + chunk = json['chunk'] != null + ? (json['chunk'] as List) + .map((i) => MatrixEvent.fromJson(i)) + .toList() + : null, + state = json['state'] != null + ? (json['state'] as List) + .map((i) => MatrixEvent.fromJson(i)) + .toList() + : null; Map toJson() { final data = {}; diff --git a/lib/src/model/turn_server_credentials.dart b/lib/src/model/turn_server_credentials.dart index 67fca47a..81b36c9e 100644 --- a/lib/src/model/turn_server_credentials.dart +++ b/lib/src/model/turn_server_credentials.dart @@ -27,12 +27,11 @@ class TurnServerCredentials { List uris; num ttl; - TurnServerCredentials.fromJson(Map json) { - username = json['username']; - password = json['password']; - uris = json['uris'].cast(); - ttl = json['ttl']; - } + TurnServerCredentials.fromJson(Map json) + : username = json['username'], + password = json['password'], + uris = json['uris'].cast(), + ttl = json['ttl']; Map toJson() { final data = {}; diff --git a/lib/src/model/upload_key_signatures_response.dart b/lib/src/model/upload_key_signatures_response.dart index cf845766..b53e01a2 100644 --- a/lib/src/model/upload_key_signatures_response.dart +++ b/lib/src/model/upload_key_signatures_response.dart @@ -26,19 +26,18 @@ import 'matrix_exception.dart'; class UploadKeySignaturesResponse { Map> failures; - UploadKeySignaturesResponse.fromJson(Map json) { - failures = json['failures'] != null - ? (json['failures'] as Map).map( - (k, v) => MapEntry( - k, - (v as Map).map((k, v) => MapEntry( - k, - MatrixException.fromJson(v), - )), - ), - ) - : null; - } + UploadKeySignaturesResponse.fromJson(Map json) + : failures = json['failures'] != null + ? (json['failures'] as Map).map( + (k, v) => MapEntry( + k, + (v as Map).map((k, v) => MapEntry( + k, + MatrixException.fromJson(v), + )), + ), + ) + : null; Map toJson() { final data = {}; diff --git a/lib/src/model/user_search_result.dart b/lib/src/model/user_search_result.dart index 27c84d7c..8da4b82a 100644 --- a/lib/src/model/user_search_result.dart +++ b/lib/src/model/user_search_result.dart @@ -27,11 +27,10 @@ class UserSearchResult { List results; bool limited; - UserSearchResult.fromJson(Map json) { - results = - (json['results'] as List).map((v) => Profile.fromJson(v)).toList(); - limited = json['limited']; - } + UserSearchResult.fromJson(Map json) + : results = + (json['results'] as List).map((v) => Profile.fromJson(v)).toList(), + limited = json['limited']; Map toJson() { final data = {}; diff --git a/lib/src/model/well_known_information.dart b/lib/src/model/well_known_information.dart index 631ef698..dbeb1a84 100644 --- a/lib/src/model/well_known_information.dart +++ b/lib/src/model/well_known_information.dart @@ -28,18 +28,23 @@ class WellKnownInformation { MHomeserver mIdentityServer; Map content; - WellKnownInformation.fromJson(Map json) { - content = json; - final mHomeserverMap = json.tryGetMap('m.homeserver'); - if (mHomeserverMap != null) { - mHomeserver = MHomeserver.fromJson(mHomeserverMap); - } - final mIdentityServerMap = - json.tryGetMap('m.identity_server'); - if (mIdentityServerMap != null) { - mIdentityServer = MHomeserver.fromJson(mIdentityServerMap); - } - } + factory WellKnownInformation.fromJson(Map json) => + WellKnownInformation._fromJson( + json, + json.tryGetMap('m.homeserver'), + json.tryGetMap('m.identity_server')); + + WellKnownInformation._fromJson( + Map json, + Map mHomeserverMap, + Map mIdentityServerMap) + : content = json, + mHomeserver = mHomeserverMap != null + ? MHomeserver.fromJson(mHomeserverMap) + : null, + mIdentityServer = mIdentityServerMap != null + ? MHomeserver.fromJson(mIdentityServerMap) + : null; Map toJson() { final data = content; diff --git a/lib/src/model/who_is_info.dart b/lib/src/model/who_is_info.dart index 5504a24d..3d47930c 100644 --- a/lib/src/model/who_is_info.dart +++ b/lib/src/model/who_is_info.dart @@ -25,13 +25,12 @@ class WhoIsInfo { String userId; Map devices; - WhoIsInfo.fromJson(Map json) { - userId = json['user_id']; - devices = json['devices'] != null - ? (json['devices'] as Map) - .map((k, v) => MapEntry(k, DeviceInfo.fromJson(v))) - : null; - } + WhoIsInfo.fromJson(Map json) + : userId = json['user_id'], + devices = json['devices'] != null + ? (json['devices'] as Map) + .map((k, v) => MapEntry(k, DeviceInfo.fromJson(v))) + : null; Map toJson() { final data = {};