fromJson static method
Returns a new ChannelConfigWithInfo instance and imports its values from
value
if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static ChannelConfigWithInfo? 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 "ChannelConfigWithInfo[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "ChannelConfigWithInfo[$key]" has a null value in JSON.');
});
return true;
}());
return ChannelConfigWithInfo(
allowedFlagReasons: json[r'allowed_flag_reasons'] is Iterable
? (json[r'allowed_flag_reasons'] as Iterable).cast<String>().toList(growable: false)
: const [],
automod: ChannelConfigWithInfoAutomodEnum.fromJson(json[r'automod'])!,
automodBehavior: ChannelConfigWithInfoAutomodBehaviorEnum.fromJson(json[r'automod_behavior'])!,
automodThresholds: Thresholds.fromJson(json[r'automod_thresholds']),
blocklist: mapValueOfType<String>(json, r'blocklist'),
blocklistBehavior: ChannelConfigWithInfoBlocklistBehaviorEnum.fromJson(json[r'blocklist_behavior']),
blocklists: BlockListOptions.listFromJson(json[r'blocklists']),
commands: Command.listFromJson(json[r'commands']),
connectEvents: mapValueOfType<bool>(json, r'connect_events')!,
createdAt: mapDateTime(json, r'created_at', r'')!,
customEvents: mapValueOfType<bool>(json, r'custom_events')!,
grants: mapCastOfType<String, List<String>>(json, r'grants') ?? const {},
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;
}