用户昵称,头像,本地缓存与更新规则
This commit is contained in:
@@ -108,8 +108,8 @@
|
||||
onLoad(e) {
|
||||
this.targetId = e.targetId
|
||||
getFriendInfo(e.targetId).then(res => {
|
||||
this.userInfo = res
|
||||
// 获取到用户信息之后,去检查一下要不要更新
|
||||
this.userInfo = res
|
||||
// 获取到用户信息之后,去检查一下要不要更新
|
||||
this.$store.dispatch('updateFriend', res)
|
||||
uni.setNavigationBarTitle({
|
||||
title: res.name
|
||||
@@ -143,7 +143,7 @@
|
||||
},
|
||||
toPrivate() {
|
||||
uni.redirectTo({
|
||||
url: '/pages/im/private/chat?conversationType=1&targetId=' + this.targetId
|
||||
url: '/pages/im/private/chat?targetId=' + this.targetId
|
||||
});
|
||||
},
|
||||
setRemark() {
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
</view>
|
||||
<view class="content u-border-bottom">
|
||||
<view class="header">
|
||||
<view class="name">{{ friend(item.targetId).name || '未知用户' }}</view>
|
||||
<view class="name">{{ friend(item.targetId).name }}</view>
|
||||
<view class="time">{{ item.sentTime|timeCustomCN }}</view>
|
||||
</view>
|
||||
<message-preview class="preview" :msg="item.latestMessage" />
|
||||
@@ -218,8 +218,7 @@
|
||||
toDetail(item) {
|
||||
this.hidePop()
|
||||
uni.navigateTo({
|
||||
url: '/pages/im/private/chat?targetId=' + item.targetId + '&conversationType=' + item
|
||||
.conversationType
|
||||
url: '/pages/im/private/chat?targetId=' + item.targetId
|
||||
})
|
||||
},
|
||||
toFriend(targetId) {
|
||||
|
||||
@@ -87,16 +87,12 @@
|
||||
},
|
||||
onLoad(e) {
|
||||
this.targetId = e.targetId
|
||||
this.conversationType = e.conversationType // 会话类型
|
||||
this.userInfo = this.$store.getters.userInfo(this.targetId)
|
||||
|
||||
console.log(this.userInfo);
|
||||
// 获取消息列表
|
||||
this.initMessageList()
|
||||
|
||||
uni.setNavigationBarTitle({
|
||||
title: this.userInfo.name
|
||||
})
|
||||
// 获取消息列表
|
||||
this.initMessageList()
|
||||
// 监听消息已读状态
|
||||
uni.$on('onReadReceiptReceived', (data) => {
|
||||
if (data.targetId == this.targetId) {
|
||||
|
||||
@@ -58,6 +58,7 @@ export default {
|
||||
model.find('userId=' + userInfo.userId, (err, result) => {
|
||||
if (userInfo.hash != result[0].hash) {
|
||||
commit('updateFriendInfo', userInfo)
|
||||
console.log(userInfo);
|
||||
if (userInfo.portraitUrl && userInfo.portraitUrl != result[0].portraitUrl) {
|
||||
saveAvatar(userInfo, (savedFilePath) => {
|
||||
const info = {
|
||||
@@ -67,7 +68,9 @@ export default {
|
||||
portraitUrl: userInfo.portraitUrl,
|
||||
localAvatar: savedFilePath
|
||||
}
|
||||
model.update('userId=' + userInfo.userId, info)
|
||||
model.update('userId=' + userInfo.userId, info, (err, res) => {
|
||||
console.log('保存结果', err, res);
|
||||
})
|
||||
commit('updateFriendInfo', info)
|
||||
})
|
||||
} else {
|
||||
@@ -76,9 +79,11 @@ export default {
|
||||
name: userInfo.name,
|
||||
hash: userInfo.hash,
|
||||
portraitUrl: userInfo.portraitUrl,
|
||||
localAvatar: ''
|
||||
localAvatar: result[0].localAvatar
|
||||
}
|
||||
model.update('userId=' + userInfo.userId, info)
|
||||
model.update('userId=' + userInfo.userId, info, (err, res) => {
|
||||
console.log('保存结果', err, res);
|
||||
})
|
||||
}
|
||||
} else {
|
||||
console.log('不用更新的用户', userInfo.userId, userInfo.name);
|
||||
@@ -102,7 +107,9 @@ export default {
|
||||
portraitUrl: userInfo.portraitUrl,
|
||||
localAvatar: savedFilePath
|
||||
}
|
||||
model.insert(info)
|
||||
model.insert(info, (err, res) => {
|
||||
console.log('保存结果', err, res);
|
||||
})
|
||||
// 保存头像后,更新信息
|
||||
commit('updateFriendInfo', info)
|
||||
})
|
||||
@@ -115,7 +122,9 @@ export default {
|
||||
portraitUrl: userInfo.portraitUrl,
|
||||
localAvatar: ''
|
||||
}
|
||||
model.insert(info)
|
||||
model.insert(info, (err, res) => {
|
||||
console.log('保存结果', err, res);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,8 +136,11 @@ const addListeners = () => {
|
||||
console.log('收到消息', res.data.message);
|
||||
const message = res.data.message
|
||||
if (inArray(message.objectName, notifyMsgTypes)) {
|
||||
console.log('new Message');
|
||||
console.log('通知并计数的消息');
|
||||
newMessage(message)
|
||||
} else if (message.objectName === 'RC:ProfileNtf') {
|
||||
console.log('更新资料消息', JSON.parse(message.content.data));
|
||||
store.dispatch('updateFriend', JSON.parse(message.content.data))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
20
utils/im/profile-update.json
Normal file
20
utils/im/profile-update.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"objectName": "RC:ProfileNtf",
|
||||
"receivedTime": 1644312766084,
|
||||
"extra": "",
|
||||
"messageUId": "BUR2-MQHQ-SMIO-I32D",
|
||||
"conversationType": 6,
|
||||
"messageDirection": 2,
|
||||
"senderUserId": "10047",
|
||||
"content": {
|
||||
"extra": "",
|
||||
"operation": "Update",
|
||||
"objectName": "RC:ProfileNtf",
|
||||
"data": "{\"a\":2,\"m\":\"修改用户信息\"}"
|
||||
},
|
||||
"targetId": "10047",
|
||||
"sentTime": 1644312766699,
|
||||
"messageId": 26,
|
||||
"receivedStatus": 0,
|
||||
"sentStatus": 30
|
||||
}
|
||||
Reference in New Issue
Block a user