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;
ForwardedRoomKeyContent.fromJson(Map<String, dynamic> json)
: senderKey = json.tryGet('sender_key') ?? '',
: senderKey = json.tryGet('sender_key', TryGet.required) ?? '',
senderClaimedEd25519Key =
json.tryGet('sender_claimed_ed25519_key') ?? '',
forwardingCurve25519KeyChain =
json.tryGetList('forwarding_curve25519_key_chain') ?? [],
json.tryGet('sender_claimed_ed25519_key', TryGet.required) ?? '',
forwardingCurve25519KeyChain = json.tryGetList(
'forwarding_curve25519_key_chain', TryGet.required) ??
[],
super.fromJson(json);
@override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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