fix: tryGet log levels

This commit is contained in:
Lukas Lihotzki 2021-08-03 16:10:55 +02:00
parent 916711cf57
commit c73b7631f5
10 changed files with 59 additions and 65 deletions

View File

@ -36,11 +36,12 @@ class ForwardedRoomKeyContent extends RoomKeyContent {
List<String> forwardingCurve25519KeyChain; List<String> forwardingCurve25519KeyChain;
ForwardedRoomKeyContent.fromJson(Map<String, dynamic> json) ForwardedRoomKeyContent.fromJson(Map<String, dynamic> json)
: senderKey = json.tryGet('sender_key') ?? '', : senderKey = json.tryGet('sender_key', TryGet.required) ?? '',
senderClaimedEd25519Key = senderClaimedEd25519Key =
json.tryGet('sender_claimed_ed25519_key') ?? '', json.tryGet('sender_claimed_ed25519_key', TryGet.required) ?? '',
forwardingCurve25519KeyChain = forwardingCurve25519KeyChain = json.tryGetList(
json.tryGetList('forwarding_curve25519_key_chain') ?? [], 'forwarding_curve25519_key_chain', TryGet.required) ??
[],
super.fromJson(json); super.fromJson(json);
@override @override

View File

@ -77,22 +77,19 @@ class ImagePackContent {
: _json = Map.fromEntries(json.entries.where( : _json = Map.fromEntries(json.entries.where(
(e) => !['images', 'pack', 'emoticons', 'short'].contains(e.key))), (e) => !['images', 'pack', 'emoticons', 'short'].contains(e.key))),
pack = ImagePackPackContent.fromJson( pack = ImagePackPackContent.fromJson(
json.tryGetMap<String, dynamic>('pack', TryGet.optional) ?? {}), json.tryGetMap<String, dynamic>('pack') ?? {}),
images = json images = json.tryGetMap<String, dynamic>('images')?.catchMap(
.tryGetMap<String, dynamic>('images', TryGet.optional) (k, v) => MapEntry(k, ImagePackImageContent.fromJson(v))) ??
?.catchMap(
(k, v) => MapEntry(k, ImagePackImageContent.fromJson(v))) ??
// the "emoticons" key needs a small migration on the key, ":string:" --> "string" // the "emoticons" key needs a small migration on the key, ":string:" --> "string"
json json.tryGetMap<String, dynamic>('emoticons')?.catchMap((k, v) =>
.tryGetMap<String, dynamic>('emoticons', TryGet.optional) MapEntry(
?.catchMap((k, v) => MapEntry(
k.startsWith(':') && k.endsWith(':') k.startsWith(':') && k.endsWith(':')
? k.substring(1, k.length - 1) ? k.substring(1, k.length - 1)
: k, : k,
ImagePackImageContent.fromJson(v))) ?? ImagePackImageContent.fromJson(v))) ??
// the "short" key was still just a map from shortcode to mxc uri // the "short" key was still just a map from shortcode to mxc uri
json.tryGetMap<String, String>('short', TryGet.optional)?.catchMap( json.tryGetMap<String, String>('short')?.catchMap((k, v) =>
(k, v) => MapEntry( MapEntry(
k.startsWith(':') && k.endsWith(':') k.startsWith(':') && k.endsWith(':')
? k.substring(1, k.length - 1) ? k.substring(1, k.length - 1)
: k, : k,
@ -122,10 +119,9 @@ class ImagePackImageContent {
: _json = Map.fromEntries(json.entries : _json = Map.fromEntries(json.entries
.where((e) => !['url', 'body', 'info'].contains(e.key))), .where((e) => !['url', 'body', 'info'].contains(e.key))),
url = Uri.parse(json['url']), url = Uri.parse(json['url']),
body = json.tryGet('body', TryGet.optional), body = json.tryGet('body'),
info = json.tryGetMap<String, dynamic>('info', TryGet.optional), info = json.tryGetMap<String, dynamic>('info'),
usage = imagePackUsageFromJson( usage = imagePackUsageFromJson(json.tryGetList<String>('usage'));
json.tryGetList<String>('usage', TryGet.optional));
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return { return {
@ -134,8 +130,7 @@ class ImagePackImageContent {
if (body != null) 'body': body, if (body != null) 'body': body,
if (info != null) 'info': info, if (info != null) 'info': info,
if (usage != null) if (usage != null)
'usage': imagePackUsageToJson( 'usage': imagePackUsageToJson(usage, _json.tryGetList<String>('usage')),
usage, _json.tryGetList<String>('usage', TryGet.optional)),
}; };
} }
} }
@ -156,13 +151,11 @@ class ImagePackPackContent {
ImagePackPackContent.fromJson(Map<String, dynamic> json) ImagePackPackContent.fromJson(Map<String, dynamic> json)
: _json = Map.fromEntries(json.entries.where((e) => : _json = Map.fromEntries(json.entries.where((e) =>
!['display_name', 'avatar_url', 'attribution'].contains(e.key))), !['display_name', 'avatar_url', 'attribution'].contains(e.key))),
displayName = json.tryGet('display_name', TryGet.optional), displayName = json.tryGet('display_name'),
// we default to an invalid uri // we default to an invalid uri
avatarUrl = avatarUrl = Uri.tryParse(json.tryGet('avatar_url') ?? '.::'),
Uri.tryParse(json.tryGet('avatar_url', TryGet.optional) ?? '.::'), usage = imagePackUsageFromJson(json.tryGetList<String>('usage')),
usage = imagePackUsageFromJson( attribution = json.tryGet('attribution');
json.tryGetList<String>('usage', TryGet.optional)),
attribution = json.tryGet('attribution', TryGet.optional);
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return { return {
@ -170,8 +163,7 @@ class ImagePackPackContent {
if (displayName != null) 'display_name': displayName, if (displayName != null) 'display_name': displayName,
if (avatarUrl != null) 'avatar_url': avatarUrl.toString(), if (avatarUrl != null) 'avatar_url': avatarUrl.toString(),
if (usage != null) if (usage != null)
'usage': imagePackUsageToJson( 'usage': imagePackUsageToJson(usage, _json.tryGetList<String>('usage')),
usage, _json.tryGetList<String>('usage', TryGet.optional)),
if (attribution != null) 'attribution': attribution, if (attribution != null) 'attribution': attribution,
}; };
} }

View File

@ -42,12 +42,12 @@ class OlmPlaintextPayload {
factory OlmPlaintextPayload.fromJson(Map<String, dynamic> json) => factory OlmPlaintextPayload.fromJson(Map<String, dynamic> json) =>
OlmPlaintextPayload( OlmPlaintextPayload(
sender: json.tryGet('sender'), sender: json.tryGet('sender', TryGet.required),
type: json.tryGet('type'), type: json.tryGet('type', TryGet.required),
content: json.tryGetMap('content'), content: json.tryGetMap('content', TryGet.required),
recipient: json.tryGet('recipient'), recipient: json.tryGet('recipient', TryGet.required),
recipientKeys: json.tryGetMap('recipient_keys'), recipientKeys: json.tryGetMap('recipient_keys', TryGet.required),
keys: json.tryGetMap('keys'), keys: json.tryGetMap('keys', TryGet.required),
); );
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -41,10 +41,10 @@ class RoomEncryptedContent {
Map<String, CiphertextInfo>? ciphertextOlm; Map<String, CiphertextInfo>? ciphertextOlm;
RoomEncryptedContent.fromJson(Map<String, dynamic> json) RoomEncryptedContent.fromJson(Map<String, dynamic> json)
: algorithm = json.tryGet('algorithm') ?? '', : algorithm = json.tryGet('algorithm', TryGet.required) ?? '',
senderKey = json.tryGet('sender_key') ?? '', senderKey = json.tryGet('sender_key', TryGet.required) ?? '',
deviceId = json.tryGet('device_id', TryGet.optional), deviceId = json.tryGet('device_id'),
sessionId = json.tryGet('session_id', TryGet.optional), sessionId = json.tryGet('session_id'),
ciphertextMegolm = json.tryGet('ciphertext', TryGet.silent), ciphertextMegolm = json.tryGet('ciphertext', TryGet.silent),
// filter out invalid/incomplete CiphertextInfos // filter out invalid/incomplete CiphertextInfos
ciphertextOlm = json ciphertextOlm = json

View File

@ -35,10 +35,9 @@ class RoomEncryptionContent {
int? rotationPeriodMsgs; int? rotationPeriodMsgs;
RoomEncryptionContent.fromJson(Map<String, dynamic> json) RoomEncryptionContent.fromJson(Map<String, dynamic> json)
: algorithm = json.tryGet('algorithm') ?? '', : algorithm = json.tryGet('algorithm', TryGet.required) ?? '',
rotationPeriodMs = json.tryGet('rotation_period_ms', TryGet.optional), rotationPeriodMs = json.tryGet('rotation_period_ms'),
rotationPeriodMsgs = rotationPeriodMsgs = json.tryGet('rotation_period_msgs');
json.tryGet('rotation_period_msgs', TryGet.optional);
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

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

View File

@ -37,10 +37,11 @@ class RoomKeyRequestContent {
RoomKeyRequestContent.fromJson(Map<String, dynamic> json) RoomKeyRequestContent.fromJson(Map<String, dynamic> json)
: body = ((x) => x != null ? RequestedKeyInfo.fromJson(x) : null)( : body = ((x) => x != null ? RequestedKeyInfo.fromJson(x) : null)(
json.tryGet('body', TryGet.optional)), json.tryGet('body')),
action = json.tryGet('action') ?? '', action = json.tryGet('action', TryGet.required) ?? '',
requestingDeviceId = json.tryGet('requesting_device_id') ?? '', requestingDeviceId =
requestId = json.tryGet('request_id') ?? ''; json.tryGet('requesting_device_id', TryGet.required) ?? '',
requestId = json.tryGet('request_id', TryGet.required) ?? '';
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};
@ -65,10 +66,10 @@ class RequestedKeyInfo {
required this.senderKey}); required this.senderKey});
RequestedKeyInfo.fromJson(Map<String, dynamic> json) RequestedKeyInfo.fromJson(Map<String, dynamic> json)
: algorithm = json.tryGet('algorithm') ?? '', : algorithm = json.tryGet('algorithm', TryGet.required) ?? '',
roomId = json.tryGet('room_id') ?? '', roomId = json.tryGet('room_id', TryGet.required) ?? '',
sessionId = json.tryGet('session_id') ?? '', sessionId = json.tryGet('session_id', TryGet.required) ?? '',
senderKey = json.tryGet('sender_key') ?? ''; senderKey = json.tryGet('sender_key', TryGet.required) ?? '';
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -36,7 +36,7 @@ class SecretStorageDefaultKeyContent {
SecretStorageDefaultKeyContent({required this.key}); SecretStorageDefaultKeyContent({required this.key});
SecretStorageDefaultKeyContent.fromJson(Map<String, dynamic> json) SecretStorageDefaultKeyContent.fromJson(Map<String, dynamic> json)
: key = json.tryGet('key'); : key = json.tryGet('key', TryGet.required);
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

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

View File

@ -34,8 +34,9 @@ class TombstoneContent {
String replacementRoom; String replacementRoom;
TombstoneContent.fromJson(Map<String, dynamic> json) TombstoneContent.fromJson(Map<String, dynamic> json)
: body = json.tryGet('body') ?? '', : body = json.tryGet('body', TryGet.required) ?? '',
replacementRoom = json.tryGet('replacement_room') ?? ''; replacementRoom =
json.tryGet('replacement_room', TryGet.required) ?? '';
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};