Authored by 李奇

历史消息优化

... ... @@ -71,7 +71,7 @@ const getMsgHistory = (encryptedUid, endTime) => {
params.endTime = endTime;
}
return api.post(urls.msgHistory, params);
return api.post(urls.msgHistory, params, {timeout: 5000});
};
module.exports = {
... ...
... ... @@ -11,6 +11,7 @@ var $ = require('yoho-jquery'),
uuid = require('uuid'),
emojiMap = require('./emoji-map'),
editArea = require('./edit-area'),
serviceApi = require('./service-api'),
broswer = require('./broswer'),
socketChat = require('./socket-chat'),
socketConf = require('./socket-config');
... ... @@ -781,6 +782,9 @@ function pageInit() {
* 获取历史聊天记录
*/
function fetchHistoryMsg() {
if(processInfo.loadingHistory) {
return;
}
processInfo.loadingHistory = true;
var msgList = [];
var data = {
... ... @@ -790,11 +794,9 @@ function pageInit() {
if (endTime) {
data.endTime = endTime;
}
$.ajax({
type: 'POST',
url: '/service/history',
data: data,
success: function(res) {
serviceApi.history(data)
.done(function(res) {
if (res && res.code === 200) {
if (processInfo.hasMore) {
msgList = res.data.records || [];
... ... @@ -802,8 +804,12 @@ function pageInit() {
}
$history.hide();
processInfo.scrollLoad = true;
} else {
processInfo.loadingHistory = false;
}
}
})
.fail(function() {
processInfo.loadingHistory = false;
});
}
... ...
/**
* 前端Ajax请求封装
* @author LQ <qi.li@yoho.cn>
* @date 2017/03/14
*/
var $ = require('yoho-jquery');
var reqUrls = {
history: '/service/history'
};
var _ajax = function(method, reqUrl, params) {
return $.ajax({
type: method || "GET",
url: reqUrl,
data: params
});
};
/**
* 历史消息
* @param params 参数对象
*/
exports.history = function(params) {
return _ajax("POST", reqUrls.history, params);
};
... ...