getChannelMetadata static method

Channel getChannelMetadata(
  1. Event event
)

Implementation

static Channel getChannelMetadata(Event event) {
  try {
    Map content = jsonDecode(event.content);
    if (event.kind == 41) {
      // create channel
      Map<String, String> additional = Map.from(content);
      String? name = additional.remove("name");
      String? about = additional.remove("about");
      String? picture = additional.remove("picture");
      String? channelId;
      String? relay;
      for (var tag in event.tags) {
        if (tag[0] == "e") {
          channelId = tag[1];
          relay = tag[2];
        }
      }
      Channel result = Channel(
          channelId!, name!, about!, picture!, event.pubkey, additional);
      result.relay = relay;
      return result;
    } else {
      throw Exception("${event.kind} is not nip28 compatible");
    }
  } catch (e) {
    throw Exception(e.toString());
  }
}