From 8de4b32dbdc3bb5fe1419912b47f442770157b0c Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Wed, 27 Sep 2023 22:29:14 +0200 Subject: [PATCH] current stand --- lib/api/get-relays-meta.dart | 30 +++++++++++++------------ lib/utils/access-deeply-nested-key.dart | 8 ++++--- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/api/get-relays-meta.dart b/lib/api/get-relays-meta.dart index fe3f1f0..180255f 100644 --- a/lib/api/get-relays-meta.dart +++ b/lib/api/get-relays-meta.dart @@ -96,34 +96,36 @@ class RelayMeta { relay: relay, canRead: canRead, canWrite: canWrite, - name: adnk(content, "info.name") ?? relay, - contactInfo: adnk(content, "info.contact") ?? "", - description: adnk(content, "info.description") ?? "", - connectionLatencies: - List.from(adnk(content, "latency.$worldRegion.0") ?? []) - .where((value) => value != null) - .toList() - .cast(), + name: adnk(content, "info.name") ?? relay, + contactInfo: adnk(content, "info.contact") ?? "", + description: adnk(content, "info.description") ?? "", + connectionLatencies: List.from( + adnk(content, "latency.$worldRegion.0") ?? []) + .where((value) => value != null) + .toList() + .cast(), readLatencies: - List.from(adnk(content, "latency.$worldRegion.1") ?? []) + List.from(adnk(content, "latency.$worldRegion.1") ?? []) .where((value) => value != null) .toList() .cast(), writeLatencies: - List.from(adnk(content, "latency.$worldRegion.2") ?? []) + List.from(adnk(content, "latency.$worldRegion.2") ?? []) .where((value) => value != null) .toList() .cast(), maxContentLength: - adnk(content, "info.limitations.max_content_length") ?? + adnk(content, "info.limitations.max_content_length") ?? MIN_LENGTH, maxMessageLength: - adnk(content, "info.limitations.max_message_length") ?? + adnk(content, "info.limitations.max_message_length") ?? MIN_LENGTH, requiresPayment: - adnk(content, "info.limitations.payment_required") ?? false, + adnk(content, "info.limitations.payment_required") ?? + false, minPowDifficulty: - adnk(content, "info.limitations.min_pow_difficulty") ?? 0); + adnk(content, "info.limitations.min_pow_difficulty") ?? + 0); bool get isSuitable => canWrite && diff --git a/lib/utils/access-deeply-nested-key.dart b/lib/utils/access-deeply-nested-key.dart index 738b85e..51c73dd 100644 --- a/lib/utils/access-deeply-nested-key.dart +++ b/lib/utils/access-deeply-nested-key.dart @@ -2,9 +2,11 @@ T? accessDeeplyNestedKey(final Map obj, final String path) { dynamic result = obj; for (final subPath in path.split(".")) { - if (result is List - ? result[int.parse(subPath)] - : result.containsKey(subPath)) { + if (result is List) { + final index = int.tryParse(subPath)!; + + result = result[index]; + } else if (result.containsKey(subPath)) { result = result[subPath]; } else { return null;