ContactList.fromJson constructor

ContactList.fromJson(
  1. List tags
)

Creates a ContactList populated from tags which is a JSON array of event tags from a contact_list event as defined by NIP-02.

Example:

final contacts = ContactList.fromJson([
  ["p", "91cf9..4e5ca", "wss://alicerelay.com/", "alice"],
  ["p", "14aeb..8dad4", "wss://bobrelay.com/nostr", "bob"],
  ["p", "612ae..e610f", "ws://carolrelay.com/ws", "carol"]
]);

Implementation

factory ContactList.fromJson(List<dynamic> tags) {
  // TODO: tags data validation
  Map<String, Contact> contacts = {};
  for (List<String> tag in tags) {
    final contact = Contact(publicKey: tag[1], url: tag[2], petname: tag[3]);
    contacts[contact.publicKey] = contact;
  }
  return ContactList._(contacts);
}