私聊中头像错误展示

This commit is contained in:
2022-02-16 16:58:45 +08:00
parent fe9b79a18d
commit 255a727d32
8 changed files with 43 additions and 38 deletions

View File

@@ -64,7 +64,7 @@
} }
}, },
computed: { computed: {
user() { sender() {
return this.$store.getters.sender return this.$store.getters.sender
} }
}, },
@@ -87,8 +87,7 @@
sourceType: ['album'], sourceType: ['album'],
success: res => { success: res => {
im.sentImage(this.conversationType, this.targetId, res.tempFilePaths[0], im.sentImage(this.conversationType, this.targetId, res.tempFilePaths[0],
this.user, ( this.sender, (res) => {
res) => {
this.success() this.success()
}) })
} }
@@ -99,8 +98,7 @@
sourceType: ['camera'], sourceType: ['camera'],
success: res => { success: res => {
im.sentImage(this.conversationType, this.targetId, res.tempFilePaths[0], im.sentImage(this.conversationType, this.targetId, res.tempFilePaths[0],
this.user, ( this.sender, (res) => {
res) => {
this.success() this.success()
}) })
} }

View File

@@ -29,7 +29,7 @@
disabled() { disabled() {
return this.inputTxt.length === 0 return this.inputTxt.length === 0
}, },
user() { sender() {
return this.$store.getters.sender return this.$store.getters.sender
} }
}, },
@@ -50,7 +50,7 @@
sent() { sent() {
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, this.user, () => { im.sentText(this.conversationType, this.targetId, this.inputTxt, this.sender, () => {
this.$emit('success') this.$emit('success')
this.inputTxt = '' this.inputTxt = ''
}) })

View File

@@ -36,7 +36,7 @@
} }
}, },
computed: { computed: {
user() { sender() {
return this.$store.getters.sender return this.$store.getters.sender
} }
}, },
@@ -85,8 +85,7 @@
// 监听录音结束 // 监听录音结束
this.recorderManager.onStop(res => { this.recorderManager.onStop(res => {
im.sentVoice(this.conversationType, this.targetId, res.tempFilePath, (this.maxRecordTime - im.sentVoice(this.conversationType, this.targetId, res.tempFilePath, (this.maxRecordTime -
this this.recordTime), this.sender, () => {
.recordTime), this.user, () => {
setTimeout(() => { setTimeout(() => {
this.$emit('success') this.$emit('success')
}, 500) }, 500)

View File

@@ -4,7 +4,7 @@
<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" <u-avatar class="avatar" @click="toUser(item)" size="36" shape="square"
:src="contact(item.senderUserId).portraitUrl" /> :src="contact(item.senderUserId).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="contact(item.senderUserId).name" /> :msg="item.content" :name="contact(item.senderUserId).name" />
@@ -60,11 +60,11 @@
sentTime: 0 sentTime: 0
} }
} }
}, },
contact() { contact() {
return function(targetId) { return function(targetId) {
return this.$store.getters.contactInfo(targetId) return this.$store.getters.contactInfo(targetId)
} }
} }
}, },
onLoad(e) { onLoad(e) {
@@ -108,7 +108,7 @@
this.latestMessage.sentTime, this.latestMessage.sentTime,
1, 1,
false, false,
(messages) => { (messages) => {
this.messages = this.messages.concat(messages) this.messages = this.messages.concat(messages)
this.scrollBottom() this.scrollBottom()
}) })
@@ -122,7 +122,7 @@
100, 100,
true, true,
(messages) => { (messages) => {
this.messages = messages.reverse() this.messages = messages.reverse()
this.scrollBottom() this.scrollBottom()
}) })
}, },

View File

@@ -8,7 +8,7 @@
</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)" <u-avatar class="avatar" size="36" shape="square" @click="showUser(targetId, item.messageDirection)"
:src="userInfo.portraitUrl" /> :src="contact(item.senderUserId).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" />
@@ -69,6 +69,11 @@
sentTime: 0 sentTime: 0
} }
} }
},
contact() {
return function(targetId) {
return this.$store.getters.contactInfo(targetId)
}
} }
}, },
onLoad(e) { onLoad(e) {
@@ -113,6 +118,7 @@
1, 1,
false, false,
(messages) => { (messages) => {
console.log(messages);
this.messages = this.messages.concat(messages) this.messages = this.messages.concat(messages)
this.scrollBottom() this.scrollBottom()
}) })
@@ -125,7 +131,8 @@
0, 0,
100, 100,
true, true,
(messages) => { (messages) => {
console.log(messages);
this.messages = messages.reverse() this.messages = messages.reverse()
this.scrollBottom() this.scrollBottom()
}) })

