修改消息拉取记录
This commit is contained in:
@@ -92,6 +92,8 @@ export default {
|
||||
isForce: "0",
|
||||
hasVideo: "1",
|
||||
callSessionId: "",
|
||||
callStatus: "watting",//房间状态
|
||||
callRoomInfoRequetTimes:0,//房间拉取次数
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
@@ -434,7 +436,10 @@ export default {
|
||||
}).then(res => {
|
||||
if (res.status == 200) {
|
||||
this.generateVideoRoomStream(res.data.data)
|
||||
}else {
|
||||
this.generateVideoRoomStream([])
|
||||
}
|
||||
//TODO 增加网络异常时候的处理
|
||||
})
|
||||
},
|
||||
leaveRoom() {
|
||||
@@ -527,6 +532,14 @@ export default {
|
||||
})
|
||||
},
|
||||
generateVideoRoomStream(videoList) {
|
||||
this.callRoomInfoRequetTimes=this.callRoomInfoRequetTimes+1;
|
||||
if(this.callRoomInfoRequetTimes>5){
|
||||
if(videoList.length==0){
|
||||
// 拉取5次房间列表之后,如果房间里面视频流的数量为0,则关掉房间
|
||||
this.videoDownAction()
|
||||
}
|
||||
}
|
||||
|
||||
let hasUpdate = false;
|
||||
if (this.oldVideoStreamList == null) {
|
||||
this.oldVideoStreamList = videoList;
|
||||
|
||||
@@ -693,10 +693,23 @@ export default {
|
||||
if (msgSendType == 'error') {
|
||||
chatWindowData.push(msgNotSend);
|
||||
}
|
||||
// TODO 内网环境下特殊配置,消息返送出去之后不直接存储
|
||||
/*
|
||||
store.dispatch('updateChatById', {
|
||||
userId: userId,
|
||||
data: chatWindowData
|
||||
});
|
||||
*/
|
||||
setTimeout(() => {
|
||||
store.dispatch('updateChartHistoryFromServerLimit5', {
|
||||
userId: userId,
|
||||
data: {
|
||||
|
||||
}
|
||||
});
|
||||
}, 500)
|
||||
|
||||
|
||||
store.dispatch('updateChatListInfoById', {
|
||||
userId: userId,
|
||||
data: msgList
|
||||
@@ -999,16 +1012,16 @@ export default {
|
||||
});
|
||||
// #endif
|
||||
},
|
||||
formatMessage(msg){
|
||||
msg.pushType="MSG"
|
||||
var msgType="TEXT"
|
||||
formatMessage(msg) {
|
||||
msg.pushType = "MSG"
|
||||
var msgType = "TEXT"
|
||||
var data = store.state.addressList
|
||||
|
||||
const fromUserData=data.find(item=>item.userId==msg.fromId)
|
||||
const fromUserData = data.find(item => item.userId == msg.fromId)
|
||||
|
||||
|
||||
|
||||
const _data=JSON.parse(msg.messageBody)
|
||||
const _data = JSON.parse(msg.messageBody)
|
||||
// try{
|
||||
// console.log("=======================formatMessage")
|
||||
// console.log(_data)
|
||||
@@ -1018,24 +1031,24 @@ export default {
|
||||
// console.error(e)
|
||||
// //TODO handle the exception
|
||||
// }
|
||||
msg.msgContent={
|
||||
msgType:_data.msgType,
|
||||
content:_data.content,
|
||||
disturb:false,
|
||||
top:false,
|
||||
msg.msgContent = {
|
||||
msgType: _data.msgType,
|
||||
content: _data.content,
|
||||
disturb: false,
|
||||
top: false,
|
||||
}
|
||||
|
||||
msg.windowType="SINGLE"
|
||||
msg.createTime=msg.messageTime;
|
||||
msg.userId=msg.fromId;
|
||||
msg.fromInfo={
|
||||
userId:msg.fromId,
|
||||
userType:1,
|
||||
nickName:fromUserData?fromUserData.realname:msg.fromId,
|
||||
portrait:"https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png"
|
||||
msg.windowType = "SINGLE"
|
||||
msg.createTime = msg.messageTime;
|
||||
msg.userId = msg.fromId;
|
||||
msg.fromInfo = {
|
||||
userId: msg.fromId,
|
||||
userType: 1,
|
||||
nickName: fromUserData ? fromUserData.realname : msg.fromId,
|
||||
portrait: "https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png"
|
||||
};
|
||||
msg.groupInfo={};
|
||||
msg.msgId=msg.messageKey;
|
||||
msg.groupInfo = {};
|
||||
msg.msgId = msg.messageKey;
|
||||
|
||||
return msg
|
||||
|
||||
|
||||
@@ -138,13 +138,126 @@ const store = new Vuex.Store({
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
updateChartHistoryFromServer(context, data) {
|
||||
updateChartHistoryFromServerLimit5(context, data) {
|
||||
const _userId = uni.getStorageSync("userId")
|
||||
const _userInfo = uni.getStorageSync("userInfo")
|
||||
var retdata = publicFc.getKeyObjectStorage(_userId + '_' + 'chatData')
|
||||
|
||||
var currentUserMsgList = retdata[data.userId].list
|
||||
console.warn(currentUserMsgList)
|
||||
// if
|
||||
|
||||
_im.getSingleUserInfo(data.userId).then((res) => {
|
||||
var detail = res.data
|
||||
let _msgList = {
|
||||
fromInfo: {
|
||||
nickName: detail.nickName,
|
||||
portrait: detail.photo,
|
||||
userId: detail.userId,
|
||||
userType: detail.userType
|
||||
},
|
||||
groupInfo: {},
|
||||
list: []
|
||||
}
|
||||
var _serverMsgList = []
|
||||
_im.getChatMessageHistoryList(data.userId, 1, 5).then((res) => {
|
||||
res.data.map((item) => {
|
||||
item.messageBody = JSON.parse(item.messageBody)
|
||||
var obj = {
|
||||
content: item.messageBody.content,
|
||||
messageKey: item.messageKey,
|
||||
msgType: item.messageBody.msgType,
|
||||
nickName: _userId == item.fromId ? "我" :
|
||||
detail.nickName,
|
||||
portrait: _userId == item.fromId ? _userInfo
|
||||
.photo : detail.photo,
|
||||
personId: item.fromId,
|
||||
sendtype: "waiting",
|
||||
time: item.createTime,
|
||||
type: _userId == item.fromId ? 2 : 1,
|
||||
userId: item.fromId,
|
||||
windowType: "SINGLE"
|
||||
}
|
||||
|
||||
var _arr = currentUserMsgList.filter(obj => obj
|
||||
.messageKey === item.messageKey)
|
||||
if (_arr.length == 0) {
|
||||
_serverMsgList.push(obj)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const reversedServerMsgList = _serverMsgList.reverse();
|
||||
|
||||
console.log("新的未收消息数组")
|
||||
console.log(reversedServerMsgList)
|
||||
|
||||
let newCurrentUserMsgList = currentUserMsgList.concat(
|
||||
reversedServerMsgList)
|
||||
|
||||
_serverMsgList = currentUserMsgList.sort(sortBy('time'))
|
||||
|
||||
_msgList.list = newCurrentUserMsgList;
|
||||
|
||||
retdata[data.userId] = _msgList
|
||||
|
||||
uni.setStorageSync(_userId + '_' + 'chatData', JSON.stringify(
|
||||
retdata));
|
||||
|
||||
context.dispatch('getchatDatalist');
|
||||
|
||||
if (reversedServerMsgList.length > 0) {
|
||||
uni.$emit('PageScroll', {
|
||||
msg: '页面更新'
|
||||
})
|
||||
}
|
||||
|
||||
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.createTime).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
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
},
|
||||
updateChartHistoryFromServer(context, data) {
|
||||
const _userId = uni.getStorageSync("userId")
|
||||
const _userInfo = uni.getStorageSync("userInfo")
|
||||
var retdata = publicFc.getKeyObjectStorage(_userId + '_' + 'chatData')
|
||||
|
||||
// if
|
||||
|
||||
_im.getSingleUserInfo(data.userId).then((res) => {
|
||||
@@ -161,33 +274,32 @@ const store = new Vuex.Store({
|
||||
}
|
||||
var _serverMsgList = []
|
||||
_im.getChatMessageHistoryList(data.userId, 1, 100).then((res) => {
|
||||
res.data.map((item)=>{
|
||||
item.messageBody=JSON.parse(item.messageBody)
|
||||
var obj={
|
||||
content:item.messageBody.content,
|
||||
messageKey:item.messageKey,
|
||||
msgType:item.messageBody.msgType,
|
||||
nickName:_userId==item.fromId?"我":detail.nickName,
|
||||
portrait:_userId==item.fromId?_userInfo.photo:detail.photo,
|
||||
personId:item.fromId,
|
||||
sendtype:"waiting",
|
||||
time:item.createTime,
|
||||
type:_userId==item.fromId?2:1,
|
||||
userId:item.fromId,
|
||||
windowType:"SINGLE"
|
||||
res.data.map((item) => {
|
||||
item.messageBody = JSON.parse(item.messageBody)
|
||||
var obj = {
|
||||
content: item.messageBody.content,
|
||||
messageKey: item.messageKey,
|
||||
msgType: item.messageBody.msgType,
|
||||
nickName: _userId == item.fromId ? "我" :
|
||||
detail.nickName,
|
||||
portrait: _userId == item.fromId ? _userInfo
|
||||
.photo : detail.photo,
|
||||
personId: item.fromId,
|
||||
sendtype: "waiting",
|
||||
time: item.createTime,
|
||||
type: _userId == item.fromId ? 2 : 1,
|
||||
userId: item.fromId,
|
||||
windowType: "SINGLE"
|
||||
}
|
||||
/*
|
||||
if(obj.msgType=="CALL_video"){
|
||||
obj.content=JSON.parse(item.messageBody.content)
|
||||
obj.content=JSON.parse(obj.content)
|
||||
}
|
||||
*/
|
||||
|
||||
_serverMsgList.push(obj)
|
||||
|
||||
})
|
||||
|
||||
|
||||
_serverMsgList = _serverMsgList.sort(sortBy('time'))
|
||||
|
||||
_msgList.list=_serverMsgList;
|
||||
_msgList.list = _serverMsgList;
|
||||
|
||||
retdata[data.userId] = _msgList
|
||||
uni.setStorageSync(_userId + '_' + 'chatData', JSON.stringify(
|
||||
@@ -195,28 +307,30 @@ const store = new Vuex.Store({
|
||||
|
||||
context.dispatch('getchatDatalist');
|
||||
|
||||
const _obj=_serverMsgList[_serverMsgList.length-1]
|
||||
const _obj = _serverMsgList[_serverMsgList.length - 1]
|
||||
|
||||
var _content=JSON.parse(_obj.content)
|
||||
var _content = JSON.parse(_obj.content)
|
||||
|
||||
if(_obj.msgType=="CALL_video"){
|
||||
_obj.content="【视频通话】"
|
||||
if (_obj.msgType == "CALL_video") {
|
||||
_obj.content = "【视频通话】"
|
||||
}
|
||||
|
||||
if(_obj.msgType=="CALL_voice"){
|
||||
_obj.content="【语音通话】"
|
||||
if (_obj.msgType == "CALL_voice") {
|
||||
_obj.content = "【语音通话】"
|
||||
}
|
||||
//判断头像是谁的
|
||||
|
||||
context.dispatch('updateChatListInfoById',{
|
||||
userId:data.userId,
|
||||
data:{
|
||||
content:_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.createTime).format("YYYY/MM/DD HH:mm:ss"),
|
||||
portrait: _userId == _obj.fromId ? _userInfo
|
||||
.photo : detail.photo,
|
||||
time: dayjs(_obj.createTime).format(
|
||||
"YYYY/MM/DD HH:mm:ss"),
|
||||
num: 0,
|
||||
windowType: 'SINGLE',
|
||||
disturb: 'N', //是否静默消息
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<template>
|
||||
<view>
|
||||
<view class="chatNavBar">
|
||||
<uni-nav-bar :leftIcon="isMobile==true?'left':''"
|
||||
@clickLeft="clickLeftHandler">
|
||||
<view class="navBarTitle">{{title}}</view></uni-nav-bar>
|
||||
<uni-nav-bar :leftIcon="isMobile==true?'left':''" @clickLeft="clickLeftHandler">
|
||||
<view class="navBarTitle">{{title}}</view>
|
||||
</uni-nav-bar>
|
||||
</view>
|
||||
<watermark></watermark>
|
||||
<uni-popup ref="popup" type="center">
|
||||
@@ -199,6 +199,10 @@
|
||||
},
|
||||
onLoad(e) {
|
||||
|
||||
uni.$on('PageScroll', ()=>{
|
||||
this.scrolltoBottom()
|
||||
})
|
||||
|
||||
// // 监听接收聊天信息
|
||||
uni.$on('onP2PMessage', this.onMessage)
|
||||
|
||||
@@ -280,6 +284,8 @@
|
||||
if (hd_gps_location != null) {
|
||||
this.isMobile = true
|
||||
}
|
||||
// TODO PC开发
|
||||
this.isMobile = true
|
||||
|
||||
if (this.chatListInfo && this.chatListInfo.nickName) {
|
||||
uni.setNavigationBarTitle({
|
||||
@@ -356,6 +362,7 @@
|
||||
//如果当前消息发送人和当前窗口的聊天对象一致,则发送已读回执
|
||||
console.log("########### 此时需要发送已读回执 ###########")
|
||||
this.$store.dispatch('sendP2PMessageReciveAck', message)
|
||||
|
||||
},
|
||||
addMsg(e) {
|
||||
this.msg += e;
|
||||
@@ -888,6 +895,11 @@
|
||||
console.log("==============sdk:")
|
||||
console.log(this.talkTo.userId)
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
this.scrolltoBottom();
|
||||
}, 1000)
|
||||
|
||||
// this.imsdk.lim.im.sendP2PMessage(this.imsdk.lim.im.createP2PTextMessage(this.talkTo.userId, e))
|
||||
|
||||
// #endif
|
||||
@@ -957,8 +969,7 @@
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
.navBarTitle{
|
||||
.navBarTitle {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
@@ -967,6 +978,7 @@
|
||||
font-size: 16px !important;
|
||||
font-weight: bold !important;
|
||||
}
|
||||
|
||||
.chatNavBar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
|
||||
Reference in New Issue
Block a user