import 'package:stream_chat/src/models/user.dart'; /// Used to avoid to serialize properties to json // ignore: prefer_void_to_null Null readonly(_) => null; /// Helper class for serialization to and from json class Serialization { /// Used to avoid to serialize properties to json static const Function readOnly = readonly; /// List of users to list of userIds static List userIds(List users) => users?.map((u) => u.id)?.toList(); /// Takes unknown json keys and puts them in the `extra_data` key static Map moveToExtraDataFromRoot( Map json, List topLevelFields, ) { if (json == null) return null; final jsonClone = Map.from(json); final extraDataMap = Map.from(json) ..removeWhere( (key, value) => topLevelFields.contains(key), ); final rootFields = jsonClone ..removeWhere((key, value) => extraDataMap.keys.contains(key)); return rootFields ..addAll({ 'extra_data': extraDataMap, }); } /// Takes values in `extra_data` key and puts them on the root level of /// the json map static Map moveFromExtraDataToRoot( Map json, List topLevelFields, ) { final jsonClone = Map.from(json); return jsonClone ..addAll({ if (json['extra_data'] != null) ...json['extra_data'], }) ..remove('extra_data'); } }