解决时间戳不一致的问题

This commit is contained in:
2022-02-16 12:00:42 +08:00
parent f9dfd6b08d
commit a88875ed55
2 changed files with 77 additions and 64 deletions

View File

@@ -3,7 +3,8 @@
<list class="body" :show-scrollbar="false">
<cell class="cell" v-for="(item, index) in messages" :key="index">
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
<u-avatar class="avatar" @click="toUser(item)" size="36" shape="square" :src="item.content.userInfo.portraitUrl" />
<u-avatar class="avatar" @click="toUser(item)" size="36" shape="square"
:src="item.content.userInfo.portraitUrl" />
<view class="msg">
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
:msg="item.content" :name="item.content.userInfo.name" />
@@ -43,13 +44,18 @@
data() {
return {
targetId: '',
conversationType: 3,
conversationType: RongIMLib.ConversationType.GROUP,
messages: [],
groupInfo: {
name: ''
}
}
},
computed: {
latestMessage() {
return this.messages[this.messages.length - 1]
}
},
onLoad(e) {
this.targetId = e.targetId
this.groupInfo = this.$store.getters.contactInfo(this.targetId)
@@ -64,10 +70,6 @@
})
uni.$once('cleanGroupMessage', this.getMessageList)
},
onBackPress() {
uni.$off('onReceiveMessage')
console.log('Off onReceiveMessage');
},
onNavigationBarButtonTap() {
uni.navigateTo({
url: '/pages/im/group/info?targetId=' + this.targetId
@@ -82,18 +84,18 @@
uni.navigateTo({
url: '/pages/im/friends/mine?targetId=' + item.senderUserId
})
} else{
uni.navigateTo({
url: '/pages/im/friends/info?targetId=' + item.senderUserId
})
} else {
uni.navigateTo({
url: '/pages/im/friends/info?targetId=' + item.senderUserId
})
}
},
getNewMessage() {
im.getMessageList(
this.conversationType,
this.targetId,
new Date().getTime(),
10,
this.latestMessage.sentTime,
1,
false,
(messages) => {
this.messages = this.messages.concat(messages)
@@ -105,7 +107,7 @@
im.getMessageList(
this.conversationType,
this.targetId,
new Date().getTime(),
0,
100,
true,
(messages) => {
@@ -115,12 +117,15 @@
},
// 滚动到底部
scrollBottom(type) {
// 清理当前会话,未读消息数量
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime() + 1100)
// 发送消息已读状态给对方
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime())
// 更新badge提醒数量
im.setNotifyBadge()
if (this.latestMessage) {
// 清理当前会话,未读消息数量
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage
.sentTime)
// // 发送消息已读状态给对方
// RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime)
// 更新badge提醒数量
im.setNotifyBadge()
}
setTimeout(() => {
let el = this.$refs.chatBottom

View File

@@ -42,6 +42,12 @@
const ChatList = uni.requireNativePlugin('dom')
export default {
components: {
sentMessageBar,
showVoice,
showImage,
showText
},
data() {
return {
targetId: '',
@@ -54,11 +60,10 @@
}
}
},
components: {
sentMessageBar,
showVoice,
showImage,
showText
computed: {
latestMessage() {
return this.messages[this.messages.length - 1]
}
},
onLoad(e) {
this.targetId = e.targetId
@@ -98,8 +103,8 @@
im.getMessageList(
this.conversationType,
this.targetId,
new Date().getTime(),
10,
this.latestMessage.sentTime,
1,
false,
(messages) => {
this.messages = this.messages.concat(messages)
@@ -111,7 +116,7 @@
im.getMessageList(
this.conversationType,
this.targetId,
new Date().getTime(),
0,
100,
true,
(messages) => {
@@ -128,12 +133,15 @@
},
// 滚动到底部
scrollBottom(type) {
// 清理当前会话,未读消息数量
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime())
// 发送消息已读状态给对方
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime())
// 更新badge提醒数量
im.setNotifyBadge()
if (this.latestMessage) {
// 清理当前会话,未读消息数量
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage
.sentTime)
// // 发送消息已读状态给对方
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime)
// 更新badge提醒数量
im.setNotifyBadge()
}
setTimeout(() => {
let el = this.$refs.chatBottom
ChatList.scrollToElement(el, {