From 53e800738bd22d25e40a2c79afb644ded41cdec7 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 15 Feb 2022 11:04:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=96=B0=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=9A=84=E8=8E=B7=E5=8F=96=E6=A8=A1=E5=BC=8F=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E5=89=8D=E6=98=AF=E5=88=B7=E6=96=B0=E6=95=B4=E4=BD=93=E5=88=97?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E6=9B=B4=E6=94=B9=E4=B8=BAconcat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/im/group/chat.nvue | 18 +++++++++++++++--- pages/im/private/chat.nvue | 37 ++++++++++++++++++++++++++++--------- utils/im/message.js | 2 +- 3 files changed, 44 insertions(+), 13 deletions(-) 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, ({