relaysFromContent static method

Map<String, ReadWriteMarker> relaysFromContent(
  1. Nip01Event event
)

Implementation

static Map<String, ReadWriteMarker> relaysFromContent(Nip01Event event) {
  Map<String, ReadWriteMarker> map = {};
  if (Helpers.isNotBlank(event.content)) {
    try {
      Map<String, dynamic> json = jsonDecode(event.content);
      if (json.entries.isNotEmpty) {
        for (var entry in json.entries) {
          try {
            bool read = entry.value["read"] ?? false;
            bool write = entry.value["write"] ?? false;
            if (read || write) {
              map[entry.key] = ReadWriteMarker.from(read: read, write: write);
            }
          } catch (e) {
            try {
              Map<String, dynamic> decodedValue = jsonDecode(entry.value);
              bool read = decodedValue["read"] ?? false;
              bool write = decodedValue["write"] ?? false;
              if (read || write) {
                map[entry.key] =
                    ReadWriteMarker.from(read: read, write: write);
              }
              continue;
            } catch (e) {
              Logger.log.d(
                  "Could not parse relay ${entry.key} , entry : ${entry.value}");
            }
            Logger.log.d(
                "Could not parse relay ${entry.key} , content : ${event.content}");
          }
        }
      }
    } catch (e) {
      // invalid json in content, ignore
    }
  }
  return map;
}