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
| Parameter | Type | Default | Description |
|---|---|---|---|
channelIdentifier | ChannelIdentifier | Required | Community channel identifier. Set subChannelId to the target subchannel. |
isAscending | bool | false | Sort order. false loads newer-to-older messages, true loads older-to-newer messages. |
policy | MessageOperationPolicy | local | Query source: local, remote, or localRemote. |
messageType | MessageType | unknown | Message type filter. unknown means all types. |
startTime | int | 0 | Start timestamp in milliseconds. 0 starts from the latest message when isAscending is false. |
pageSize | int | 20 | Messages per page. |
PageResult<Message>
| Property | Type | Description |
|---|---|---|
data | List<Message> | Messages returned in the current page. |
totalCount | int | Total 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
| Property | Type | Description |
|---|---|---|
matched | List<Message> | Messages that still exist on the remote server. |
notMatched | List<Message> | Messages that were not found on the remote server. |
note
checkRemoteMessages() is a community-channel API. Pass community messages only.