refactor: initializer lists in fromJson constructors
This commit is contained in:
parent
23db25d4af
commit
9de57fad9b
|
|
@ -27,10 +27,9 @@ class AuthenticationData {
|
|||
|
||||
AuthenticationData({this.type, this.session});
|
||||
|
||||
AuthenticationData.fromJson(Map<String, dynamic> json) {
|
||||
type = json['type'];
|
||||
AuthenticationData.fromJson(Map<String, dynamic> json)
|
||||
: type = json['type'],
|
||||
session = json['session'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -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>{};
|
||||
|
|
|
|||
|
|
@ -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']);
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ class BasicEvent {
|
|||
this.content,
|
||||
});
|
||||
|
||||
BasicEvent.fromJson(Map<String, dynamic> json) {
|
||||
type = json['type'];
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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>{};
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
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();
|
||||
}
|
||||
event = json['event'] != null ? MatrixEvent.fromJson(json['event']) : null;
|
||||
if (json['events_before'] != null) {
|
||||
eventsBefore = (json['events_before'] as List)
|
||||
.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();
|
||||
}
|
||||
start = json['start'];
|
||||
if (json['state'] != null) {
|
||||
state =
|
||||
(json['state'] as List).map((v) => MatrixEvent.fromJson(v)).toList();
|
||||
}
|
||||
}
|
||||
.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>{};
|
||||
|
|
|
|||
|
|
@ -28,13 +28,14 @@ class EventsSyncUpdate {
|
|||
String end;
|
||||
List<MatrixEvent> chunk;
|
||||
|
||||
EventsSyncUpdate.fromJson(Map<String, dynamic> json) {
|
||||
start = json['start'];
|
||||
end = json['end'];
|
||||
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()
|
||||
? (json['chunk'] as List)
|
||||
.map((i) => MatrixEvent.fromJson(i))
|
||||
.toList()
|
||||
: null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -38,22 +38,21 @@ class Filter {
|
|||
this.eventFields,
|
||||
});
|
||||
|
||||
Filter.fromJson(Map<String, dynamic> json) {
|
||||
room = json['room'] != null ? RoomFilter.fromJson(json['room']) : 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;
|
||||
: null,
|
||||
accountData = json['account_data'] != null
|
||||
? EventFilter.fromJson(json['account_data'])
|
||||
: null;
|
||||
: null,
|
||||
eventFormat = json['event_format'] != null
|
||||
? EventFormat.values.firstWhere(
|
||||
(e) => e.toString().split('.').last == json['event_format'])
|
||||
: null;
|
||||
: null,
|
||||
eventFields = json['event_fields'] != null
|
||||
? json['event_fields'].cast<String>()
|
||||
: null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ class KeysQueryResponse {
|
|||
Map<String, MatrixCrossSigningKey> selfSigningKeys;
|
||||
Map<String, MatrixCrossSigningKey> userSigningKeys;
|
||||
|
||||
KeysQueryResponse.fromJson(Map<String, dynamic> json) {
|
||||
failures = (json['failures'] as Map<String, dynamic>)?.copy();
|
||||
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(
|
||||
|
|
@ -45,7 +45,7 @@ class KeysQueryResponse {
|
|||
),
|
||||
),
|
||||
)
|
||||
: null;
|
||||
: null,
|
||||
masterKeys = json['master_keys'] != null
|
||||
? (json['master_keys'] as Map).map(
|
||||
(k, v) => MapEntry(
|
||||
|
|
@ -53,8 +53,7 @@ class KeysQueryResponse {
|
|||
MatrixCrossSigningKey.fromJson(v),
|
||||
),
|
||||
)
|
||||
: null;
|
||||
|
||||
: null,
|
||||
selfSigningKeys = json['self_signing_keys'] != null
|
||||
? (json['self_signing_keys'] as Map).map(
|
||||
(k, v) => MapEntry(
|
||||
|
|
@ -62,8 +61,7 @@ class KeysQueryResponse {
|
|||
MatrixCrossSigningKey.fromJson(v),
|
||||
),
|
||||
)
|
||||
: null;
|
||||
|
||||
: null,
|
||||
userSigningKeys = json['user_signing_keys'] != null
|
||||
? (json['user_signing_keys'] as Map).map(
|
||||
(k, v) => MapEntry(
|
||||
|
|
@ -72,7 +70,6 @@ class KeysQueryResponse {
|
|||
),
|
||||
)
|
||||
: null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -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>{};
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
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'];
|
||||
}
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -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']);
|
||||
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;
|
||||
: null,
|
||||
unsigned = (json['unsigned'] as Map<String, dynamic>)?.copy();
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = _json ?? <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -27,12 +27,11 @@ class NotificationsQueryResponse {
|
|||
String nextToken;
|
||||
List<Notification> notifications;
|
||||
|
||||
NotificationsQueryResponse.fromJson(Map<String, dynamic> json) {
|
||||
nextToken = json['next_token'];
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -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() ?? {};
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
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'];
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -25,10 +25,9 @@ class RequestTokenResponse {
|
|||
String sid;
|
||||
String submitUrl;
|
||||
|
||||
RequestTokenResponse.fromJson(Map<String, dynamic> json) {
|
||||
sid = json['sid'];
|
||||
RequestTokenResponse.fromJson(Map<String, dynamic> json)
|
||||
: sid = json['sid'],
|
||||
submitUrl = json['submit_url'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -25,10 +25,9 @@ class RoomAliasInformation {
|
|||
String roomId;
|
||||
List<String> servers;
|
||||
|
||||
RoomAliasInformation.fromJson(Map<String, dynamic> json) {
|
||||
roomId = json['room_id'];
|
||||
RoomAliasInformation.fromJson(Map<String, dynamic> json)
|
||||
: roomId = json['room_id'],
|
||||
servers = json['servers'].cast<String>();
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
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)
|
||||
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)
|
||||
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?
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -30,17 +30,16 @@ class ServerCapabilities {
|
|||
MRoomVersions mRoomVersions;
|
||||
Map<String, dynamic> customCapabilities;
|
||||
|
||||
ServerCapabilities.fromJson(Map<String, dynamic> json) {
|
||||
mChangePassword = json['m.change_password'] != null
|
||||
ServerCapabilities.fromJson(Map<String, dynamic> json)
|
||||
: mChangePassword = json['m.change_password'] != null
|
||||
? MChangePassword.fromJson(json['m.change_password'])
|
||||
: null;
|
||||
: null,
|
||||
mRoomVersions = json['m.room_versions'] != null
|
||||
? MRoomVersions.fromJson(json['m.room_versions'])
|
||||
: null;
|
||||
: null,
|
||||
customCapabilities = json.copy()
|
||||
..remove('m.change_password')
|
||||
..remove('m.room_versions');
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
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)));
|
||||
.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>{};
|
||||
|
|
|
|||
|
|
@ -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>{};
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
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)
|
||||
: null,
|
||||
accountData = (json['account_data'] != null &&
|
||||
json['account_data']['events'] != null)
|
||||
? (json['account_data']['events'] as List)
|
||||
.map((i) => BasicEvent.fromJson(i))
|
||||
.toList()
|
||||
: null;
|
||||
: null,
|
||||
toDevice =
|
||||
(json['to_device'] != null && json['to_device']['events'] != null)
|
||||
? (json['to_device']['events'] as List)
|
||||
.map((i) => BasicEventWithSender.fromJson(i))
|
||||
.toList()
|
||||
: null;
|
||||
: null,
|
||||
deviceLists = json['device_lists'] != null
|
||||
? DeviceListsUpdate.fromJson(json['device_lists'])
|
||||
: null;
|
||||
: 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,
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -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>{};
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -28,11 +28,10 @@ class ThirdPartyLocation {
|
|||
String protocol;
|
||||
Map<String, dynamic> fields;
|
||||
|
||||
ThirdPartyLocation.fromJson(Map<String, dynamic> json) {
|
||||
alias = json['alias'];
|
||||
protocol = json['protocol'];
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -28,11 +28,10 @@ class ThirdPartyUser {
|
|||
String protocol;
|
||||
Map<String, dynamic> fields;
|
||||
|
||||
ThirdPartyUser.fromJson(Map<String, dynamic> json) {
|
||||
userId = json['userid'];
|
||||
protocol = json['protocol'];
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -29,16 +29,19 @@ class TimelineHistoryResponse {
|
|||
List<MatrixEvent> chunk;
|
||||
List<MatrixEvent> state;
|
||||
|
||||
TimelineHistoryResponse.fromJson(Map<String, dynamic> json) {
|
||||
start = json['start'];
|
||||
end = json['end'];
|
||||
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;
|
||||
? (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()
|
||||
? (json['state'] as List)
|
||||
.map((i) => MatrixEvent.fromJson(i))
|
||||
.toList()
|
||||
: null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -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>();
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ import 'matrix_exception.dart';
|
|||
class UploadKeySignaturesResponse {
|
||||
Map<String, Map<String, MatrixException>> failures;
|
||||
|
||||
UploadKeySignaturesResponse.fromJson(Map<String, dynamic> json) {
|
||||
failures = json['failures'] != null
|
||||
UploadKeySignaturesResponse.fromJson(Map<String, dynamic> json)
|
||||
: failures = json['failures'] != null
|
||||
? (json['failures'] as Map).map(
|
||||
(k, v) => MapEntry(
|
||||
k,
|
||||
|
|
@ -38,7 +38,6 @@ class UploadKeySignaturesResponse {
|
|||
),
|
||||
)
|
||||
: null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
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>{};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -25,13 +25,12 @@ class WhoIsInfo {
|
|||
String userId;
|
||||
Map<String, DeviceInfo> devices;
|
||||
|
||||
WhoIsInfo.fromJson(Map<String, dynamic> json) {
|
||||
userId = json['user_id'];
|
||||
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>{};
|
||||
|
|
|
|||
Loading…
Reference in New Issue