调整新信息的获取模式,以前是刷新整体列表,更改为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

@@ -16,7 +16,7 @@
</cell> </cell>
<cell class="cell-footer" ref="chatBottom"></cell> <cell class="cell-footer" ref="chatBottom"></cell>
</list> </list>
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getMessageList()" /> <sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
</view> </view>
</template> </template>
@@ -59,7 +59,7 @@
this.getMessageList() this.getMessageList()
uni.$on('onReceiveMessage', (msg) => { uni.$on('onReceiveMessage', (msg) => {
if (msg.targetId == this.targetId) { if (msg.targetId == this.targetId) {
this.getMessageList() this.getNewMessage()
} }
}) })
uni.$once('cleanGroupMessage', this.getMessageList) uni.$once('cleanGroupMessage', this.getMessageList)
@@ -88,13 +88,25 @@
}) })
} }
}, },
getNewMessage() {
im.getMessageList(
this.conversationType,
this.targetId,
new Date().getTime(),
10,
false,
(messages) => {
this.messages = this.messages.concat(messages)
this.scrollBottom()
})
},
// 获取消息列表 // 获取消息列表
getMessageList() { getMessageList() {
im.getMessageList( im.getMessageList(
this.conversationType, this.conversationType,
this.targetId, this.targetId,
new Date().getTime(), new Date().getTime(),
20, 100,
true, true,
(messages) => { (messages) => {
this.messages = messages.reverse() this.messages = messages.reverse()

View File

@@ -7,7 +7,8 @@
<text class="text">{{ customCN(item.sentTime) }}</text> <text class="text">{{ customCN(item.sentTime) }}</text>
</view> </view>
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'"> <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" /> <u-avatar class="avatar" size="36" shape="square" @click="showUser(targetId, item.messageDirection)"
:src="userInfo.portraitUrl" />
<view class="msg"> <view class="msg">
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1" <show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
:msg="item.content" /> :msg="item.content" />
@@ -23,7 +24,7 @@
</cell> </cell>
<cell class="cell-footer" ref="chatBottom"></cell> <cell class="cell-footer" ref="chatBottom"></cell>
</list> </list>
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getMessageList()" /> <sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
</view> </view>
</template> </template>
@@ -70,30 +71,48 @@
// 监听消息已读状态 // 监听消息已读状态
uni.$on('onReadReceiptReceived', (data) => { uni.$on('onReadReceiptReceived', (data) => {
if (data.targetId == this.targetId) { 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) => { uni.$on('onReceiveMessage', (msg) => {
if (msg.targetId == this.targetId) { if (msg.targetId == this.targetId) {
this.getMessageList() this.getNewMessage()
} }
}) })
}, },
onBackPress() { onUnload() {
uni.$off('onReceiveMessage') uni.$off('onReadReceiptReceived')
}, },
methods: { methods: {
customCN(val) { customCN(val) {
return timeCustomCN(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() { getMessageList() {
im.getMessageList( im.getMessageList(
this.conversationType, this.conversationType,
this.targetId, this.targetId,
new Date().getTime(), new Date().getTime(),
10, 100,
true, true,
(messages) => { (messages) => {
this.messages = messages.reverse() this.messages = messages.reverse()
@@ -110,7 +129,7 @@
// 滚动到底部 // 滚动到底部
scrollBottom(type) { 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()) RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime())
// 更新badge提醒数量 // 更新badge提醒数量

View File

@@ -22,7 +22,7 @@ const getMessageList = (conversationType, targetId, timeStamp, count, isForward,
conversationType, conversationType,
targetId, targetId,
objectNames, objectNames,
timeStamp + 1000, timeStamp,
count, count,
isForward, isForward,
({ ({