From 420c59267e022e6c5bb45a43448e23277750c405 Mon Sep 17 00:00:00 2001 From: Dmitry Matora Date: Sat, 7 Sep 2024 02:11:08 +0600 Subject: [PATCH] Ugly hack to move notifications from cloud to offline #8 --- src/routes/texting/$chatId.tsx | 17 +++++++++++++++++ src/server/models/Chat.ts | 6 ------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/routes/texting/$chatId.tsx b/src/routes/texting/$chatId.tsx index 670f671..0427dd5 100644 --- a/src/routes/texting/$chatId.tsx +++ b/src/routes/texting/$chatId.tsx @@ -406,6 +406,23 @@ function TextingPage() { return null; } + const showNotification = (persona: string, message: string) => { + if (Notification.permission === 'granted') { + new Notification(persona, { + body: message, + icon: '/assets/pwa/android-chrome-192x192.png' + }); + } else Notification.requestPermission(); + }; + + + useEffect(() => { + const lastMessage = messagesQuery.data?.messages[messagesQuery.data.messages.length - 1]; + if (lastMessage && !lastMessage.isGenerating && lastMessage.role === 'assistant') { + showNotification(messagesQuery.data.chat.personas[0]?.name || 'AI', lastMessage.content); + } + }, [messagesQuery.data, showNotification]); + return (