GroupChannelListRequest constructor

GroupChannelListRequest({
  1. required GroupChannelListOrder order,
  2. String? token,
  3. int limit = 30,
  4. List<String>? channelUrls,
  5. String? searchQuery,
  6. required GroupChannelListQueryType queryType,
  7. List<GroupChannelListQuerySearchField> searchFields = const [],
  8. List<ChannelQueryIncludeOption> options = const [],
  9. required GroupChannelFilter filter,
  10. String? userId,
})

Implementation

GroupChannelListRequest({
  required GroupChannelListOrder order,
  String? token,
  int limit = 30,
  List<String>? channelUrls,
  String? searchQuery,
  required GroupChannelListQueryType queryType,
  List<GroupChannelListQuerySearchField> searchFields = const [],
  List<ChannelQueryIncludeOption> options = const [],
  required GroupChannelFilter filter,
  String? userId,
}) : super(userId: userId) {
  url = 'users/${userId ?? state.userId}/my_group_channels';

  final searchFieldStrings = stringFromSearchFields(searchFields);
  queryParams = {
    if (userId != null) 'user_id': userId,
    if (token != null) 'token': token,
    'limit': limit,
    if (channelUrls != null) 'channel_urls': channelUrls,
    'order': groupChannelListOrderEnumMap[order],
    if (searchFieldStrings.isNotEmpty) 'search_field': searchFieldStrings,
    if (searchFieldStrings.isNotEmpty) 'search_query': searchQuery,
    'distinct_mode': 'all',
    'show_member': true,
  };

  queryParams.addAll(options.toJson());
  queryParams.addAll(filter.toJson());

  if (filter.membersIncludeIn != null &&
      filter.membersIncludeIn!.isNotEmpty) {
    queryParams['members_include_in'] = filter.membersIncludeIn;
    queryParams['query_type'] = queryType.asString();
  }

  if (order == GroupChannelListOrder.channelMetaDataValueAlphabetical &&
      filter.metadataOrderKey != null) {
    queryParams['metadata_order_key'] = filter.metadataOrderKey;
  }

  queryParams.removeWhere((key, value) => value == null);
}