fix(component): 🐛 修改群聊中群消息设置逻辑

修复异地同端登录没有重新登录提示问题
This commit is contained in:
Dawn
2025-04-27 02:54:25 +08:00
parent 802d224209
commit 62460fbfe0
10 changed files with 124 additions and 32 deletions
+19 -12
View File
@@ -3926,7 +3926,7 @@ version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35"
dependencies = [
"toml_edit 0.22.24",
"toml_edit 0.22.25",
]
[[package]]
@@ -6205,21 +6205,21 @@ dependencies = [
[[package]]
name = "toml"
version = "0.8.20"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148"
checksum = "900f6c86a685850b1bc9f6223b20125115ee3f31e01207d81655bbcc0aea9231"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit 0.22.24",
"toml_edit 0.22.25",
]
[[package]]
name = "toml_datetime"
version = "0.6.8"
version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3"
dependencies = [
"serde",
]
@@ -6248,17 +6248,24 @@ dependencies = [
[[package]]
name = "toml_edit"
version = "0.22.24"
version = "0.22.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474"
checksum = "10558ed0bd2a1562e630926a2d1f0b98c827da99fabd3fe20920a59642504485"
dependencies = [
"indexmap 2.9.0",
"serde",
"serde_spanned",
"toml_datetime",
"toml_write",
"winnow 0.7.7",
]
[[package]]
name = "toml_write"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28391a4201ba7eb1984cfeb6862c0b3ea2cfe23332298967c749dddc0d6cd976"
[[package]]
name = "tower"
version = "0.5.2"
@@ -7702,18 +7709,18 @@ dependencies = [
[[package]]
name = "zerocopy"
version = "0.8.24"
version = "0.8.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.24"
version = "0.8.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be"
checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef"
dependencies = [
"proc-macro2",
"quote",
+18 -6
View File
@@ -140,10 +140,10 @@
"identifier": {
"anyOf": [
{
"description": "This set of permissions describes the what kind of\nfile system access the `fs` plugin has enabled or denied by default.\n\n#### Granted Permissions\n\nThis default permission set enables read access to the\napplication specific directories (AppConfig, AppData, AppLocalData, AppCache,\nAppLog) and all files and sub directories created in it.\nThe location of these directories depends on the operating system,\nwhere the application is run.\n\nIn general these directories need to be manually created\nby the application at runtime, before accessing files or folders\nin it is possible.\n\nTherefore, it is also allowed to create all of these folders via\nthe `mkdir` command.\n\n#### Denied Permissions\n\nThis default permission set prevents access to critical components\nof the Tauri application by default.\nOn Windows the webview data folder access is denied.\n\n#### Included permissions within this default permission set:\n\n#### This default permission set includes:\n\n- `create-app-specific-dirs`\n- `read-app-specific-dirs-recursive`\n- `deny-default`",
"description": "This set of permissions describes the what kind of\nfile system access the `fs` plugin has enabled or denied by default.\n\n#### Granted Permissions\n\nThis default permission set enables read access to the\napplication specific directories (AppConfig, AppData, AppLocalData, AppCache,\nAppLog) and all files and sub directories created in it.\nThe location of these directories depends on the operating system,\nwhere the application is run.\n\nIn general these directories need to be manually created\nby the application at runtime, before accessing files or folders\nin it is possible.\n\nTherefore, it is also allowed to create all of these folders via\nthe `mkdir` command.\n\n#### Denied Permissions\n\nThis default permission set prevents access to critical components\nof the Tauri application by default.\nOn Windows the webview data folder access is denied.\n\n#### This default permission set includes:\n\n- `create-app-specific-dirs`\n- `read-app-specific-dirs-recursive`\n- `deny-default`",
"type": "string",
"const": "fs:default",
"markdownDescription": "This set of permissions describes the what kind of\nfile system access the `fs` plugin has enabled or denied by default.\n\n#### Granted Permissions\n\nThis default permission set enables read access to the\napplication specific directories (AppConfig, AppData, AppLocalData, AppCache,\nAppLog) and all files and sub directories created in it.\nThe location of these directories depends on the operating system,\nwhere the application is run.\n\nIn general these directories need to be manually created\nby the application at runtime, before accessing files or folders\nin it is possible.\n\nTherefore, it is also allowed to create all of these folders via\nthe `mkdir` command.\n\n#### Denied Permissions\n\nThis default permission set prevents access to critical components\nof the Tauri application by default.\nOn Windows the webview data folder access is denied.\n\n#### Included permissions within this default permission set:\n\n#### This default permission set includes:\n\n- `create-app-specific-dirs`\n- `read-app-specific-dirs-recursive`\n- `deny-default`"
"markdownDescription": "This set of permissions describes the what kind of\nfile system access the `fs` plugin has enabled or denied by default.\n\n#### Granted Permissions\n\nThis default permission set enables read access to the\napplication specific directories (AppConfig, AppData, AppLocalData, AppCache,\nAppLog) and all files and sub directories created in it.\nThe location of these directories depends on the operating system,\nwhere the application is run.\n\nIn general these directories need to be manually created\nby the application at runtime, before accessing files or folders\nin it is possible.\n\nTherefore, it is also allowed to create all of these folders via\nthe `mkdir` command.\n\n#### Denied Permissions\n\nThis default permission set prevents access to critical components\nof the Tauri application by default.\nOn Windows the webview data folder access is denied.\n\n#### This default permission set includes:\n\n- `create-app-specific-dirs`\n- `read-app-specific-dirs-recursive`\n- `deny-default`"
},
{
"description": "This allows non-recursive read access to metadata of the application folders, including file listing and statistics.\n#### This permission set includes:\n\n- `read-meta`\n- `scope-app-index`",
@@ -2492,6 +2492,12 @@
"const": "core:app:allow-set-app-theme",
"markdownDescription": "Enables the set_app_theme command without any pre-configured scope."
},
{
"description": "Enables the set_dock_visibility command without any pre-configured scope.",
"type": "string",
"const": "core:app:allow-set-dock-visibility",
"markdownDescription": "Enables the set_dock_visibility command without any pre-configured scope."
},
{
"description": "Enables the tauri_version command without any pre-configured scope.",
"type": "string",
@@ -2552,6 +2558,12 @@
"const": "core:app:deny-set-app-theme",
"markdownDescription": "Denies the set_app_theme command without any pre-configured scope."
},
{
"description": "Denies the set_dock_visibility command without any pre-configured scope.",
"type": "string",
"const": "core:app:deny-set-dock-visibility",
"markdownDescription": "Denies the set_dock_visibility command without any pre-configured scope."
},
{
"description": "Denies the tauri_version command without any pre-configured scope.",
"type": "string",
@@ -4383,10 +4395,10 @@
"markdownDescription": "Denies the save command without any pre-configured scope."
},
{
"description": "This set of permissions describes the what kind of\nfile system access the `fs` plugin has enabled or denied by default.\n\n#### Granted Permissions\n\nThis default permission set enables read access to the\napplication specific directories (AppConfig, AppData, AppLocalData, AppCache,\nAppLog) and all files and sub directories created in it.\nThe location of these directories depends on the operating system,\nwhere the application is run.\n\nIn general these directories need to be manually created\nby the application at runtime, before accessing files or folders\nin it is possible.\n\nTherefore, it is also allowed to create all of these folders via\nthe `mkdir` command.\n\n#### Denied Permissions\n\nThis default permission set prevents access to critical components\nof the Tauri application by default.\nOn Windows the webview data folder access is denied.\n\n#### Included permissions within this default permission set:\n\n#### This default permission set includes:\n\n- `create-app-specific-dirs`\n- `read-app-specific-dirs-recursive`\n- `deny-default`",
"description": "This set of permissions describes the what kind of\nfile system access the `fs` plugin has enabled or denied by default.\n\n#### Granted Permissions\n\nThis default permission set enables read access to the\napplication specific directories (AppConfig, AppData, AppLocalData, AppCache,\nAppLog) and all files and sub directories created in it.\nThe location of these directories depends on the operating system,\nwhere the application is run.\n\nIn general these directories need to be manually created\nby the application at runtime, before accessing files or folders\nin it is possible.\n\nTherefore, it is also allowed to create all of these folders via\nthe `mkdir` command.\n\n#### Denied Permissions\n\nThis default permission set prevents access to critical components\nof the Tauri application by default.\nOn Windows the webview data folder access is denied.\n\n#### This default permission set includes:\n\n- `create-app-specific-dirs`\n- `read-app-specific-dirs-recursive`\n- `deny-default`",
"type": "string",
"const": "fs:default",
"markdownDescription": "This set of permissions describes the what kind of\nfile system access the `fs` plugin has enabled or denied by default.\n\n#### Granted Permissions\n\nThis default permission set enables read access to the\napplication specific directories (AppConfig, AppData, AppLocalData, AppCache,\nAppLog) and all files and sub directories created in it.\nThe location of these directories depends on the operating system,\nwhere the application is run.\n\nIn general these directories need to be manually created\nby the application at runtime, before accessing files or folders\nin it is possible.\n\nTherefore, it is also allowed to create all of these folders via\nthe `mkdir` command.\n\n#### Denied Permissions\n\nThis default permission set prevents access to critical components\nof the Tauri application by default.\nOn Windows the webview data folder access is denied.\n\n#### Included permissions within this default permission set:\n\n#### This default permission set includes:\n\n- `create-app-specific-dirs`\n- `read-app-specific-dirs-recursive`\n- `deny-default`"
"markdownDescription": "This set of permissions describes the what kind of\nfile system access the `fs` plugin has enabled or denied by default.\n\n#### Granted Permissions\n\nThis default permission set enables read access to the\napplication specific directories (AppConfig, AppData, AppLocalData, AppCache,\nAppLog) and all files and sub directories created in it.\nThe location of these directories depends on the operating system,\nwhere the application is run.\n\nIn general these directories need to be manually created\nby the application at runtime, before accessing files or folders\nin it is possible.\n\nTherefore, it is also allowed to create all of these folders via\nthe `mkdir` command.\n\n#### Denied Permissions\n\nThis default permission set prevents access to critical components\nof the Tauri application by default.\nOn Windows the webview data folder access is denied.\n\n#### This default permission set includes:\n\n- `create-app-specific-dirs`\n- `read-app-specific-dirs-recursive`\n- `deny-default`"
},
{
"description": "This allows non-recursive read access to metadata of the application folders, including file listing and statistics.\n#### This permission set includes:\n\n- `read-meta`\n- `scope-app-index`",
@@ -6531,10 +6543,10 @@
"markdownDescription": "Denies the version command without any pre-configured scope."
},
{
"description": "This permission set configures which\nprocess feeatures are by default exposed.\n\n#### Granted Permissions\n\nThis enables to quit via `allow-exit` and restart via `allow-restart`\nthe application.\n\n#### This default permission set includes:\n\n- `allow-exit`\n- `allow-restart`",
"description": "This permission set configures which\nprocess features are by default exposed.\n\n#### Granted Permissions\n\nThis enables to quit via `allow-exit` and restart via `allow-restart`\nthe application.\n\n#### This default permission set includes:\n\n- `allow-exit`\n- `allow-restart`",
"type": "string",
"const": "process:default",
"markdownDescription": "This permission set configures which\nprocess feeatures are by default exposed.\n\n#### Granted Permissions\n\nThis enables to quit via `allow-exit` and restart via `allow-restart`\nthe application.\n\n#### This default permission set includes:\n\n- `allow-exit`\n- `allow-restart`"
"markdownDescription": "This permission set configures which\nprocess features are by default exposed.\n\n#### Granted Permissions\n\nThis enables to quit via `allow-exit` and restart via `allow-restart`\nthe application.\n\n#### This default permission set includes:\n\n- `allow-exit`\n- `allow-restart`"
},
{
"description": "Enables the exit command without any pre-configured scope.",
+55 -8
View File
@@ -83,7 +83,7 @@
</n-popover>
</div>
<div class="options-box" @click="handleCreateGroupOrInvite">
<div v-if="activeItem.roomId !== '1'" class="options-box" @click="handleCreateGroupOrInvite">
<n-popover trigger="hover" :show-arrow="false" placement="bottom">
<template #trigger>
<svg><use href="#launch"></use></svg>
@@ -211,13 +211,16 @@
</div>
<!-- 我本群的昵称 -->
<p class="text-(12px #909090) mt-20px mb-10px">我本群的昵称</p>
<p class="text-(12px [--chat-text-color]) mt-20px mb-10px">我本群的昵称</p>
<n-input
class="border-(solid 1px [--line-color]) custom-shadow"
v-model:value="groupDetail.myNickname"
@update:value="updateGroupInfo($event, 'nickname')" />
<!-- 群备注 -->
<p class="text-(12px #909090) mt-20px mb-10px">群备注</p>
<p class="flex-start-center gap-10px text-(12px [--chat-text-color]) mt-20px mb-10px">
群备注
<span class="text-(10px #909090)">(群备注仅自己可见)</span>
</p>
<n-input
class="border-(solid 1px [--line-color]) custom-shadow"
v-model:value="groupDetail.groupRemark"
@@ -242,12 +245,21 @@
:value="activeItem.muteNotification === NotificationTypeEnum.NOT_DISTURB"
@update:value="handleNotification" />
</div>
</n-flex>
</div>
<div class="h-1px bg-[--setting-item-line] m-[10px_0]"></div>
<!-- 群消息设置(仅在消息免打扰开启时显示) -->
<div
v-if="activeItem.muteNotification === NotificationTypeEnum.NOT_DISTURB"
class="box-item cursor-default">
<n-flex vertical justify="center" :size="4">
<p class="text-(12px #909090) pb-14px">群消息设置</p>
<div class="flex-between-center">
<p>屏蔽群消息</p>
<n-switch size="small" :value="activeItem.shield" @update:value="handleShield" />
<n-select
v-model:value="messageSettingType"
:options="messageSettingOptions"
@update:value="handleMessageSetting" />
</div>
</n-flex>
</div>
@@ -410,6 +422,17 @@ if (type() !== 'linux') {
peerConnection = new RTCPeerConnection()
}
const messageSettingType = ref(
activeItem.shield
? 'shield'
: activeItem.muteNotification === NotificationTypeEnum.NOT_DISTURB
? 'notification'
: 'shield'
)
const messageSettingOptions = ref([
{ label: '接收消息但不提醒', value: 'notification' },
{ label: '屏蔽消息', value: 'shield' }
])
const MIN_LOADING_TIME = 300 // 最小加载时间(毫秒)
/** 是否在线 */
const isOnline = computed(() => {
@@ -568,7 +591,7 @@ const handleCreateGroupOrInvite = () => {
/** 处理创建群聊 */
const handleCreateGroup = () => {
console.log(111)
useMitt.emit(MittEnum.CREATE_GROUP, activeItem.id)
}
/** 处理邀请进群 */
@@ -684,7 +707,14 @@ const handleTop = (value: boolean) => {
/** 处理消息免打扰 */
const handleNotification = (value: boolean) => {
const newType = value ? NotificationTypeEnum.NOT_DISTURB : NotificationTypeEnum.RECEPTION
// 如果当前是屏蔽状态,需要先取消屏蔽
if (activeItem.shield) {
handleShield(false)
}
// 设置为消息免打扰时初始化为接收消息但不提醒
if (value) {
messageSettingType.value = 'notification'
}
apis
.notification({
roomId: activeItem.roomId,
@@ -747,6 +777,23 @@ const handleShield = (value: boolean) => {
})
}
const handleMessageSetting = (value: string) => {
if (value === 'shield') {
if (activeItem.shield) return
handleShield(true)
} else if (value === 'notification') {
// 检查当前的消息提醒状态是否已经是免打扰
const isCurrentlyMuted = activeItem.muteNotification === NotificationTypeEnum.NOT_DISTURB
// 如果当前是屏蔽状态,需要先取消屏蔽
if (activeItem.shield) {
handleShield(false)
}
if (isCurrentlyMuted) return
handleNotification(true)
}
}
/** 删除操作二次提醒 */
const handleDelete = (label: RoomActEnum) => {
modalShow.value = true
+3 -1
View File
@@ -93,7 +93,9 @@ export enum MittEnum {
/** 消息动画 */
MESSAGE_ANIMATION = 'messageAnimation',
/** 聊天框滚动到底部 */
CHAT_SCROLL_BOTTOM = 'CHAT_SCROLL_BOTTOM'
CHAT_SCROLL_BOTTOM = 'CHAT_SCROLL_BOTTOM',
/** 创建群聊 */
CREATE_GROUP = 'createGroup'
}
/** 主题类型 */
+5
View File
@@ -269,6 +269,11 @@ onMounted(async () => {
useMitt.on(MittEnum.SHRINK_WINDOW, (event: boolean) => {
shrinkStatus.value = event
})
useMitt.on(MittEnum.CREATE_GROUP, (event: { id: string }) => {
createGroupModal.value = true
console.log(event)
// TODO: 选用并且禁用当前 event.id 对应的uid的用户
})
useMitt.on(MittEnum.MSG_BOX_SHOW, (event: any) => {
if (!event) return
currentMsg.value = event
+6 -2
View File
@@ -169,11 +169,11 @@ useMitt.on(WsResponseMessageType.ONLINE, async (onStatusChangeType: OnStatusChan
}
})
useMitt.on(WsResponseMessageType.TOKEN_EXPIRED, async (wsTokenExpire: WsTokenExpire) => {
if (Number(userUid) === Number(wsTokenExpire.uid) && userStore.userInfo.client === wsTokenExpire.client) {
if (Number(userUid.value) === Number(wsTokenExpire.uid) && userStore.userInfo.client === wsTokenExpire.client) {
console.log('收到用户token过期通知', wsTokenExpire)
// 聚焦主窗口
const home = await WebviewWindow.getByLabel('home')
await home?.setFocus()
console.log('账号在其他设备登录', wsTokenExpire)
useMitt.emit(MittEnum.LEFT_MODAL_SHOW, {
type: ModalEnum.REMOTE_LOGIN,
props: {
@@ -298,6 +298,10 @@ useMitt.on(WsResponseMessageType.ROOM_INFO_CHANGE, async (data: { roomId: string
await groupStore.getCountStatistic()
}
})
useMitt.on(WsResponseMessageType.ROOM_DISSOLUTION, async () => {
// 刷新群聊列表
await contactStore.getGroupChatList()
})
onBeforeMount(async () => {
// 默认执行一次
+5
View File
@@ -344,6 +344,11 @@ class WS {
)
break
}
case WsResponseMessageType.ROOM_DISSOLUTION: {
console.log('群解散', params.data)
useMitt.emit(WsResponseMessageType.ROOM_DISSOLUTION, params.data)
break
}
default: {
console.log('接收到未处理类型的消息:', params)
break
+1 -1
View File
@@ -24,7 +24,7 @@ export const useGlobalStore = defineStore(
})
// 当前会话信息:包含房间ID和房间类型
const currentSession = reactive<{ roomId: string; type: RoomTypeEnum }>({
const currentSession = ref<{ roomId: string; type: RoomTypeEnum }>({
roomId: '1',
type: RoomTypeEnum.GROUP
})
+1
View File
@@ -135,6 +135,7 @@ const hasPendingFriendRequests = computed(() => {
/** 群聊列表 */
const groupChatList = computed(() => {
console.log(contactStore.groupChatList)
return [...contactStore.groupChatList].sort((a, b) => {
// 将roomId为'1'的群聊排在最前面
if (a.roomId === '1' && b.roomId !== '1') return -1
+11 -2
View File
@@ -148,6 +148,13 @@ const sessionList = computed(() => {
latestAvatar = useUserInfo(item.id).value.avatar || item.avatar
}
// 获取群聊备注名称(如果有)
let displayName = item.name
if (item.type === RoomTypeEnum.GROUP && item.remark) {
// 使用群组备注(如果存在)
displayName = item.remark
}
if (lastMsg) {
const lastMsgUserName = useUserInfo(lastMsg.fromUser.uid)
@@ -184,20 +191,22 @@ const sessionList = computed(() => {
? `${atPrefix}${messageContent}` // 有人@我时才保留HTML标签
: messageContent // 正常消息内容已在renderReplyContent中被转义
// 返回带有isAtMe标记的对象
// 返回带有isAtMe标记的对象和修改后的名称
return {
...item,
avatar: latestAvatar,
name: displayName, // 使用可能修改过的显示名称
lastMsg: LastUserMsg || item.text || '欢迎使用HuLa',
lastMsgTime: formatTimestamp(item?.activeTime),
isAtMe: isAtMe
}
}
// 如果没有最后一条消息,则返回不带@标记的对象
// 如果没有最后一条消息,则返回不带@标记的对象,但也包含修改后的名称
return {
...item,
avatar: latestAvatar,
name: displayName, // 使用可能修改过的显示名称
lastMsg: item.text || '欢迎使用HuLa',
lastMsgTime: formatTimestamp(item?.activeTime),
isAtMe: false