fromEvent static method

Future<Nip51Set?> fromEvent(
  1. Nip01Event event,
  2. EventSigner? signer
)
override

Implementation

static Future<Nip51Set?> fromEvent(
    Nip01Event event, EventSigner? signer) async {
  String? name = event.getDtag();
  if (name == null || event.kind != Nip51List.RELAY_SET) {
    return null;
  }
  Nip51Set set = Nip51Set(
      pubKey: event.pubKey,
      name: name,
      createdAt: event.createdAt,
      elements: []);
  set.id = event.id;
  if (Helpers.isNotBlank(event.content) &&
      signer != null &&
      signer.canSign()) {
    try {
      var json = await signer.decrypt(event.content, signer.getPublicKey());
      List<dynamic> tags = jsonDecode(json ?? '');
      set.parseTags(tags, private: true);
      set.parseSetTags(tags);
    } catch (e) {
      set.name = "<invalid encrypted content>";
      Logger.log.d(e);
    }
  } else {
    set.parseTags(event.tags, private: false);
    set.parseSetTags(event.tags);
  }
  return set;
}