解决时间戳不一致的问题

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"> <list class="body" :show-scrollbar="false">
<cell class="cell" v-for="(item, index) in messages" :key="index"> <cell class="cell" v-for="(item, index) in messages" :key="index">
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'"> <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"> <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" :name="item.content.userInfo.name" /> :msg="item.content" :name="item.content.userInfo.name" />
@@ -43,12 +44,17 @@
data() { data() {
return { return {
targetId: '', targetId: '',
conversationType: 3, conversationType: RongIMLib.ConversationType.GROUP,
messages: [], messages: [],
groupInfo: { groupInfo: {
name: '' name: ''
} }
} }
},
computed: {
latestMessage() {
return this.messages[this.messages.length - 1]
}
}, },
onLoad(e) { onLoad(e) {
this.targetId = e.targetId this.targetId = e.targetId
@@ -61,51 +67,47 @@
if (msg.targetId == this.targetId) { if (msg.targetId == this.targetId) {
this.getNewMessage() this.getNewMessage()
} }
}) })
uni.$once('cleanGroupMessage', this.getMessageList) uni.$once('cleanGroupMessage', this.getMessageList)
},
onBackPress() {
uni.$off('onReceiveMessage')
console.log('Off onReceiveMessage');
}, },
onNavigationBarButtonTap() { onNavigationBarButtonTap() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/im/group/info?targetId=' + this.targetId url: '/pages/im/group/info?targetId=' + this.targetId
}) })
}, },
methods: { methods: {
toUser(item) { toUser(item) {
if (item.senderUserId == '__system__') { if (item.senderUserId == '__system__') {
return return
} }
if (item.messageDirection == 1) { if (item.messageDirection == 1) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/im/friends/mine?targetId=' + item.senderUserId url: '/pages/im/friends/mine?targetId=' + item.senderUserId
}) })
} else{ } else {
uni.navigateTo({ uni.navigateTo({
url: '/pages/im/friends/info?targetId=' + item.senderUserId url: '/pages/im/friends/info?targetId=' + item.senderUserId
}) })
} }
}, },
getNewMessage() { getNewMessage() {
im.getMessageList( im.getMessageList(
this.conversationType, this.conversationType,
this.targetId, this.targetId,
new Date().getTime(), this.latestMessage.sentTime,
10, 1,
false, false,
(messages) => { (messages) => {
this.messages = this.messages.concat(messages) this.messages = this.messages.concat(messages)
this.scrollBottom() this.scrollBottom()
}) })
}, },
// 获取消息列表 // 获取消息列表
getMessageList() { getMessageList() {
im.getMessageList( im.getMessageList(
this.conversationType, this.conversationType,
this.targetId, this.targetId,
new Date().getTime(), 0,
100, 100,
true, true,
(messages) => { (messages) => {
@@ -115,12 +117,15 @@
}, },
// 滚动到底部 // 滚动到底部
scrollBottom(type) { scrollBottom(type) {
// 清理当前会话,未读消息数量 if (this.latestMessage) {
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime() + 1100) // 清理当前会话,未读消息数量
// 发送消息已读状态给对方 RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime()) .sentTime)
// 更新badge提醒数量 // // 发送消息已读状态给对方
im.setNotifyBadge() // RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime)
// 更新badge提醒数量
im.setNotifyBadge()
}
setTimeout(() => { setTimeout(() => {
let el = this.$refs.chatBottom let el = this.$refs.chatBottom

View File

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