View File

@@ -109,8 +109,7 @@ class userAuth {
.access_token) .access_token)
// 在这里登录成功链接IM服务 // 在这里登录成功链接IM服务
getImToken().then(res => { getImToken().then(res => {
console.log('在这获取IM-TOKEN', res); im.connect(res.token, res.userInfo, () => {})
im.connect(res.token, res.userInfo)
}) })
resolve() resolve()
}).catch(err => { }).catch(err => {

View File

@@ -71,14 +71,14 @@ const connect = (token, userInfo, callback) => {
}) })
}) })
}, },
fail: () => { fail: () => {
// 程序是首次运行,初始化加载好友和群组信息 // 程序是首次运行,初始化加载好友和群组信息
Promise.all([getFriends(), getMyGroups()]).then(result => { Promise.all([getFriends(), getMyGroups()]).then(result => {
result.map(contacts => { result.map(contacts => {
contacts.map(item => { contacts.map(item => {
store.dispatch('initContact', item) store.dispatch('initContact', item)
}) })
}) })
uni.setStorageSync(FK, userInfo.targetId) uni.setStorageSync(FK, userInfo.targetId)
}) })
} }
@@ -141,16 +141,16 @@ const addListeners = () => {
}).catch(err => { }).catch(err => {
console.log('ERR', err) console.log('ERR', err)
}) })
} }
if (!store.getters.contactIsExist(message.senderUserId)) { if (!store.getters.contactIsExist(message.senderUserId)) {
getUserInfo(message.senderUserId).then(res => { getUserInfo(message.senderUserId).then(res => {
store.dispatch('initContact', res) store.dispatch('initContact', res)
}).catch(err => { }).catch(err => {
console.log('ERR', err) console.log('ERR', err)
}) })
} }
newMessage(message) newMessage(message)
} else if (message.objectName === RongIMLib.ObjectName.ProfileNotification) { } else if (message.objectName === RongIMLib.ObjectName.ProfileNotification) {
// 更新会话信息 // 更新会话信息
store.dispatch('updateContact', JSON.parse(message.content.data)) store.dispatch('updateContact', JSON.parse(message.content.data))
// 调用完更新之后,删除这条消息 // 调用完更新之后,删除这条消息

View File

@@ -151,14 +151,15 @@ const sentImage = (conversationType, targetId, imageUrl, user, callback) => {
}) })
} }
const sentGif = (conversationType, targetId, gifUrl, time, callback) => { const sentGif = (conversationType, targetId, gifUrl, time, user, callback) => {
const msg = { const msg = {
conversationType: conversationType, conversationType: conversationType,
targetId: String(targetId), targetId: String(targetId),
content: { content: {
objectName: 'RC:GIFMsg', objectName: 'RC:GIFMsg',
local: 'file:///' + plus.io.convertLocalFileSystemURL(gifUrl), local: 'file:///' + plus.io.convertLocalFileSystemURL(gifUrl),
duration: time duration: time,
userInfo: user
} }
} }
RongIMLib.sendMediaMessage(msg, { RongIMLib.sendMediaMessage(msg, {
@@ -177,14 +178,15 @@ const sentGif = (conversationType, targetId, gifUrl, time, callback) => {
}) })
} }
const sendFile = (conversationType, targetId, fileUrl, time, callback) => { const sendFile = (conversationType, targetId, fileUrl, time, user, callback) => {
const msg = { const msg = {
conversationType: conversationType, conversationType: conversationType,
targetId: String(targetId), targetId: String(targetId),
content: { content: {
objectName: 'RC:FileMsg', objectName: 'RC:FileMsg',
local: 'file:///' + plus.io.convertLocalFileSystemURL(fileUrl), local: 'file:///' + plus.io.convertLocalFileSystemURL(fileUrl),
duration: time duration: time,
userInfo: user
} }
} }
RongIMLib.sendMediaMessage(msg, { RongIMLib.sendMediaMessage(msg, {
@@ -204,7 +206,7 @@ const sendFile = (conversationType, targetId, fileUrl, time, callback) => {
} }
export default { export default {
getMessageList, getMessageList,
getPendingList, getPendingList,
sentText, sentText,
sentVoice, sentVoice,