Skip to content

Commit

Permalink
Ugly hack to move notifications from cloud to offline avarayr#8
Browse files Browse the repository at this point in the history
  • Loading branch information
dmatora committed Sep 6, 2024
1 parent 7098f25 commit 420c592
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/routes/texting/$chatId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Texting
layout="ChaiMessage"
Expand Down
6 changes: 0 additions & 6 deletions src/server/models/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,6 @@ export const Chat = {
isGenerating: false,
});

// Send a notification to the user
void WebPush.sendNotification({
title: persona.name,
message: aiResponse,
});

return aiResponse;
});
},
Expand Down

0 comments on commit 420c592

Please sign in to comment.