fromJson static method

ChannelConfig? fromJson(
  1. dynamic value
)

Returns a new ChannelConfig instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static ChannelConfig? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "ChannelConfig[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "ChannelConfig[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return ChannelConfig(
      allowedFlagReasons: json[r'allowed_flag_reasons'] is Iterable
          ? (json[r'allowed_flag_reasons'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      automod: ChannelConfigAutomodEnum.fromJson(json[r'automod'])!,
      automodBehavior: ChannelConfigAutomodBehaviorEnum.fromJson(json[r'automod_behavior'])!,
      automodThresholds: Thresholds.fromJson(json[r'automod_thresholds']),
      blocklist: mapValueOfType<String>(json, r'blocklist'),
      blocklistBehavior: ChannelConfigBlocklistBehaviorEnum.fromJson(json[r'blocklist_behavior']),
      blocklists: BlockListOptions.listFromJson(json[r'blocklists']),
      commands: json[r'commands'] is Iterable
          ? (json[r'commands'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      connectEvents: mapValueOfType<bool>(json, r'connect_events')!,
      createdAt: mapDateTime(json, r'created_at', r'')!,
      customEvents: mapValueOfType<bool>(json, r'custom_events')!,
      markMessagesPending: mapValueOfType<bool>(json, r'mark_messages_pending')!,
      maxMessageLength: mapValueOfType<int>(json, r'max_message_length')!,
      mutes: mapValueOfType<bool>(json, r'mutes')!,
      name: mapValueOfType<String>(json, r'name')!,
      polls: mapValueOfType<bool>(json, r'polls')!,
      pushNotifications: mapValueOfType<bool>(json, r'push_notifications')!,
      quotes: mapValueOfType<bool>(json, r'quotes')!,
      reactions: mapValueOfType<bool>(json, r'reactions')!,
      readEvents: mapValueOfType<bool>(json, r'read_events')!,
      reminders: mapValueOfType<bool>(json, r'reminders')!,
      replies: mapValueOfType<bool>(json, r'replies')!,
      search: mapValueOfType<bool>(json, r'search')!,
      typingEvents: mapValueOfType<bool>(json, r'typing_events')!,
      updatedAt: mapDateTime(json, r'updated_at', r'')!,
      uploads: mapValueOfType<bool>(json, r'uploads')!,
      urlEnrichment: mapValueOfType<bool>(json, r'url_enrichment')!,
    );
  }
  return null;
}