聊天记录

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

@@ -34,6 +34,7 @@
console.log('App Show')
appInit(500).then((res) => {
// getAddressList
console.log("获取到token创建长链接")
this.$store.dispatch('getAddressList');
setTimeout(() => {

File diff suppressed because one or more lines are too long

View File

@@ -540,15 +540,21 @@ export default {
}
}
//TODO 需要请求接口获取真实的消息时间
/*
chatWindowData.push(msgOffline)
store.dispatch('updateChatById', {
userId: userId,
data: chatWindowData
store.dispatch('updateChatById', {
userId: userId,
data: chatWindowData
})
store.dispatch('updateChatListInfoById', {
userId: userId,
data: msgList
})
*/
store.dispatch('tabBarpull')
store.dispatch('updateChatDataState', userId);
});

View File

@@ -139,9 +139,7 @@ export default {
// console.warn(res)
// })
sdk.getUserConversationList(0).then(res => {
console.warn(res)
})
store.dispatch('queryConversationList')
} else {

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 => {

View File

@@ -199,7 +199,7 @@
},
onLoad(e) {
uni.$on('PageScroll', ()=>{
uni.$on('PageScroll', () => {
this.scrolltoBottom()
})
@@ -285,7 +285,7 @@
this.isMobile = true
}
// TODO PC开发
this.isMobile = true
// this.isMobile = true
if (this.chatListInfo && this.chatListInfo.nickName) {
uni.setNavigationBarTitle({
@@ -363,6 +363,20 @@
console.log("########### 此时需要发送已读回执 ###########")
this.$store.dispatch('sendP2PMessageReciveAck', message)
setTimeout(() => {
this.$store.dispatch('updateChartHistoryFromServerLimit5', {
userId: this.talkTo.userId,
data: ""
})
setTimeout(() => {
this.$store.dispatch('updateChartHistoryFromServerLimit5', {
userId: this.talkTo.userId,
data: ""
})
}, 1000)
}, 1500)
},
addMsg(e) {
this.msg += e;

View File

@@ -61,6 +61,10 @@
console.log("首页获取到url参数")
console.log(options)
console.log(location.href)
// // 监听接收聊天信息
uni.$on('onP2PMessage', this.onMessage)
if (options.imUserSign) {
uni.showLoading({
title: "数据加载中...",
@@ -185,6 +189,7 @@
},
onShow() {
var i=0
this.$store.dispatch('queryConversationList');
this.$store.dispatch('tabBarpull');
this.timer = setInterval(() => {
i=i+1;
@@ -204,6 +209,11 @@
console.log('beforeUnmount');
},
methods: {
onMessage(){
setTimeout(() => {
this.$store.dispatch('queryConversationList')
}, 1000)
},
longpressItem(e, i, v) {
// console.log(e,i,v)
this.longTapItemKey = i;