Skip to content

Commit

Permalink
fix: notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
avarayr committed Sep 20, 2024
1 parent 6c2b8a7 commit 326f68f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/server/models/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,15 @@ export const Chat = {
isGenerating: false,
});

// Send a notification to the user
void WebPush.sendNotification({
title: persona.name,
message: aiResponse,
});
try {
// Send a notification to the user
void WebPush.sendNotification({
title: persona.name,
message: aiResponse,
});
} catch (e) {
console.error("Error sending notification", e);
}
})();
} catch (e) {
console.error("Error generating message in background", e);
Expand Down
3 changes: 2 additions & 1 deletion src/server/models/WebPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const WebPush = {
sendNotification: async (message: Notification) => {
const vapidKeys = await VapidKeys.get();
if (!vapidKeys) {
throw new Error("VAPID keys not found. Please generate them first.");
// notifications are disabled
return;
}

const subscriptions = (await db.query("web-push-subscriptions").get<WebPushSubscription>()).getValues();
Expand Down

0 comments on commit 326f68f

Please sign in to comment.