ImagePackContent.fromJson constructor
Implementation
ImagePackContent.fromJson(Map<String, Object?> json)
: _json = Map.fromEntries(
json.entries.where(
(e) => !['images', 'pack', 'emoticons', 'short'].contains(e.key),
),
),
pack = ImagePackPackContent.fromJson(
json.tryGetMap<String, Object?>('pack') ?? {},
),
images = json.tryGetMap<String, Object?>('images')?.catchMap(
(k, v) => MapEntry(
k,
ImagePackImageContent.fromJson(
v as Map<String, Object?>,
),
),
) ??
// the "emoticons" key needs a small migration on the key, ":string:" --> "string"
json.tryGetMap<String, Object?>('emoticons')?.catchMap(
(k, v) => MapEntry(
k.startsWith(':') && k.endsWith(':')
? k.substring(1, k.length - 1)
: k,
ImagePackImageContent.fromJson(
v as Map<String, Object?>,
),
),
) ??
// the "short" key was still just a map from shortcode to mxc uri
json.tryGetMap<String, String>('short')?.catchMap(
(k, v) => MapEntry(
k.startsWith(':') && k.endsWith(':')
? k.substring(1, k.length - 1)
: k,
ImagePackImageContent(url: Uri.parse(v)),
),
) ??
{};