调整新信息的获取模式,以前是刷新整体列表,更改为concat

This commit is contained in:
2022-02-15 11:04:05 +08:00
parent a831b65a5f
commit 53e800738b
3 changed files with 44 additions and 13 deletions

View File

@@ -6,8 +6,9 @@
<view class="time">
<text class="text">{{ customCN(item.sentTime) }}</text>
</view>
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
<u-avatar class="avatar" size="36" shape="square" @click="showUser(targetId, item.messageDirection)" :src="userInfo.portraitUrl" />
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
<u-avatar class="avatar" size="36" shape="square" @click="showUser(targetId, item.messageDirection)"
:src="userInfo.portraitUrl" />
<view class="msg">
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
:msg="item.content" />
@@ -23,7 +24,7 @@
</cell>
<cell class="cell-footer" ref="chatBottom"></cell>
</list>
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getMessageList()" />
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
</view>
</template>
@@ -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提醒数量