getChannelStates method
Future<List<ChannelState> >
getChannelStates({
- Filter? filter,
- SortOrder<
ChannelState> ? channelStateSort, - PaginationParams? paginationParams,
Get all the stored ChannelStates
Optionally, pass filter, sort, paginationParams
for filtering out states.
Implementation
@override
Future<List<ChannelState>> getChannelStates({
Filter? filter,
SortOrder<ChannelState>? channelStateSort,
PaginationParams? paginationParams,
}) async {
assert(_debugIsConnected, '');
_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
if (channelStateSort != null && channelStateSort.isNotEmpty) {
channelStates.sort(channelStateSort.compare);
}
// Apply offset
if (paginationParams?.offset case final paginationOffset?) {
final clampedOffset = paginationOffset.clamp(0, channelStates.length);
channelStates.removeRange(0, clampedOffset);
}
// Apply limit
if (paginationParams?.limit case final paginationLimit?) {
return channelStates.take(paginationLimit).toList();
}
return channelStates;
}