diff --git a/src/event/talk.js b/src/event/talk.js index 7826004..8a1db18 100644 --- a/src/event/talk.js +++ b/src/event/talk.js @@ -94,7 +94,7 @@ class Talk extends Base { useSettingsStore().isPromptTone && palyMusic() } - handle() { + async handle() { // 不是自己发送的消息则需要播放提示音 if (!this.isCurrSender()) { this.play() @@ -102,7 +102,18 @@ class Talk extends Base { // 判断会话列表是否存在,不存在则创建 if (useTalkStore().findTalkIndex(this.getIndexName()) == -1) { - return this.addTalkItem() + if (this.resource.msg_type == 1102) { + //被邀请进入群聊时,需要热更新会话列表 + await useTalkStore().loadTalkList() + } else if (this.resource.msg_type == 1106) { + //群解散时,需要热更新会话列表 + await useTalkStore().loadTalkList() + } else if (this.resource.msg_type == 1104 || this.resource.msg_type == 1115) { + //群成员被移出时,需要热更新会话列表 + await useTalkStore().loadTalkList() + } else { + return this.addTalkItem() + } } // 判断当前是否正在和好友对话 @@ -169,10 +180,42 @@ class Talk extends Base { let record = this.resource // 群成员变化的消息,需要更新群成员列表 - if ([1102, 1103, 1104].includes(record.msg_type)) { + if ([1102, 1103, 1104, 1115].includes(record.msg_type)) { useDialogueStore().updateGroupMembers() } + //群解散时,需要更新群成员权限 + if ([1106].includes(record.msg_type)) { + useDialogueStore().updateDismiss(true) + } + + //群成员被移出时,需要更新群成员权限 + if ([1104, 1115].includes(record.msg_type)) { + if (this.resource?.extra?.members?.length > 0) { + const isMeQuit = this.resource.extra.members.find( + (item) => item.user_id === this.getAccountId() + ) + if (isMeQuit) { + useDialogueStore().updateQuit(true) + } + } + } + + // 群信息变更时,需要更新群信息 + if ([1116].includes(record.msg_type)) { + // 更新会话信息 + useDialogueStore().updateDialogueTalk({ + username: record.extra.group_name, + avatar: record.extra.group_avatar + }) + //更新会话列表中的会话信息 + useTalkStore().updateItem({ + index_name: this.getIndexName(), + name: record.extra.group_name, + avatar: record.extra.group_avatar + }) + } + useDialogueStore().addDialogueRecord(formatTalkRecord(this.getAccountId(), this.resource)) if (!this.isCurrSender()) { @@ -221,6 +264,21 @@ class Talk extends Base { msg_text: this.getTalkText(), updated_at: parseTime(new Date()) }) + //收到新消息时,同时判断是否有人@我 + if (this.resource.msg_type === 1 && this.resource?.extra?.mentions?.length > 0) { + const findMention = this.resource?.extra?.mentions?.find( + (mention) => mention === this.getAccountId() + ) + //有人@我或者@所有人,则更新会话列表 + if (findMention || this.resource?.extra?.mentions?.includes(0)) { + // useTalkStore().loadTalkList() + useTalkStore().updateItem({ + index_name: this.getIndexName(), + msg_text: this.getTalkText(), + atsign_num: 1 + }) + } + } } } diff --git a/src/store/modules/dialogue.js b/src/store/modules/dialogue.js index 0ba545b..b235bc2 100644 --- a/src/store/modules/dialogue.js +++ b/src/store/modules/dialogue.js @@ -49,6 +49,12 @@ export const useDialogueStore = defineStore('dialogue', { // 是否显示编辑器 isShowEditor: false, + //是否已被解散 + isDismiss: false, + + //是否退群/移出群 + isQuit: false, + // 是否显示会话列表 isShowSessionList: true, groupInfo: {} , @@ -80,6 +86,16 @@ export const useDialogueStore = defineStore('dialogue', { this.online = status }, + // 更新群解散状态 + updateDismiss(isDismiss) { + this.isDismiss = isDismiss + }, + + // 更新群成员退出状态 + updateQuit(isQuit) { + this.isQuit = isQuit + }, + // 更新对话信息 setDialogue(data = {}) { this.online = data.is_online == 1 @@ -95,6 +111,9 @@ export const useDialogueStore = defineStore('dialogue', { this.records = [] this.unreadBubble = 0 this.isShowEditor = data?.is_robot === 0 + + this.isDismiss = data?.is_dismiss === 1 ? true : false + this.isQuit = data?.is_quit === 1 ? true : false // 只在手动切换会话时清空 specifiedMsg // if (this.isManualSwitch) { @@ -292,6 +311,11 @@ export const useDialogueStore = defineStore('dialogue', { record.extra.url = videoInfo.url // record.extra.cover = videoInfo.cover } + }, + + // 更新会话信息 + updateDialogueTalk(params){ + Object.assign(this.talk, params) } } }) diff --git a/src/utils/talk.js b/src/utils/talk.js index 941c1a5..4377eaa 100644 --- a/src/utils/talk.js +++ b/src/utils/talk.js @@ -39,6 +39,8 @@ export function formatTalkItem(params) { is_top: 0, is_online: 0, is_robot: 0, + is_dismiss: 0, + is_quit: 0, unread_num: 0, content: '......', draft_text: '', diff --git a/src/views/message/inner/IndexSider.vue b/src/views/message/inner/IndexSider.vue index 5193042..f737c24 100644 --- a/src/views/message/inner/IndexSider.vue +++ b/src/views/message/inner/IndexSider.vue @@ -401,7 +401,8 @@ const onTabTalk = (item: ISession, follow = false) => { }).then(() => { talkStore.updateItem({ index_name: item.index_name, - unread_num: 0 + unread_num: 0, + atsign_num: 0 }) }) } diff --git a/src/views/message/inner/TalkItem.vue b/src/views/message/inner/TalkItem.vue index fca0330..905f015 100644 --- a/src/views/message/inner/TalkItem.vue +++ b/src/views/message/inner/TalkItem.vue @@ -51,6 +51,7 @@ const labelColor=[ + [有人@你] [在线] diff --git a/src/views/message/inner/panel/PanelHeader.vue b/src/views/message/inner/panel/PanelHeader.vue index 80c36ab..bcc5f55 100644 --- a/src/views/message/inner/panel/PanelHeader.vue +++ b/src/views/message/inner/panel/PanelHeader.vue @@ -19,7 +19,7 @@ defineProps({ type: Boolean, default: false }, - avatar:{ + avatar: { type: String, default: '' }, @@ -46,19 +46,22 @@ const onSetMenu = () => { /> -->
@@ -80,8 +83,13 @@ const onSetMenu = () => {
:size="18"
class="icon"
@click="emit('evnet', 'group')"
+ v-show="!dialogueStore.isDismiss && !dialogueStore.isQuit"
>
-
+