Authored by 陈轩

im history time

{{#each .}}
<div class="msg-wrap {{style from}}" data-uuid={{uuid}}>
<img src="http:{{image avatar 80 80}}" alt="" class="head-icon">
<div class="chat-info clearfix">
... ... @@ -8,7 +7,6 @@
<i class="msg-status iconfont"></i>
</div>
</div>
{{/each}}
{{!--inline partails--}}
... ...
... ... @@ -53,6 +53,7 @@ let customerService = {
// 历史消息分页
let msgHistory = {
conversationId: '', // 会话id
endTime: null,
curCount: 0,
totalCount: null
... ... @@ -621,10 +622,6 @@ var chat = {
_drawMSG: function(viewData, cusAction = null) {
let chatWin = this.$chatWin[0];
if (!$.isArray(viewData)) {
viewData = [viewData];
}
// console.log(viewData);
let $html = $(this.messageT(viewData));
... ... @@ -690,22 +687,41 @@ var chat = {
let records = result.records || [];
records.reverse();
// records.reverse();
let $docFragment = $(document.createDocumentFragment());
records.forEach(chatMessage => {
records.forEach((chatMessage, index, arr) => {
let nextChat = records[index + 1];
let data = self.buildViewData(chatMessage); //eslint-disable-line
if (data) {
arr.push(data);
let conversationId = chatMessage.conversationId;
let timstamp = Math.ceil(chatMessage.sendTime / 1000); // 原来是微妙 转换成毫秒
let $html = self._drawMSG(data);
$docFragment.prepend($html);
if (index === 0 && !msgHistory.conversationId) {
msgHistory.conversationId = conversationId;
}
if (
nextChat &&
(nextChat.conversationId !== msgHistory.conversationId)
) {
$docFragment.prepend(time(timstamp).show());
msgHistory.conversationId = nextChat.conversationId;
}
}
});
self._drawMSG(arr, function($html) {
self.$historyLoader.after($html);
});
self.$historyLoader.after($docFragment);
if (records.length) {
msgHistory.endTime = records[0].sendTime;
msgHistory.endTime = records[records.length - 1].sendTime;
msgHistory.curCount += records.length;
}
... ...
... ... @@ -44,6 +44,10 @@ class Time {
timef = this._format(this.timestamp, 'yyyy.MM.dd hh:mm');
}
return this.render(timef);
}
render(timef) {
return `<div class="chat-time">
${timef}
</div>`;
... ...