Line data Source code
1 20 : enum _EnrichmentType { 2 : ownChildren, 3 : ownReactions, 4 : reactionCounts, 5 : reactionKinds, 6 : recentReactions, 7 : recentReactionsLimit, 8 : } 9 : 10 : extension _EnrichmentTypeX on _EnrichmentType { 11 6 : String get type => { 12 : _EnrichmentType.ownChildren: 'with_own_children', 13 : _EnrichmentType.ownReactions: 'with_own_reactions', 14 : _EnrichmentType.reactionCounts: 'with_reaction_counts', 15 : _EnrichmentType.reactionKinds: 'reaction_kinds_filter', 16 : _EnrichmentType.recentReactions: 'with_recent_reactions', 17 : _EnrichmentType.recentReactionsLimit: 'recent_reactions_limit', 18 3 : }[this]!; 19 : } 20 : 21 : class EnrichmentFlags { 22 : String? _userId; 23 : final Map<_EnrichmentType, Object> _flags = {}; 24 : 25 4 : Map<String, Object?> get params { 26 17 : final params = _flags.map((key, value) => MapEntry(key.type, value)); 27 6 : if (_userId != null) params['user_id'] = _userId!; 28 : return params; 29 : } 30 : 31 1 : EnrichmentFlags withOwnChildren() { 32 2 : _flags[_EnrichmentType.ownChildren] = true; 33 : return this; 34 : } 35 : 36 1 : EnrichmentFlags withOwnReactions() { 37 2 : _flags[_EnrichmentType.ownReactions] = true; 38 : return this; 39 : } 40 : 41 1 : EnrichmentFlags withUserReactions(String userId) { 42 2 : _flags[_EnrichmentType.ownReactions] = true; 43 1 : _userId = userId; 44 : return this; 45 : } 46 : 47 4 : EnrichmentFlags withRecentReactions([int? limit]) { 48 : if (limit == null) { 49 6 : _flags[_EnrichmentType.recentReactions] = true; 50 : } else { 51 2 : _flags[_EnrichmentType.recentReactionsLimit] = limit; 52 : } 53 : return this; 54 : } 55 : 56 1 : EnrichmentFlags reactionKindFilter(Iterable<String> kinds) { 57 3 : _flags[_EnrichmentType.reactionKinds] = kinds.join(','); 58 : return this; 59 : } 60 : 61 4 : EnrichmentFlags withReactionCounts() { 62 8 : _flags[_EnrichmentType.reactionCounts] = true; 63 : return this; 64 : } 65 : 66 1 : EnrichmentFlags withUserChildren(String userId) { 67 2 : _flags[_EnrichmentType.ownChildren] = true; 68 1 : _userId = userId; 69 : return this; 70 : } 71 : }