fetchHistoryMessagesByOption method
- String conversationId,
- ChatConversationType type, {
- FetchMessageOptions? options,
- String? cursor,
- int pageSize = 50,
~english Gets historical messages of a conversation from the server according to FetchMessageOptions.
Param conversationId
The conversation ID, which is the user ID of the peer user for one-to-one chat, but the group ID for group chat.
Param type
The conversation type. You can set this parameter only to ChatConversationType.Chat or ChatConversationType.GroupChat.
Param options
The parameter configuration class for pulling historical messages from the server. See FetchMessageOptions.
Param cursor
The cursor position from which to start querying data.
Param pageSize
The number of messages that you expect to get on each page. The value range is 1,50
.
~end
~chinese 根据 FetchMessageOptions 从服务器分页获取指定会话的历史消息。
Param conversationId
会话 ID。
Param type
会话类型,只支持 ChatConversationType.Chat 和群组 ChatConversationType.GroupChat 。
Param options
查询历史消息的参数配置接口,详见 FetchMessageOptions。
Param cursor
查询的起始游标位置。
Param pageSize
每页期望获取的消息条数。取值范围为 1,50
。
~end
Implementation
Future<ChatCursorResult<ChatMessage>> fetchHistoryMessagesByOption(
String conversationId,
ChatConversationType type, {
FetchMessageOptions? options,
String? cursor,
int pageSize = 50,
}) async {
Map req = Map();
req.putIfNotNull('convId', conversationId);
req.putIfNotNull('type', conversationTypeToInt(type));
req.putIfNotNull('pageSize', pageSize);
req.putIfNotNull('cursor', cursor);
req.putIfNotNull('options', options?.toJson());
Map result = await ChatChannel.invokeMethod(
ChatMethodKeys.fetchHistoryMessagesByOptions, req);
try {
ChatError.hasErrorFromResult(result);
return ChatCursorResult<ChatMessage>.fromJson(
result[ChatMethodKeys.fetchHistoryMessagesByOptions],
dataItemCallback: (value) {
return ChatMessage.fromJson(value);
});
} on ChatError catch (e) {
throw e;
}
}