fetchHistoryMessages method Null safety
- {required String conversationId,
- EMConversationType type = EMConversationType.Chat,
- int pageSize = 20,
- String startMsgId = ''}
Gets historical messages of the conversation from the server with pagination.
Param conversationId
The conversation ID.
Param type
The conversation type. See {@link EMConversationType}.
Param pageSize
The number of messages per page.
Param startMsgId
The ID of the message from which you start to get the historical messages. If null
is passed, the SDK gets messages in reverse chronological order.
Return The obtained messages and the cursor for the next fetch action.
Throws A description of the exception. See {@link EMError}.
Implementation
Future<EMCursorResult<EMMessage>> fetchHistoryMessages({
required String conversationId,
EMConversationType type = EMConversationType.Chat,
int pageSize = 20,
String startMsgId = '',
}) async {
Map req = Map();
req['con_id'] = conversationId;
req['type'] = conversationTypeToInt(type);
req['pageSize'] = pageSize;
req['startMsgId'] = startMsgId;
Map result = await EMMethodChannel.ChatManager.invokeMethod(
ChatMethodKeys.fetchHistoryMessages, req);
try {
EMError.hasErrorFromResult(result);
return EMCursorResult<EMMessage>.fromJson(
result[ChatMethodKeys.fetchHistoryMessages],
dataItemCallback: (value) {
return EMMessage.fromJson(value);
});
} on EMError catch (e) {
throw e;
}
}