queryChannels method
Stream<List<Channel> >
queryChannels({
- Filter? filter,
- List<
SortOption< ? channelStateSort,ChannelState> > - bool state = true,
- bool watch = true,
- bool presence = false,
- int? memberLimit,
- int? messageLimit,
- PaginationParams paginationParams = const PaginationParams(),
- bool waitForConnect = true,
Requests channels with a given query.
Implementation
Stream<List<Channel>> queryChannels({
Filter? filter,
List<SortOption<ChannelState>>? channelStateSort,
bool state = true,
bool watch = true,
bool presence = false,
int? memberLimit,
int? messageLimit,
PaginationParams paginationParams = const PaginationParams(),
bool waitForConnect = true,
}) async* {
if (!_connectionIdManager.hasConnectionId) {
// ignore: parameter_assignments
watch = false;
}
final hash = generateHash([
filter,
channelStateSort,
state,
watch,
presence,
memberLimit,
messageLimit,
paginationParams,
]);
if (_queryChannelsStreams.containsKey(hash)) {
yield await _queryChannelsStreams[hash]!;
} else {
final channels = await queryChannelsOffline(
filter: filter,
channelStateSort: channelStateSort,
paginationParams: paginationParams,
);
if (channels.isNotEmpty) yield channels;
try {
final newQueryChannelsFuture = queryChannelsOnline(
filter: filter,
sort: channelStateSort,
state: state,
watch: watch,
presence: presence,
memberLimit: memberLimit,
messageLimit: messageLimit,
paginationParams: paginationParams,
waitForConnect: waitForConnect,
).whenComplete(() {
_queryChannelsStreams.remove(hash);
});
_queryChannelsStreams[hash] = newQueryChannelsFuture;
yield await newQueryChannelsFuture;
} catch (_) {
if (channels.isEmpty) rethrow;
}
}
}