query method
Future<ChannelState>
query({
- bool state = true,
- bool watch = false,
- bool presence = false,
- PaginationParams? messagesPagination,
- PaginationParams? membersPagination,
- PaginationParams? watchersPagination,
- bool preferOffline = false,
Query the API, get messages, members or other channel fields.
Set preferOffline
to true to avoid the API call if the data is already
in the offline storage.
Implementation
Future<ChannelState> query({
bool state = true,
bool watch = false,
bool presence = false,
PaginationParams? messagesPagination,
PaginationParams? membersPagination,
PaginationParams? watchersPagination,
bool preferOffline = false,
}) async {
if (preferOffline && cid != null) {
final updatedState = await _client.chatPersistenceClient
?.getChannelStateByCid(cid!, messagePagination: messagesPagination);
if (updatedState != null &&
updatedState.messages != null &&
updatedState.messages!.isNotEmpty) {
if (this.state == null) {
_initState(updatedState);
} else {
this.state?.updateChannelState(updatedState);
}
return updatedState;
}
}
try {
final updatedState = await _client.queryChannel(
type,
channelId: id,
channelData: _extraData,
state: state,
watch: watch,
presence: presence,
messagesPagination: messagesPagination,
membersPagination: membersPagination,
watchersPagination: watchersPagination,
);
if (_id == null) {
_id = updatedState.channel!.id;
_cid = updatedState.channel!.cid;
}
this.state?.updateChannelState(updatedState);
return updatedState;
} catch (e) {
if (!_client.persistenceEnabled) {
rethrow;
}
return _client.chatPersistenceClient!.getChannelStateByCid(
cid!,
messagePagination: messagesPagination,
);
}
}