feat: 可点击通知跳转对话
This commit is contained in:
@@ -119,30 +119,37 @@ export default function App() {
|
|||||||
userProfileDialogRef.current!.open = true
|
userProfileDialogRef.current!.open = true
|
||||||
}
|
}
|
||||||
|
|
||||||
Notification.requestPermission()
|
if ('Notification' in window) {
|
||||||
React.useEffect(() => {
|
Notification.requestPermission()
|
||||||
interface OnMessageData {
|
React.useEffect(() => {
|
||||||
chat: string
|
interface OnMessageData {
|
||||||
msg: Message
|
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,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
async function onMessage(_event: unknown) {
|
||||||
Client.on('Client.onMessage', onMessage)
|
EventBus.emit('RecentsList.updateRecents')
|
||||||
return () => {
|
|
||||||
Client.off('Client.onMessage', onMessage)
|
const event = _event as OnMessageData
|
||||||
}
|
if (currentChatId != event.chat) {
|
||||||
}, [currentChatId])
|
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 (
|
return (
|
||||||
<div style={{
|
<div style={{
|
||||||
|
|||||||
Reference in New Issue
Block a user