解决发送消息之后,显示延迟的问题

This commit is contained in:
2022-02-07 15:49:38 +08:00
parent f17f264391
commit 1941fe7d99
3 changed files with 23 additions and 16 deletions

View File

@@ -47,9 +47,7 @@
if (!this.disabled) { if (!this.disabled) {
RongIMLib.clearTextMessageDraft(this.conversationType, this.targetId) RongIMLib.clearTextMessageDraft(this.conversationType, this.targetId)
im.sentText(this.conversationType, this.targetId, this.inputTxt, () => { im.sentText(this.conversationType, this.targetId, this.inputTxt, () => {
setTimeout(() => {
this.$emit('success') this.$emit('success')
}, 500)
this.inputTxt = '' this.inputTxt = ''
}) })
} }

View File

@@ -121,7 +121,14 @@
}, },
// 获取消息列表 // 获取消息列表
getMessageList() { getMessageList() {
im.getMessageList(this.conversationType, this.targetId, (messages) => { im.getMessageList(
this.conversationType,
this.targetId,
new Date().getTime(),
10,
true,
(messages) => {
console.log(messages);
this.messages = messages.reverse() this.messages = messages.reverse()
this.scrollBottom() this.scrollBottom()
}) })

View File

@@ -1,7 +1,7 @@
import store from '@/store/index.js' import store from '@/store/index.js'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index' import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
const getMessageList = (conversationType, targetId, callback) => { const getMessageList = (conversationType, targetId, timeStamp, count, isForward, callback) => {
// 获取消息列表 // 获取消息列表
const objectNames = [ const objectNames = [
'RC:TxtMsg', 'RC:TxtMsg',
@@ -16,10 +16,12 @@ const getMessageList = (conversationType, targetId, callback) => {
'RC:ReferenceMsg', 'RC:ReferenceMsg',
'RC:CombineMsg' 'RC:CombineMsg'
] ]
const timeStamp = new Date().getTime()
const count = 10 // 获取的消息数量 RongIMLib.getHistoryMessagesByTimestamp(
const isForward = true // 是否向前获取 conversationType,
RongIMLib.getHistoryMessagesByTimestamp(conversationType, targetId, objectNames, timeStamp, targetId,
objectNames,
timeStamp + 1000,
count, count,
isForward, isForward,
({ ({