diff --git a/plugins/msbIm.js b/plugins/msbIm.js index ed408ce..442f030 100644 --- a/plugins/msbIm.js +++ b/plugins/msbIm.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-05-18 14:54:47 * @LastEditors: ch - * @LastEditTime: 2022-06-13 10:51:59 + * @LastEditTime: 2022-06-13 19:52:36 * @Description: file content */ import { CreateUUID, FormatDate, ToAsyncAwait } from "@/plugins/utils"; @@ -171,8 +171,8 @@ class MsbIm { // 判断非服务端主动推送消息不做处理 if (data[this.option.ioKey] || data.code !== 200) { return false; - } - console.log('[im] 主动接收的消息', data); + } + console.log('[im] 主动接收的消息', data); let ctx = data.content; let historyData = [...this.sessionData], newData = []; @@ -192,13 +192,13 @@ class MsbIm { newData = [ ...historyData, { - fromAvatar: ctx.fromAvatar, + fromAvatar: ctx.session.fromAvatar, fromId: ctx.fromId, - fromNickname: ctx.fromNickname, + fromNickname: ctx.session.fromNickname, id: ctx.sessionId, lastMessage: ctx, - messageList: [ctx], - updateTimeStamp : ctx.createTimeStamp, + messageList: [ctx], + updateTimeStamp: ctx.createTimeStamp, unreadCount: 1, }, ]; @@ -269,6 +269,7 @@ class MsbIm { return Promise.reject(error); } const { content } = result; + let newData = []; content.sessionVOS.forEach((item) => { if (item.lastMessage) { @@ -279,13 +280,14 @@ class MsbIm { if (hisIndex >= 0) { historyData[hisIndex].lastMessage = item.lastMessage; historyData[hisIndex].unreadCount++; - this.setSessionData(historyData); + newData.push(historyData); } else { item.messageList = []; - const newData = [...historyData, item]; - this.setSessionData(newData); + newData = [...newData, item]; } }); + + this.setSessionData(newData); return Promise.resolve(result); } /** @@ -364,10 +366,12 @@ class MsbIm { sendStatus: 'loading', }; if (typeof msgCtx.payload === 'string') { - msgCtx.payload = JSON.parse(msgCtx.payload) + msgCtx.payload = JSON.parse(msgCtx.payload); } // 点发送,立即把消息加入消息列表,标记为发送中状态 curSession.messageList.push(msgCtx); + this.setSessionData(this.sessionData); + // 超过时间未返回视为发送失败 this.timerStatus(msgCtx); @@ -454,11 +458,5 @@ class MsbIm { } return Promise.resolve(result); } - close() { - this.socket.close(); - this.socket = null; - this.isOpen = false; - this.setSessionData([]); - } } export default MsbIm; \ No newline at end of file