修改消息拉取记录

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

@@ -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'
}
})
})
})
},