diff --git a/pages/im/group/chat.nvue b/pages/im/group/chat.nvue index 74bac82..a54b351 100644 --- a/pages/im/group/chat.nvue +++ b/pages/im/group/chat.nvue @@ -16,7 +16,7 @@ - + @@ -59,7 +59,7 @@ this.getMessageList() uni.$on('onReceiveMessage', (msg) => { if (msg.targetId == this.targetId) { - this.getMessageList() + this.getNewMessage() } }) uni.$once('cleanGroupMessage', this.getMessageList) @@ -87,6 +87,18 @@ url: '/pages/im/friends/info?targetId=' + item.senderUserId }) } + }, + getNewMessage() { + im.getMessageList( + this.conversationType, + this.targetId, + new Date().getTime(), + 10, + false, + (messages) => { + this.messages = this.messages.concat(messages) + this.scrollBottom() + }) }, // 获取消息列表 getMessageList() { @@ -94,7 +106,7 @@ this.conversationType, this.targetId, new Date().getTime(), - 20, + 100, true, (messages) => { this.messages = messages.reverse() diff --git a/pages/im/private/chat.nvue b/pages/im/private/chat.nvue index 57e407c..c1ec122 100644 --- a/pages/im/private/chat.nvue +++ b/pages/im/private/chat.nvue @@ -6,8 +6,9 @@ {{ customCN(item.sentTime) }} - - + + @@ -23,7 +24,7 @@ - + @@ -70,30 +71,48 @@ // 监听消息已读状态 uni.$on('onReadReceiptReceived', (data) => { if (data.targetId == this.targetId) { - this.getMessageList() + this.messages = this.messages.map((item) => { + if (item.messageDirection == 1 && item.sentStatus == 30 && item.receivedTime < + data.messageTime + 1000) { + item.sentStatus = 50 + } + return item + }) } }) // 监听收到新消息,判断是否是当前会话,更新会话内容 uni.$on('onReceiveMessage', (msg) => { if (msg.targetId == this.targetId) { - this.getMessageList() + this.getNewMessage() } }) }, - onBackPress() { - uni.$off('onReceiveMessage') + onUnload() { + uni.$off('onReadReceiptReceived') }, methods: { customCN(val) { return timeCustomCN(val) }, + getNewMessage() { + im.getMessageList( + this.conversationType, + this.targetId, + new Date().getTime(), + 10, + false, + (messages) => { + this.messages = this.messages.concat(messages) + this.scrollBottom() + }) + }, // 获取消息列表 getMessageList() { im.getMessageList( this.conversationType, this.targetId, new Date().getTime(), - 10, + 100, true, (messages) => { this.messages = messages.reverse() @@ -110,7 +129,7 @@ // 滚动到底部 scrollBottom(type) { // 清理当前会话,未读消息数量 - RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime() + 1100) + RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime()) // 发送消息已读状态给对方 RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime()) // 更新badge提醒数量 diff --git a/utils/im/message.js b/utils/im/message.js index 15dc586..53e51d1 100644 --- a/utils/im/message.js +++ b/utils/im/message.js @@ -22,7 +22,7 @@ const getMessageList = (conversationType, targetId, timeStamp, count, isForward, conversationType, targetId, objectNames, - timeStamp + 1000, + timeStamp, count, isForward, ({