Skip to main content

Get message history

Retrieve message history from a community subchannel using BaseChannel.createMessagesQuery().

Get local or remote messages

Dart
final query = BaseChannel.createMessagesQuery(MessagesQueryParams(
channel: ChannelIdentifier(
channelType: ChannelType.community,
channelId: '<community-id>',
subChannelId: '<subchannel-id>',
),
policy: MessageOperationPolicy.localRemote,
pageSize: 20,
));

await query.loadNextPage((result, error) {
if (error == null) {
print('Loaded ${result?.data.length} messages');
print('Total matched: ${result?.totalCount}');
}
});

MessagesQueryParams

ParameterTypeDefaultDescription
channelChannelIdentifierRequiredCommunity channel identifier. Set subChannelId to the target subchannel.
orderTimeOrderTimeOrder.beforeDirection for paging through history.
policyMessageOperationPolicylocalQuery source: local, remote, or localRemote.
messageTypeMessageTypeunknownMessage type filter. unknown means all types.
pageSizeint20Messages per page.

PageResult<Message>

PropertyTypeDescription
dataList<Message>Messages returned in the current page.
totalCountintTotal number of messages matched by the query.