Browse Source

修复bugfix

congjiang 1 month ago
parent
commit
7e27d2e82f

+ 1 - 0
src/common/constant/msgType.js

@@ -70,6 +70,7 @@ export const MSG_TYPE_GROUP = [
   EXIT_GROUP,
   DELETE_GROUP,
   CREATE_GROUP,
+  // MESSAGE_CC_GROUP,
   MESSAGE_NOTICE_GROUP,
   MESSAGE_STICKY_GROUP,
 ]

+ 56 - 54
src/stores/modules/webSocketStore.js

@@ -12,7 +12,7 @@ import {
   setMessageHook,
   handleMessageHook,
 } from "@/views/im/hook/messagesHook";
-import { add } from "lodash";
+import { add, update } from "lodash";
 
 
 // 配置常量
@@ -64,10 +64,11 @@ export const useWebSocketStore = defineStore("webSocketStore", {
     loading:false,
     applyfriend:{},//好友申请数据
     unread:false,//判断有无好友申请
-    chatDelAuth:{},//控制会话权限
-    chatRefresh:0,//刷新会话列表
+    chatDelAuth: {}, //控制会话权限
+    chatGroupAuth: {}, // 群会话权限
+    chatRefresh:0,//强制刷新会话列表
+    needRefreshIm:0,//软刷新会话列表
     indexs:0,// 接收消息计数器
-    needRefreshIm:0,//刷新会话
   }),
 
   persist: {
@@ -578,9 +579,10 @@ export const useWebSocketStore = defineStore("webSocketStore", {
     },
     // 更新会话列表消息
     updateSessionNewMessage(message, sessionId, msg = null) { 
-      console.log("更新会话列表消息:", message, sessionId);
-      // 过滤系统消息
-      if ([MsgType.MESSAGE_APPLY_FRIEND,MsgType.MESSAGE_REJECT_FRIEND,MsgType.MESSAGE_DELETE_FRIEND].includes(message.messageType)){
+      console.log("更新会话列表消息:", message, sessionId, msg);
+
+      // 过滤接收的系统消息
+      if (MsgType.MSG_SYSTEM_GROUP.includes(message.messageType)){
         return;
       }
 
@@ -620,20 +622,24 @@ export const useWebSocketStore = defineStore("webSocketStore", {
         })
       } else {
         // 创建临时会话记录
-        systemStore.ImsessionList.push({
-          uuid: sessionId,
-          name: message.toUsername || message.fromUsername || message.to || message.from,
-          type: message.messageType == 2?'group':'user',
-          message: lastMsg,
-          updatedAt: time,
-          avatar: message.avatar || '',
-          avatars: [],
-          unReadNum,
-          slience: 0,
-          stick: 0,
-        });
+        // systemStore.ImsessionList.push({
+        //   uuid: sessionId,
+        //   name: message.toUsername || message.fromUsername || message.to || message.from,
+        //   nickname: message.toUsername || message.fromUsername || message.to || message.from,
+        //   type: message.messageType == 2?'group':'user',
+        //   message: lastMsg,
+        //   updatedAt: time,
+        //   avatar: message.avatar || '',
+        //   avatars: [],
+        //   unReadNum,
+        //   slience: 0,
+        //   stick: 0,
+        // });
+        // 刷新会话列表
+        this.chatRefresh += 1;
+        return;
       }
-      // 刷新会话列表
+      // 刷新会话列表
       this.needRefreshIm += 1;
     },
 
@@ -745,6 +751,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
         // 恢复会话功能
         this.funRestoreDelAuth(message.from);
         // 需要更新会话或创建会话
+        this.chatRefresh += 1;
       }
       // 好友删除
       if (message.messageType == MsgType.MESSAGE_DELETE_FRIEND) {
@@ -755,10 +762,11 @@ export const useWebSocketStore = defineStore("webSocketStore", {
     },
     // 监控群系统消息
     listenGroupSystemMessage(message, msg = null) { 
+      console.log('群系统消息', message, msg);
       // 解散群/提出群/退群
       if (message.messageType == MsgType.DELETE_GROUP || message.messageType == MsgType.REMOVE_GROUP || message.messageType == MsgType.EXIT_GROUP) {
         // 如果存在于users中(被提出或退出的人)或者解散群
-        if ((msg && msg.user && msg.users.includes(message.to)) || message.messageType == MsgType.DELETE_GROUP) {
+        if ((msg && msg.users && msg.users.includes(message.to)) || message.messageType == MsgType.DELETE_GROUP) {
           // 禁用会话功能
           this.funDeleteDelAuth(message.from);
           // 删除会话
@@ -778,38 +786,6 @@ export const useWebSocketStore = defineStore("webSocketStore", {
 
     },
 
-    // 申请好友操作
-    // funApplyfriend(message) {
-    //   if (message.messageType == MsgType.MESSAGE_APPLY_FRIEND) {
-    //     this.applyfriend[message.from] = 1;
-    //     this.unread = true;
-    //   }
-    // },
-
-    // 删除会话
-    // funDeleteSessionMessage(message, msg) {
-    //   if (message.messageType == MsgType.MESSAGE_DELETE_FRIEND || message.messageType == MsgType.DELETE_GROUP || message.messageType == MsgType.REMOVE_GROUP || message.messageType == MsgType.EXIT_GROUP) {
-    //     // let msg;
-    //     // try {
-    //     //   msg = JSON.parse(message.content);
-    //     // } catch (e) { }
-
-    //     if (msg?.users?.includes(message.to) || message.messageType == MsgType.DELETE_GROUP) {
-    //       this.funDeleteDelAuth(message.from);
-    //       this.deleteSessionChat(message.from);
-    //     }
-    //   }
-    // },
-    // 恢复会话
-    // funRestoreSessionMessage(message) {
-    //   if (message.messageType == MsgType.CREATE_GROUP || message.messageType == MsgType.JION_GROUP || message.messageType == MsgType.INVITATION_GROUP || message.messageType == MsgType.MESSAGE_PASS_FRIEND) {
-    //     this.chatRefresh += 1;
-    //     if (message.messageType == MsgType.JION_GROUP || message.messageType == MsgType.INVITATION_GROUP || message.messageType == MsgType.MESSAGE_PASS_FRIEND) {
-    //       this.funRestoreDelAuth(message.from);
-    //     }
-    //   }
-    // },
-
     // 语音视频通知
     // 群通知
     funGroupNotice(msg){
@@ -870,7 +846,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
       this.applyfriend[uuid] = 1;
       this.unread = true;
     },
-    // 初始化好友申请数据
+    // 初始化好友申请记录
     async funInitfriend(uuid){
       if (Object.keys(this.applyfriend).length > 0){
         this.unread = true;
@@ -885,15 +861,41 @@ export const useWebSocketStore = defineStore("webSocketStore", {
       // }
       // this.unread = res.data && res.data.length > 0;
     },
+    // 初始化用户群权限
+    async funInitGroupAuth(uuid){
+    },
+    // 更新用户群权限
+    updateGroupAuth(data){ 
+      Array.isArray(data) && data.forEach(item=>{
+        if(typeof item === 'string'){
+          this.chatGroupAuth[item] = 1;
+          return;
+        }
+        if(item.uuid && item.messageType == MsgType.MESSAGE_TYPE_GROUP){
+          this.chatGroupAuth[item.uuid] = 1
+        }
+      })
+    },
+    // 校验会话权限
+    verifyChatAuth(uuid){
+      if(this.chatDelAuth[uuid] && !this.chatGroupAuth[uuid]){
+        return false;
+      }
+      return true;
+    },
     //恢复会话权限
     funRestoreDelAuth(uuid) {
       if (this.chatDelAuth[uuid]) {
         delete this.chatDelAuth[uuid]
       }
+      this.chatGroupAuth[uuid] = 1;
     },
     // 禁用会话权限
     funDeleteDelAuth(uuid){
       this.chatDelAuth[uuid] = 1;
+      if(this.chatGroupAuth[uuid]){
+        delete this.chatGroupAuth[uuid]
+      }
     },
     // 更新会话未读状态
     funUpdateUnread(uuid) {

+ 14 - 1
src/views/im/chat/index.vue

@@ -558,6 +558,15 @@ const viewBurnMessage = (message) => {
 // 真正销毁
 const destroyMessage = (message) => {
   message.content = ''; // 先清空本地显示
+  // 如果是群消息, 本地更新消息销毁
+  if (message.messageType ==  MsgType.MESSAGE_TYPE_GROUP) {
+    const msg = {isTemp: true, content: '', contentType: message.contentType, messageType: message.messageType};
+    // 更新消息
+    wsStore.modifyMessage(msg, message.id, wsStore.toUserInfo.uuid);
+    // 更新会话列表
+    wsStore.updateSessionNewMessage(msg, wsStore.toUserInfo.uuid);
+    return;
+  }
   wsStore.sendMessage({
     content: JSON.stringify({ 
       content: '',
@@ -600,7 +609,7 @@ let audioChunks = [];
 
 // 切换文字/语音输入模式
 const toggleVoiceMode = () => {
-  if(wsStore.chatDelAuth[ wsStore.toUserInfo.uuid]){
+  if(wsStore.chatDelAuth[wsStore.toUserInfo.uuid]){
     showToast(`${wsStore.toUserInfo.type == 'user' ? '对方已删除' : '您已不在群聊里面'}`);
     return;
   }
@@ -782,6 +791,10 @@ console.log(wsStore.toUserInfo);
 
 // 发送图片消息
 const afterRead = async (file) => { 
+  if(wsStore.chatDelAuth[wsStore.toUserInfo.uuid]){
+    showToast(`${wsStore.toUserInfo.type == 'user' ? '对方已删除' : '您已不在群聊里面'}`);
+    return;
+  }
   const arrayBuffer = await file.file.arrayBuffer();
   const message = {
     // content: text.value, // 如果有文本内容

+ 1 - 1
src/views/im/detail/index.vue

@@ -395,7 +395,7 @@ const changeDisturb = async () => {
     const res = await setMessageDisturb(wsStore.toUserInfo.uuid,{friendUuid:walletStore.account});
     if(res.code == 200){
         wsStore.toUserInfo.slience = res.data;
-        wsStore.updateSessionNewMessage({stick: res.data}, wsStore.toUserInfo.uuid);
+        wsStore.updateSessionNewMessage({slience: res.data}, wsStore.toUserInfo.uuid);
     }
     console.log(res)
 }

+ 11 - 7
src/views/im/hook/messagesHook.js

@@ -62,6 +62,11 @@ export const setMessageHook = (message, wsStore) => {
   // 处理好友系统消息
   wsStore.funApprovalFriend(message)
 
+  // 过滤发送的系统消息
+  if (MsgType.MSG_SYSTEM_GROUP.includes(message.messageType)) {
+    return;
+  }
+
   // 处理个人消息撤回
   if (message.messageType === MsgType.MESSAGE_REVOKE) { 
     console.log('消息撤回',message)
@@ -74,10 +79,7 @@ export const setMessageHook = (message, wsStore) => {
     // 更新会话列表
     wsStore.updateSessionNewMessage({...message, content: msg && !msg.isTemp?'[消息已销毁]':`${message.from == walletStore.account ? '你' : (message.fromUsername || '对方')}撤回了一条消息`}, message.to);
   }
-  // 过滤发送的系统消息
-  if (MsgType.MSG_SYSTEM_GROUP.includes(message.messageType)) {
-    return;
-  }
+  
   // 语音和视频挂断/拒接消息处理
   if ([Constant.CANCELL_AUDIO_ONLINE, Constant.CANCELL_VIDEO_ONLINE, Constant.REJECT_AUDIO_ONLINE, Constant.REJECT_VIDEO_ONLINE].includes(message.contentType)) {
     wsStore.pushMessage({
@@ -192,14 +194,14 @@ export const handleMessageHook = async (payload, wsStore) => {
   // }
 
   // 处理功能
-  wsStore.listenFriendSystem(message); // 好友系统消息
-  wsStore.listenGroupSystemMessage(message, msg); //群系统消息
+  wsStore.listenFriendSystem(message); // 好友系统功能消息
+  wsStore.listenGroupSystemMessage(message, msg); //群系统功能消息
   // wsStore.funCancelfriend(message); // 好友取消
   // wsStore.funDeleteSessionMessage(message, msg); // 会话禁用
   // wsStore.funRestoreSessionMessage(message, msg); // 会话恢复
 
   // 接收群系统消息
-  if (MsgType.MSG_TYPE_GROUP.indexOf(message.messageType) >= 0) {
+  if (MsgType.MSG_TYPE_GROUP.includes(message.messageType)) {
     let newContent = msg?msg.content:message.content;
     // 处理群通知
     if (message.messageType === MsgType.MESSAGE_NOTICE_GROUP) {
@@ -219,6 +221,7 @@ export const handleMessageHook = async (payload, wsStore) => {
     notifications(wsStore);
     return;
   }
+
   // 语音和视频挂断/拒接消息处理
   if ([Constant.CANCELL_AUDIO_ONLINE, Constant.CANCELL_VIDEO_ONLINE, Constant.REJECT_AUDIO_ONLINE, Constant.REJECT_VIDEO_ONLINE].includes(message.contentType)) {
     wsStore.pushMessage({
@@ -232,6 +235,7 @@ export const handleMessageHook = async (payload, wsStore) => {
       },
     });
   }
+
   // 文本消息
   if (message.contentType === MsgType.MSG_TYPE.TEXT) {
     wsStore.pushMessage(formatMessageExt({

+ 2 - 0
src/views/im/index.vue

@@ -194,6 +194,8 @@ const getuserList = async (refresh=false) => {
     //   type: "user"
     // }));
     systemStore.ImsessionList = [...list.value];
+    // 记录用户群组
+    // wsStore.updateGroupAuth(res.data || []);
   }else{
     list.value = systemStore.ImsessionList
   }