From dffa773acc97c5430f3a1d6dc7fa31e384c4a46b Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 1 Nov 2025 01:11:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=AF=E7=82=B9=E5=87=BB=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E8=B7=B3=E8=BD=AC=E5=AF=B9=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/ui/App.tsx | 53 +++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/client/ui/App.tsx b/client/ui/App.tsx index 9bc86b7..8c7a9c4 100644 --- a/client/ui/App.tsx +++ b/client/ui/App.tsx @@ -119,30 +119,37 @@ export default function App() { userProfileDialogRef.current!.open = true } - Notification.requestPermission() - React.useEffect(() => { - interface OnMessageData { - chat: string - msg: Message - } - async function onMessage(_event: unknown) { - EventBus.emit('RecentsList.updateRecents') - - const event = _event as OnMessageData - if (currentChatId != event.chat) { - const chat = await DataCaches.getChatInfo(event.chat) - const user = await DataCaches.getUserProfile(event.msg.user_id) - new Notification(`${user.nickname} (对话: ${chat.title})`, { - icon: getUrlForFileByHash(chat.avatar_file_hash), - body: event.msg.text, - }) + if ('Notification' in window) { + Notification.requestPermission() + React.useEffect(() => { + interface OnMessageData { + chat: string + msg: Message } - } - Client.on('Client.onMessage', onMessage) - return () => { - Client.off('Client.onMessage', onMessage) - } - }, [currentChatId]) + async function onMessage(_event: unknown) { + EventBus.emit('RecentsList.updateRecents') + + const event = _event as OnMessageData + if (currentChatId != event.chat) { + const chat = await DataCaches.getChatInfo(event.chat) + const user = await DataCaches.getUserProfile(event.msg.user_id) + const notification = new Notification(`${user.nickname} (对话: ${chat.title})`, { + icon: getUrlForFileByHash(chat.avatar_file_hash), + body: event.msg.text, + }) + notification.addEventListener('click', () => { + setCurrentChatId(chat.id) + setIsShowChatFragment(true) + notification.close() + }) + } + } + Client.on('Client.onMessage', onMessage) + return () => { + Client.off('Client.onMessage', onMessage) + } + }, [currentChatId]) + } return (