修改消息拉取记录

This commit is contained in:
2023-12-04 22:25:19 +08:00
parent 6f690c1987
commit d2a3af7f1f
4 changed files with 262 additions and 110 deletions

View File

@@ -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;

View File

@@ -2,7 +2,7 @@ import http from '@/common/request'
import browser from '@/common/browser'
import store from '../store'
import pinyin from '@/common/pinyin.js';
import dayjs from "dayjs"
import dayjs from "dayjs"
import localForage from 'localforage';
@@ -346,7 +346,7 @@ export default {
*/
const _userId = uni.getStorageSync("userId")
this.pushInMsg({
type: resbody.msgContent.msgType == 'ALERT' ? 3 : 1, //显示类型 1左侧 2右侧 3中间
msgContent: resbody.msgContent.content, //msg内容
@@ -466,11 +466,11 @@ export default {
store.dispatch('getChatList');
var chatWindowData = store.state.chatDatalist[userId].list
var chatListInfo = store.state.chatlist[userId]
var data2 = this.getKeyObjectStorage(store.state.userInfo.userId + '_' +
'chatlistData')
// var _num=data2[userId].num||
// 找到数组中对象属性值一样的对象并返回
function arrfindobject({
arr,
@@ -682,7 +682,7 @@ export default {
// TODO
// 发送完成之后设置消息状态
//TODO
//TODO
// msgSendType = 'error';
msgOffline.sendtype = msgSendType;
msgOffline.msgId = "1231"
@@ -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
@@ -995,20 +1008,20 @@ export default {
}
titleObj.buttons[index].text = text;
currentWebview.setStyle({
titleNView: titleObj
titleNView: titleObj
});
// #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 _data=JSON.parse(msg.messageBody)
const fromUserData = data.find(item => item.userId == msg.fromId)
const _data = JSON.parse(msg.messageBody)
// try{
// console.log("=======================formatMessage")
// console.log(_data)
@@ -1018,27 +1031,27 @@ 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
},
debounce(func, wait = 1000, immediate = true) {
/**

View File

@@ -5,7 +5,7 @@ import * as sdk from "@/common/imSdk/lim-sdk.js";
import lim from "@/common/imSdk/sdk-bridge.js";
import localForage from 'localforage';
import dayjs from "dayjs"
import dayjs from "dayjs"
const _im = lim.lim.im
function sortBy(field) {
@@ -109,7 +109,7 @@ const store = new Vuex.Store({
tabBarpull(context) {
context.dispatch('get_UserInfo').then(res => {
context.dispatch('getChatList')
// 新朋友圈
var topicRed = publicFc.getKeyObjectStorage('topicRed')
context.state.topicRed = topicRed
@@ -117,7 +117,7 @@ const store = new Vuex.Store({
var friendApply = publicFc.getKeyObjectStorage('friendApply')
context.state.friendApply = friendApply
var chatListNum = context.state.chatListNum ? context.state.chatListNum : 0
// #ifdef APP-PLUS
plus.runtime.setBadgeNumber(sumCount);
// #endif
@@ -138,14 +138,127 @@ const store = new Vuex.Store({
})
})
},
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')
var currentUserMsgList = retdata[data.userId].list
// if
// if
_im.getSingleUserInfo(data.userId).then((res) => {
var detail = res.data
@@ -161,70 +274,71 @@ 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"
}
/*
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;
retdata[data.userId] = _msgList
uni.setStorageSync(_userId + '_' + 'chatData', JSON.stringify(
retdata));
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.createTime).format("YYYY/MM/DD HH:mm:ss"),
num: 0,
windowType: 'SINGLE',
disturb: 'N', //是否静默消息
top: 'N', //是否置顶
userType: '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"
}
_serverMsgList.push(obj)
})
_serverMsgList = _serverMsgList.sort(sortBy('time'))
_msgList.list = _serverMsgList;
retdata[data.userId] = _msgList
uni.setStorageSync(_userId + '_' + 'chatData', JSON.stringify(
retdata));
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.createTime).format(
"YYYY/MM/DD HH:mm:ss"),
num: 0,
windowType: 'SINGLE',
disturb: 'N', //是否静默消息
top: 'N', //是否置顶
userType: 'SINGLE'
}
})
})
})
},

View File

@@ -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,9 +969,8 @@
</script>
<style lang="scss" scoped>
.navBarTitle{
width: 100%;
.navBarTitle {
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
@@ -967,6 +978,7 @@
font-size: 16px !important;
font-weight: bold !important;
}
.chatNavBar {
position: fixed;
top: 0;