fromJsonStorage static method

Metadata fromJsonStorage(
  1. Map<String, Object?> json
)

Implementation

static Metadata fromJsonStorage(Map<String, Object?> json) {
  // Parse tags from storage
  List<List<String>>? parsedTags;
  if (json['tags'] != null) {
    parsedTags = (json['tags'] as List)
        .map((tag) => (tag as List).map((e) => e.toString()).toList())
        .toList();
  }

  // Create a mutable copy of content if it exists
  Map<String, dynamic>? contentCopy;
  if (json['content'] != null) {
    contentCopy =
        Map<String, dynamic>.from(json['content'] as Map<String, dynamic>);
  }

  final metadata = Metadata(
    pubKey: json['pubKey'] as String? ?? '',
    name: json['name'] as String?,
    displayName: json['displayName'] as String?,
    picture: json['picture'] as String?,
    banner: json['banner'] as String?,
    website: json['website'] as String?,
    about: json['about'] as String?,
    nip05: json['nip05'] as String?,
    lud16: json['lud16'] as String?,
    lud06: json['lud06'] as String?,
    updatedAt: json['updatedAt'] as int?,
    refreshedTimestamp: json['refreshedTimestamp'] as int?,
    tags: parsedTags,
    content: contentCopy,
  );

  if (json['sources'] != null) {
    metadata.sources = List<String>.from(json['sources'] as List);
  }

  return metadata;
}