getChannelStates method
Future<List<ChannelState> >
getChannelStates({
- Filter? filter,
- List<
SortOption< ? channelStateSort,ChannelState> > - PaginationParams? paginationParams,
Get all the stored ChannelState
s
Optionally, pass filter
, sort
, paginationParams
for filtering out states.
Implementation
@override
Future<List<ChannelState>> getChannelStates({
Filter? filter,
List<SortOption<ChannelState>>? channelStateSort,
PaginationParams? paginationParams,
}) async {
assert(_debugIsConnected, '');
assert(() {
if (channelStateSort?.any((it) => it.comparator == null) ?? false) {
throw ArgumentError(
'SortOption requires a comparator in order to sort',
);
}
return true;
}(), '');
_logger.info('getChannelStates');
final channels = await db!.channelQueryDao.getChannels(filter: filter);
final channelStates = await Future.wait(
channels.map((e) => getChannelStateByCid(e.cid)),
);
// Sort the channel states
var comparator = _defaultChannelStateComparator;
if (channelStateSort != null && channelStateSort.isNotEmpty) {
comparator = _combineComparators(
channelStateSort.map((it) => it.comparator).withNullifyer,
);
}
channelStates.sort(comparator);
final offset = paginationParams?.offset;
if (offset != null && offset > 0 && channelStates.isNotEmpty) {
channelStates.removeRange(0, offset);
}
if (paginationParams?.limit != null) {
return channelStates.take(paginationParams!.limit).toList();
}
return channelStates;
}