同一用户所有已登录设备都可以获取该用户在所有设备上的历史消息;
用户可从服务器获取全部历史消息,也可以根据本地数据库存储的消息有选择的获取服务器历史消息;
消息漫游支持以会话为单位获取历史消息;
漫游消息的存储不限制条数和消息类型,时间限制分为3个月和6个月两种,客户可根据自身需求进行选择;
Android
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();
}
iOS
/**
* 从服务器获取指定会话的历史消息
*
* @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;