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(
channelIdentifier: ChannelIdentifier(
channelType: ChannelType.community,
channelId: '<community-id>',
subChannelId: '<subchannel-id>',
),
isAscending: false,
policy: MessageOperationPolicy.localRemote,
startTime: 0,
pageSize: 20,
));

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

MessagesQueryParams

ParameterTypeDefaultDescription
channelIdentifierChannelIdentifierRequiredCommunity channel identifier. Set subChannelId to the target subchannel.
isAscendingboolfalseSort order. false loads newer-to-older messages, true loads older-to-newer messages.
policyMessageOperationPolicylocalQuery source: local, remote, or localRemote.
messageTypeMessageTypeunknownMessage type filter. unknown means all types.
startTimeint0Start timestamp in milliseconds. 0 starts from the latest message when isAscending is false.
pageSizeint20Messages per page.

PageResult<Message>

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

Check whether messages still exist on the remote server

Use CommunityChannel.checkRemoteMessages() to verify whether specific community messages still exist on the server.

Method

Dart
static Future<int> checkRemoteMessages(List<Message> messages, OperationHandler<CheckRemoteMessagesResult> handler)

Code example

Dart
await CommunityChannel.checkRemoteMessages(
messages,
(result, error) {
if (error == null) {
print('Matched: ${result?.matched.length}');
print('Not matched: ${result?.notMatched.length}');
}
},
);

CheckRemoteMessagesResult

PropertyTypeDescription
matchedList<Message>Messages that still exist on the remote server.
notMatchedList<Message>Messages that were not found on the remote server.
note

checkRemoteMessages() is a community-channel API. Pass community messages only.