聊天记录

This commit is contained in:
2023-12-05 20:24:36 +08:00
parent 8aa642ecb4
commit 228943fc02
7 changed files with 110 additions and 85 deletions

View File

@@ -138,6 +138,70 @@ const store = new Vuex.Store({
})
})
},
queryConversationList(context){
const userId = uni.getStorageSync("userId")
console.log("==================开始 获取会话列表")
_im.queryConversationList().then((res) => {
console.log("==================已经获取到会话列表")
console.log(res)
if(res.code==200){
var retdata = publicFc.getKeyObjectStorage(userId + '_' +
'chatlistData')
var _newConversationList=[]
res.data.map((item)=>{
console.log(item)
var _userId=item.ownerId==item.fromId?item.toId:item.fromId
console.log("会话对方id",_userId)
_im.getSingleUserInfo(_userId).then((userInfo) => {
var detail = userInfo.data
console.log("会话对方nickName",detail.nickName)
item.messageBody = JSON.parse(item.messageBody)
try {
if (item.messageBody.msgType == "CALL_video") {
item.messageBody.content = "【视频通话】"
}
if (item.messageBody.msgType == "CALL_voice") {
item.messageBody.content = "【语音通话】"
}
} catch (e) {
console.log(e)
}
context.dispatch('updateChatListInfoById', {
userId: _userId,
data: {
content: item.messageBody.content,
userId: _userId,
personId: _userId,
nickName: detail.nickName,
portrait: detail.photo,
time: dayjs(item.createTime).format(
"YYYY/MM/DD HH:mm:ss"),
num: item.num,
windowType: 'SINGLE',
disturb: 'N', //是否静默消息
top: 'N', //是否置顶
userType: 'SINGLE'
}
})
context.dispatch('tabBarpull')
})
})
}
})
},
updateChartHistoryFromServerLimit5(context, data) {
const _userId = uni.getStorageSync("userId")
const _userInfo = uni.getStorageSync("userInfo")
@@ -160,7 +224,7 @@ const store = new Vuex.Store({
list: []
}
var _serverMsgList = []
_im.getChatMessageHistoryList(data.userId, 1, 5).then((res) => {
_im.getChatMessageHistoryList(data.userId, 1, 3).then((res) => {
res.data.map((item) => {
item.messageBody = JSON.parse(item.messageBody)
var obj = {
@@ -212,44 +276,6 @@ const store = new Vuex.Store({
})
}
const _obj = newCurrentUserMsgList[newCurrentUserMsgList
.length - 1]
try {
var _content = JSON.parse(_obj.content)
if (_obj.msgType == "CALL_video") {
_obj.content = "【视频通话】"
}
if (_obj.msgType == "CALL_voice") {
_obj.content = "【语音通话】"
}
//判断头像是谁的
context.dispatch('updateChatListInfoById', {
userId: data.userId,
data: {
content: _obj.content,
userId: data.userId,
personId: _userId,
nickName: detail.nickName,
portrait: _userId == _obj.fromId ? _userInfo
.photo : detail.photo,
time: dayjs(_obj.time).format(
"YYYY/MM/DD HH:mm:ss"),
num: 0,
windowType: 'SINGLE',
disturb: 'N', //是否静默消息
top: 'N', //是否置顶
userType: 'SINGLE'
}
})
} catch (e) {
console.log(e)
//TODO handle the exception
}
})
})
},
@@ -307,38 +333,6 @@ const store = new Vuex.Store({
context.dispatch('getchatDatalist');
const _obj = _serverMsgList[_serverMsgList.length - 1]
var _content = JSON.parse(_obj.content)
if (_obj.msgType == "CALL_video") {
_obj.content = "【视频通话】"
}
if (_obj.msgType == "CALL_voice") {
_obj.content = "【语音通话】"
}
//判断头像是谁的
context.dispatch('updateChatListInfoById', {
userId: data.userId,
data: {
content: _obj.content,
userId: data.userId,
personId: _userId,
nickName: detail.nickName,
portrait: _userId == _obj.fromId ? _userInfo
.photo : detail.photo,
time: dayjs(_obj.time).format(
"YYYY/MM/DD HH:mm:ss"),
num: 0,
windowType: 'SINGLE',
disturb: 'N', //是否静默消息
top: 'N', //是否置顶
userType: 'SINGLE'
}
})
})
})
@@ -577,6 +571,8 @@ const store = new Vuex.Store({
if (res.data.code == 200) {
var records = res.data.result.records
context.state.addressList = records
localForage.setItem("addressList", records)
}
}
}).catch(err => {