send notifications over SSE to be displayed inside the app

This commit is contained in:
m5r
2022-06-19 17:57:51 +02:00
parent a46a4a3861
commit 6cf2f8cb94
13 changed files with 146 additions and 63 deletions

View File

@ -1,8 +1,9 @@
import { Queue } from "~/utils/queue.server";
import db from "~/utils/db.server";
import logger from "~/utils/logger.server";
import { buildMessageNotificationPayload, notify } from "~/utils/web-push.server";
import getTwilioClient from "~/utils/twilio.server";
import { buildMessageNotificationPayload, notify } from "~/utils/web-push.server";
import { notifySSE } from "~/utils/events.server";
type Payload = {
messageSid: string;
@ -39,6 +40,6 @@ export default Queue<Payload>("notify incoming message", async ({ data }) => {
const message = await twilioClient.messages.get(messageSid).fetch();
const payload = buildMessageNotificationPayload(message);
// TODO: implement WS/SSE to push new messages for users who haven't enabled push notifications
await notify(subscriptions, payload);
await notifySSE(payload);
});