try {
EMClient.getInstance().chatManager().fetchHistoryMessages(
toChatUsername, EaseCommonUtils.getConversationType(chatType), pagesize, "");
final List<EMMessage> msgs = conversation.getAllMessages();
int msgCount = msgs != null ? msgs.size() : 0;
if (msgCount < conversation.getAllMsgCount() && msgCount < pagesize) {
String msgId = null;
if (msgs != null && msgs.size() > 0) {
msgId = msgs.get(0).getMsgId();
}
conversation.loadMoreMsgFromDB(msgId, pagesize - msgCount);
}
messageList.refreshSelectLast();
} catch (HyphenateException e) {
e.printStackTrace();
}
/**
* 从服务器获取指定会话的历史消息
*
* @param aConversationId 要获取漫游消息的Conversation id
* @param aConversationType 要获取漫游消息的Conversation type
* @param aStartMessageId 参考起始消息的ID
* @param aPageSize 获取消息条数
* @param pError 错误信息
*
* @return 获取的消息结果
*/
- (EMCursorResult *)fetchHistoryMessagesFromServer:(NSString *)aConversationId
conversationType:(EMConversationType)aConversationType
startMessageId:(NSString *)aStartMessageId
pageSize:(int)aPageSize
error:(EMError **)pError;
/**
* 从服务器获取指定会话的历史消息
*
* 异步方法
*
* @param aConversationId 要获取漫游消息的Conversation id
* @param aConversationType 要获取漫游消息的Conversation type
* @param aStartMessageId 参考起始消息的ID
* @param aPageSize 获取消息条数
* @param aCompletionBlock 获取消息结束的callback
*/
- (void)asyncFetchHistoryMessagesFromServer:(NSString *)aConversationId
conversationType:(EMConversationType)aConversationType
startMessageId:(NSString *)aStartMessageId
pageSize:(int)aPageSize
complation:(void (^)(EMCursorResult *aResult, EMError *aError))aCompletionBlock;