refactor: initializer lists in fromJson constructors

This commit is contained in:
Lukas Lihotzki 2021-05-05 12:05:26 +02:00
parent 23db25d4af
commit 9de57fad9b
48 changed files with 372 additions and 401 deletions

View File

@ -27,10 +27,9 @@ class AuthenticationData {
AuthenticationData({this.type, this.session});
AuthenticationData.fromJson(Map<String, dynamic> json) {
type = json['type'];
session = json['session'];
}
AuthenticationData.fromJson(Map<String, dynamic> json)
: type = json['type'],
session = json['session'];
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -26,9 +26,8 @@ class AuthenticationIdentifier {
AuthenticationIdentifier({this.type});
AuthenticationIdentifier.fromJson(Map<String, dynamic> json) {
type = json['type'];
}
AuthenticationIdentifier.fromJson(Map<String, dynamic> json)
: type = json['type'];
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -45,10 +45,10 @@ class AuthenticationPassword extends AuthenticationData {
);
AuthenticationPassword.fromJson(Map<String, dynamic> 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']);

View File

@ -32,10 +32,9 @@ class AuthenticationPhoneIdentifier extends AuthenticationIdentifier {
: super(type: AuthenticationIdentifierTypes.phone);
AuthenticationPhoneIdentifier.fromJson(Map<String, dynamic> json)
: super.fromJson(json) {
country = json['country'];
phone = json['phone'];
}
: country = json['country'],
phone = json['phone'],
super.fromJson(json);
@override
Map<String, dynamic> toJson() {

View File

@ -34,9 +34,8 @@ class AuthenticationRecaptcha extends AuthenticationData {
);
AuthenticationRecaptcha.fromJson(Map<String, dynamic> json)
: super.fromJson(json) {
response = json['response'];
}
: response = json['response'],
super.fromJson(json);
@override
Map<String, dynamic> toJson() {

View File

@ -32,10 +32,9 @@ class AuthenticationThirdPartyIdentifier extends AuthenticationIdentifier {
: super(type: AuthenticationIdentifierTypes.thirdParty);
AuthenticationThirdPartyIdentifier.fromJson(Map<String, dynamic> json)
: super.fromJson(json) {
medium = json['medium'];
address = json['address'];
}
: medium = json['medium'],
address = json['address'],
super.fromJson(json);
@override
Map<String, dynamic> toJson() {

View File

@ -72,12 +72,11 @@ class ThreepidCreds {
ThreepidCreds(
{this.sid, this.clientSecret, this.idServer, this.idAccessToken});
ThreepidCreds.fromJson(Map<String, dynamic> json) {
sid = json['sid'];
clientSecret = json['client_secret'];
idServer = json['id_server'];
idAccessToken = json['id_access_token'];
}
ThreepidCreds.fromJson(Map<String, dynamic> json)
: sid = json['sid'],
clientSecret = json['client_secret'],
idServer = json['id_server'],
idAccessToken = json['id_access_token'];
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -35,10 +35,9 @@ class AuthenticationToken extends AuthenticationData {
);
AuthenticationToken.fromJson(Map<String, dynamic> json)
: super.fromJson(json) {
token = json['token'];
txnId = json['txn_id'];
}
: token = json['token'],
txnId = json['txn_id'],
super.fromJson(json);
@override
Map<String, dynamic> toJson() {

View File

@ -31,9 +31,8 @@ class AuthenticationUserIdentifier extends AuthenticationIdentifier {
: super(type: AuthenticationIdentifierTypes.userId);
AuthenticationUserIdentifier.fromJson(Map<String, dynamic> json)
: super.fromJson(json) {
user = json['user'];
}
: user = json['user'],
super.fromJson(json);
@override
Map<String, dynamic> toJson() {

View File

@ -32,10 +32,10 @@ class BasicEvent {
this.content,
});
BasicEvent.fromJson(Map<String, dynamic> json) {
type = json['type'];
content = (json['content'] as Map<String, dynamic>).copy();
}
BasicEvent.fromJson(Map<String, dynamic> json)
: type = json['type'],
content = (json['content'] as Map<String, dynamic>).copy();
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['type'] = type;

View File

@ -29,9 +29,8 @@ class BasicEventWithSender extends BasicEvent {
BasicEventWithSender();
BasicEventWithSender.fromJson(Map<String, dynamic> json)
: super.fromJson(json) {
senderId = json['sender'];
}
: senderId = json['sender'],
super.fromJson(json);
@override
Map<String, dynamic> toJson() {

View File

@ -35,9 +35,9 @@ class BasicRoomEvent extends BasicEvent {
type: type,
);
BasicRoomEvent.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
roomId = json['room_id'];
}
BasicRoomEvent.fromJson(Map<String, dynamic> json)
: roomId = json['room_id'],
super.fromJson(json);
@override
Map<String, dynamic> toJson() {

View File

@ -27,12 +27,12 @@ class Device {
String lastSeenIp;
DateTime lastSeenTs;
Device.fromJson(Map<String, dynamic> 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<String, dynamic> json)
: deviceId = json['device_id'],
displayName = json['display_name'],
lastSeenIp = json['last_seen_ip'],
lastSeenTs =
DateTime.fromMillisecondsSinceEpoch(json['last_seen_ts'] ?? 0);
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -31,25 +31,26 @@ class EventContext {
String start;
List<MatrixEvent> state;
EventContext.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -28,13 +28,14 @@ class EventsSyncUpdate {
String end;
List<MatrixEvent> chunk;
EventsSyncUpdate.fromJson(Map<String, dynamic> 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<String, dynamic> json)
: start = json['start'],
end = json['end'],
chunk = json['chunk'] != null
? (json['chunk'] as List)
.map((i) => MatrixEvent.fromJson(i))
.toList()
: null;
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -38,22 +38,21 @@ class Filter {
this.eventFields,
});
Filter.fromJson(Map<String, dynamic> 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<String>()
: null;
}
Filter.fromJson(Map<String, dynamic> 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<String>()
: null;
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -31,48 +31,45 @@ class KeysQueryResponse {
Map<String, MatrixCrossSigningKey> selfSigningKeys;
Map<String, MatrixCrossSigningKey> userSigningKeys;
KeysQueryResponse.fromJson(Map<String, dynamic> json) {
failures = (json['failures'] as Map<String, dynamic>)?.copy();
deviceKeys = json['device_keys'] != null
? (json['device_keys'] as Map).map(
(k, v) => MapEntry(
k,
(v as Map).map(
KeysQueryResponse.fromJson(Map<String, dynamic> json)
: failures = (json['failures'] as Map<String, dynamic>)?.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<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -29,14 +29,13 @@ class LoginResponse {
String deviceId;
WellKnownInformation wellKnownInformation;
LoginResponse.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -34,15 +34,15 @@ class MatrixEvent extends StrippedStateEvent {
MatrixEvent();
MatrixEvent.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
eventId = json['event_id'];
roomId = json['room_id'];
originServerTs =
DateTime.fromMillisecondsSinceEpoch(json['origin_server_ts']);
unsigned = (json['unsigned'] as Map<String, dynamic>)?.copy();
prevContent = (json['prev_content'] as Map<String, dynamic>)?.copy();
redacts = json['redacts'];
}
MatrixEvent.fromJson(Map<String, dynamic> json)
: eventId = json['event_id'],
roomId = json['room_id'],
originServerTs =
DateTime.fromMillisecondsSinceEpoch(json['origin_server_ts']),
unsigned = (json['unsigned'] as Map<String, dynamic>)?.copy(),
prevContent = (json['prev_content'] as Map<String, dynamic>)?.copy(),
redacts = json['redacts'],
super.fromJson(json);
@override
Map<String, dynamic> toJson() {

View File

@ -36,17 +36,16 @@ class MatrixSignableKey {
// This object is used for signing so we need the raw json too
Map<String, dynamic> _json;
MatrixSignableKey.fromJson(Map<String, dynamic> json) {
_json = json;
userId = json['user_id'];
keys = Map<String, String>.from(json['keys']);
// we need to manually copy to ensure that our map is Map<String, Map<String, String>>
signatures = json['signatures'] is Map
? Map<String, Map<String, String>>.from((json['signatures'] as Map)
.map((k, v) => MapEntry(k, Map<String, String>.from(v))))
: null;
unsigned = (json['unsigned'] as Map<String, dynamic>)?.copy();
}
MatrixSignableKey.fromJson(Map<String, dynamic> json)
: _json = json,
userId = json['user_id'],
keys = Map<String, String>.from(json['keys']),
// we need to manually copy to ensure that our map is Map<String, Map<String, String>>
signatures = json['signatures'] is Map
? Map<String, Map<String, String>>.from((json['signatures'] as Map)
.map((k, v) => MapEntry(k, Map<String, String>.from(v))))
: null,
unsigned = (json['unsigned'] as Map<String, dynamic>)?.copy();
Map<String, dynamic> toJson() {
final data = _json ?? <String, dynamic>{};

View File

@ -27,12 +27,11 @@ class NotificationsQueryResponse {
String nextToken;
List<Notification> notifications;
NotificationsQueryResponse.fromJson(Map<String, dynamic> json) {
nextToken = json['next_token'];
notifications = (json['notifications'] as List)
.map((v) => Notification.fromJson(v))
.toList();
}
NotificationsQueryResponse.fromJson(Map<String, dynamic> json)
: nextToken = json['next_token'],
notifications = (json['notifications'] as List)
.map((v) => Notification.fromJson(v))
.toList();
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -27,12 +27,11 @@ class OneTimeKeysClaimResponse {
Map<String, dynamic> failures;
Map<String, Map<String, dynamic>> oneTimeKeys;
OneTimeKeysClaimResponse.fromJson(Map<String, dynamic> json) {
failures = (json['failures'] as Map<String, dynamic>)?.copy() ?? {};
// We still need a Map<...>.from(...) to ensure all second-level entries are also maps
oneTimeKeys = Map<String, Map<String, dynamic>>.from(
(json['one_time_keys'] as Map<String, dynamic>).copy());
}
OneTimeKeysClaimResponse.fromJson(Map<String, dynamic> json)
: failures = (json['failures'] as Map<String, dynamic>)?.copy() ?? {},
// We still need a Map<...>.from(...) to ensure all second-level entries are also maps
oneTimeKeys = Map<String, Map<String, dynamic>>.from(
(json['one_time_keys'] as Map<String, dynamic>).copy());
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -30,15 +30,14 @@ class OpenGraphData {
int ogImageWidth;
int matrixImageSize;
OpenGraphData.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -27,12 +27,11 @@ class OpenIdCredentials {
String matrixServerName;
double expiresIn;
OpenIdCredentials.fromJson(Map<String, dynamic> json) {
accessToken = json['access_token'];
tokenType = json['token_type'];
matrixServerName = json['matrix_server_name'];
expiresIn = json['expires_in'];
}
OpenIdCredentials.fromJson(Map<String, dynamic> json)
: accessToken = json['access_token'],
tokenType = json['token_type'],
matrixServerName = json['matrix_server_name'],
expiresIn = json['expires_in'];
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

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

View File

@ -29,13 +29,12 @@ class PresenceContent {
String statusMsg;
bool currentlyActive;
PresenceContent.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -27,12 +27,12 @@ class PublicRoomsResponse {
String prevBatch;
int totalRoomCountEstimate;
PublicRoomsResponse.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> toJson() {
final data = <String, dynamic>{};
@ -61,17 +61,16 @@ class PublicRoom {
bool worldReadable;
String canonicalAlias;
PublicRoom.fromJson(Map<String, dynamic> json) {
aliases = json['aliases']?.cast<String>();
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<String, dynamic> json)
: aliases = json['aliases']?.cast<String>(),
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<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -42,16 +42,15 @@ class Pusher {
this.kind,
});
Pusher.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> toJson() {
final data = <String, dynamic>{};
@ -78,12 +77,9 @@ class PusherData {
this.format,
});
PusherData.fromJson(Map<String, dynamic> json) {
if (json.containsKey('url')) {
url = Uri.parse(json['url']);
}
format = json['format'];
}
PusherData.fromJson(Map<String, dynamic> json)
: format = json['format'],
url = json.containsKey('url') ? Uri.parse(json['url']) : null;
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -25,10 +25,9 @@ class RequestTokenResponse {
String sid;
String submitUrl;
RequestTokenResponse.fromJson(Map<String, dynamic> json) {
sid = json['sid'];
submitUrl = json['submit_url'];
}
RequestTokenResponse.fromJson(Map<String, dynamic> json)
: sid = json['sid'],
submitUrl = json['submit_url'];
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -25,10 +25,9 @@ class RoomAliasInformation {
String roomId;
List<String> servers;
RoomAliasInformation.fromJson(Map<String, dynamic> json) {
roomId = json['room_id'];
servers = json['servers'].cast<String>();
}
RoomAliasInformation.fromJson(Map<String, dynamic> json)
: roomId = json['room_id'],
servers = json['servers'].cast<String>();
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -52,15 +52,14 @@ class RoomKeysVersionResponse {
String etag;
String version;
RoomKeysVersionResponse.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -33,12 +33,11 @@ class RoomKeysSingleKey {
this.isVerified,
this.sessionData});
RoomKeysSingleKey.fromJson(Map<String, dynamic> json) {
firstMessageIndex = json['first_message_index'];
forwardedCount = json['forwarded_count'];
isVerified = json['is_verified'];
sessionData = json['session_data'];
}
RoomKeysSingleKey.fromJson(Map<String, dynamic> json)
: firstMessageIndex = json['first_message_index'],
forwardedCount = json['forwarded_count'],
isVerified = json['is_verified'],
sessionData = json['session_data'];
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
@ -57,10 +56,9 @@ class RoomKeysRoom {
sessions ??= <String, RoomKeysSingleKey>{};
}
RoomKeysRoom.fromJson(Map<String, dynamic> json) {
sessions = (json['sessions'] as Map)
.map((k, v) => MapEntry(k, RoomKeysSingleKey.fromJson(v)));
}
RoomKeysRoom.fromJson(Map<String, dynamic> json)
: sessions = (json['sessions'] as Map)
.map((k, v) => MapEntry(k, RoomKeysSingleKey.fromJson(v)));
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
@ -76,10 +74,9 @@ class RoomKeys {
rooms ??= <String, RoomKeysRoom>{};
}
RoomKeys.fromJson(Map<String, dynamic> json) {
rooms = (json['rooms'] as Map)
.map((k, v) => MapEntry(k, RoomKeysRoom.fromJson(v)));
}
RoomKeys.fromJson(Map<String, dynamic> json)
: rooms = (json['rooms'] as Map)
.map((k, v) => MapEntry(k, RoomKeysRoom.fromJson(v)));
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
@ -92,10 +89,9 @@ class RoomKeysUpdateResponse {
String etag;
int count;
RoomKeysUpdateResponse.fromJson(Map<String, dynamic> json) {
etag = json['etag']; // synapse replies an int but docs say string?
count = json['count'];
}
RoomKeysUpdateResponse.fromJson(Map<String, dynamic> json)
: etag = json['etag'], // synapse replies an int but docs say string?
count = json['count'];
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

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

View File

@ -30,17 +30,16 @@ class ServerCapabilities {
MRoomVersions mRoomVersions;
Map<String, dynamic> customCapabilities;
ServerCapabilities.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -28,9 +28,8 @@ class StrippedStateEvent extends BasicEventWithSender {
StrippedStateEvent();
StrippedStateEvent.fromJson(Map<String, dynamic> json)
: super.fromJson(json) {
stateKey = json['state_key'];
}
: stateKey = json['state_key'],
super.fromJson(json);
@override
Map<String, dynamic> toJson() {

View File

@ -28,16 +28,15 @@ class SupportedProtocol {
Map<String, ProtocolFieldType> fieldTypes;
List<ProtocolInstance> instances;
SupportedProtocol.fromJson(Map<String, dynamic> json) {
userFields = json['user_fields'].cast<String>();
locationFields = json['location_fields'].cast<String>();
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<String, dynamic> json)
: userFields = json['user_fields'].cast<String>(),
locationFields = json['location_fields'].cast<String>(),
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<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -25,10 +25,10 @@ class SupportedVersions {
List<String> versions;
Map<String, bool> unstableFeatures;
SupportedVersions.fromJson(Map<String, dynamic> json) {
versions = json['versions'].cast<String>();
unstableFeatures = Map<String, bool>.from(json['unstable_features'] ?? {});
}
SupportedVersions.fromJson(Map<String, dynamic> json)
: versions = json['versions'].cast<String>(),
unstableFeatures =
Map<String, bool>.from(json['unstable_features'] ?? {});
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -41,39 +41,42 @@ class SyncUpdate {
SyncUpdate();
SyncUpdate.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, int>.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<String>.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<String, int>.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<String>.from(json['device_unused_fallback_key_types'] ??
json['org.matrix.msc2732.device_unused_fallback_key_types'])
: null;
}
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -24,9 +24,8 @@
class Tag {
double order;
Tag.fromJson(Map<String, dynamic> json) {
order = double.tryParse(json['order'].toString());
}
Tag.fromJson(Map<String, dynamic> json)
: order = double.tryParse(json['order'].toString());
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -29,13 +29,12 @@ class ThirdPartyIdentifier {
int validatedAt;
int addedAt;
ThirdPartyIdentifier.fromJson(Map<String, dynamic> json) {
medium = ThirdPartyIdentifierMedium.values
.firstWhere((medium) => describeEnum(medium) == json['medium']);
address = json['address'];
validatedAt = json['validated_at'];
addedAt = json['added_at'];
}
ThirdPartyIdentifier.fromJson(Map<String, dynamic> json)
: medium = ThirdPartyIdentifierMedium.values
.firstWhere((medium) => describeEnum(medium) == json['medium']),
address = json['address'],
validatedAt = json['validated_at'],
addedAt = json['added_at'];
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -28,11 +28,10 @@ class ThirdPartyLocation {
String protocol;
Map<String, dynamic> fields;
ThirdPartyLocation.fromJson(Map<String, dynamic> json) {
alias = json['alias'];
protocol = json['protocol'];
fields = (json['fields'] as Map<String, dynamic>).copy();
}
ThirdPartyLocation.fromJson(Map<String, dynamic> json)
: alias = json['alias'],
protocol = json['protocol'],
fields = (json['fields'] as Map<String, dynamic>).copy();
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -28,11 +28,10 @@ class ThirdPartyUser {
String protocol;
Map<String, dynamic> fields;
ThirdPartyUser.fromJson(Map<String, dynamic> json) {
userId = json['userid'];
protocol = json['protocol'];
fields = (json['fields'] as Map<String, dynamic>).copy();
}
ThirdPartyUser.fromJson(Map<String, dynamic> json)
: userId = json['userid'],
protocol = json['protocol'],
fields = (json['fields'] as Map<String, dynamic>).copy();
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -29,16 +29,19 @@ class TimelineHistoryResponse {
List<MatrixEvent> chunk;
List<MatrixEvent> state;
TimelineHistoryResponse.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -27,12 +27,11 @@ class TurnServerCredentials {
List<String> uris;
num ttl;
TurnServerCredentials.fromJson(Map<String, dynamic> json) {
username = json['username'];
password = json['password'];
uris = json['uris'].cast<String>();
ttl = json['ttl'];
}
TurnServerCredentials.fromJson(Map<String, dynamic> json)
: username = json['username'],
password = json['password'],
uris = json['uris'].cast<String>(),
ttl = json['ttl'];
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -26,19 +26,18 @@ import 'matrix_exception.dart';
class UploadKeySignaturesResponse {
Map<String, Map<String, MatrixException>> failures;
UploadKeySignaturesResponse.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -27,11 +27,10 @@ class UserSearchResult {
List<Profile> results;
bool limited;
UserSearchResult.fromJson(Map<String, dynamic> json) {
results =
(json['results'] as List).map((v) => Profile.fromJson(v)).toList();
limited = json['limited'];
}
UserSearchResult.fromJson(Map<String, dynamic> json)
: results =
(json['results'] as List).map((v) => Profile.fromJson(v)).toList(),
limited = json['limited'];
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

@ -28,18 +28,23 @@ class WellKnownInformation {
MHomeserver mIdentityServer;
Map<String, dynamic> content;
WellKnownInformation.fromJson(Map<String, dynamic> json) {
content = json;
final mHomeserverMap = json.tryGetMap<String, dynamic>('m.homeserver');
if (mHomeserverMap != null) {
mHomeserver = MHomeserver.fromJson(mHomeserverMap);
}
final mIdentityServerMap =
json.tryGetMap<String, dynamic>('m.identity_server');
if (mIdentityServerMap != null) {
mIdentityServer = MHomeserver.fromJson(mIdentityServerMap);
}
}
factory WellKnownInformation.fromJson(Map<String, dynamic> json) =>
WellKnownInformation._fromJson(
json,
json.tryGetMap<String, dynamic>('m.homeserver'),
json.tryGetMap<String, dynamic>('m.identity_server'));
WellKnownInformation._fromJson(
Map<String, dynamic> json,
Map<String, dynamic> mHomeserverMap,
Map<String, dynamic> mIdentityServerMap)
: content = json,
mHomeserver = mHomeserverMap != null
? MHomeserver.fromJson(mHomeserverMap)
: null,
mIdentityServer = mIdentityServerMap != null
? MHomeserver.fromJson(mIdentityServerMap)
: null;
Map<String, dynamic> toJson() {
final data = content;

View File

@ -25,13 +25,12 @@ class WhoIsInfo {
String userId;
Map<String, DeviceInfo> devices;
WhoIsInfo.fromJson(Map<String, dynamic> 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<String, dynamic> json)
: userId = json['user_id'],
devices = json['devices'] != null
? (json['devices'] as Map)
.map((k, v) => MapEntry(k, DeviceInfo.fromJson(v)))
: null;
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};