接入有人@你功能,并实现热更新;接入群信息更新、双场景下的群聊解散、退群消息更新群聊设置按钮点击权限

This commit is contained in:
wangyifeng 2025-05-31 03:53:18 +08:00
parent d5b0a8b599
commit dbdec912ce
6 changed files with 112 additions and 18 deletions

View File

@ -94,7 +94,7 @@ class Talk extends Base {
useSettingsStore().isPromptTone && palyMusic()
}
handle() {
async handle() {
// 不是自己发送的消息则需要播放提示音
if (!this.isCurrSender()) {
this.play()
@ -102,8 +102,19 @@ class Talk extends Base {
// 判断会话列表是否存在,不存在则创建
if (useTalkStore().findTalkIndex(this.getIndexName()) == -1) {
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()
}
}
// 判断当前是否正在和好友对话
if (this.isTalk(this.talk_type, this.receiver_id, this.sender_id)) {
@ -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
})
}
}
}
}

View File

@ -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
@ -96,6 +112,9 @@ export const useDialogueStore = defineStore('dialogue', {
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) {
// this.specifiedMsg = ''
@ -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)
}
}
})

View File

@ -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: '',

View File

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

View File

@ -51,6 +51,7 @@ const labelColor=[
<span class="detail" v-html="data.draft_text" />
</template>
<template v-else>
<span class="draft" v-show="data.talk_type == 2 && data.atsign_num"> [有人@] </span>
<span class="online" v-show="data.talk_type == 1 && data.is_online == 1"> [在线] </span>
<span class="detail" v-html="data.msg_text" />
</template>

View File

@ -19,7 +19,7 @@ defineProps({
type: Boolean,
default: false
},
avatar:{
avatar: {
type: String,
default: ''
},
@ -46,10 +46,14 @@ const onSetMenu = () => {
/>
</div> -->
<div class="flex items-center">
<avatarModule class="mr-10px" :mode="dialogueStore.talk.talk_type"
<avatarModule
class="mr-10px"
:mode="dialogueStore.talk.talk_type"
:avatar="avatar"
:groupType="dialogueStore.talk?.group_type"
:userName="username" :customStyle="{width:'42px',height:'42px'}"></avatarModule>
:userName="username"
:customStyle="{ width: '42px', height: '42px' }"
></avatarModule>
<div class="module left-module">
<!-- <span class="tag" :class="{ red: type == 1 }">
{{ type == 1 ? '好友' : '群聊' }}
@ -59,7 +63,6 @@ const onSetMenu = () => {
</div>
</div>
<div class="module center-module" v-if="type == 1">
<p class="online">
<span class="online-status" v-show="online"></span>
@ -80,8 +83,13 @@ const onSetMenu = () => {
:size="18"
class="icon"
@click="emit('evnet', 'group')"
v-show="!dialogueStore.isDismiss && !dialogueStore.isQuit"
>
<img style="width: 20px; height: 20px;" src="@/assets/image/chatList/chat-settings.png" alt="" />
<img
style="width: 20px; height: 20px;"
src="@/assets/image/chatList/chat-settings.png"
alt=""
/>
</n-icon>
</div>
</header>
@ -156,7 +164,7 @@ const onSetMenu = () => {
text-align: center;
&.color {
color: #462AA0;
color: #462aa0;
}
.online-status {
@ -168,7 +176,7 @@ const onSetMenu = () => {
vertical-align: middle;
border-radius: 50%;
position: relative;
background-color: #462AA0;
background-color: #462aa0;
margin-right: 5px;
&:after {
@ -177,7 +185,7 @@ const onSetMenu = () => {
left: -1px;
width: 100%;
height: 100%;
border: 1px solid #462AA0;
border: 1px solid #462aa0;
border-radius: 50%;
-webkit-animation: antStatusProcessing 1.2s ease-in-out infinite;
animation: antStatusProcessing 1.2s ease-in-out infinite;