|
@@ -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) {
|