From ebd66d6c1ac6923ff2bd54cb13f6202383183d3b Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 19 Jan 2023 12:09:34 +0000 Subject: [PATCH] Send notifications --- src/feed/LoginFeed.ts | 17 ++++++++++++++--- src/pages/Layout.tsx | 9 --------- src/state/Login.ts | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/feed/LoginFeed.ts b/src/feed/LoginFeed.ts index 52cfab6f..f3eb448b 100644 --- a/src/feed/LoginFeed.ts +++ b/src/feed/LoginFeed.ts @@ -1,3 +1,4 @@ +import Nostrich from "./nostrich.jpg"; import { useEffect, useMemo } from "react"; import { useDispatch, useSelector } from "react-redux"; import { HexKey } from "../nostr"; @@ -61,9 +62,19 @@ export default function useLoginFeed() { } if ("Notification" in window && Notification.permission === "granted") { - for (let nx in notifications.filter(a => (a.created_at * 1000) > readNotifications)) { - //let n = new Notification(`New reply!`, { body: nx.content, icon: Nostrich }); - //console.log(n); + for (let nx of notifications.filter(a => (a.created_at * 1000) > readNotifications)) { + if (Notification.permission === "granted") { + let body = nx.content.substring(0, 50); + let title = "Snort" + navigator.serviceWorker.ready.then(worker => { + worker.showNotification(title, { + body: body, + icon: Nostrich, + tag: "notification", + }); + + }) + } } } dispatch(addNotifications(notifications)); diff --git a/src/pages/Layout.tsx b/src/pages/Layout.tsx index a3460d03..34c1d457 100644 --- a/src/pages/Layout.tsx +++ b/src/pages/Layout.tsx @@ -51,15 +51,6 @@ export default function Layout() { let res = await Notification.requestPermission(); console.debug(res); } - if (Notification.permission === "granted") { - let worker = await navigator.serviceWorker.ready; - worker.showNotification("Vibration Sample", { - body: "Buzz! Buzz!", - icon: "../images/touch/chrome-touch-icon-192x192.png", - vibrate: [200, 100, 200, 100, 200, 100, 200], - tag: "vibration-sample", - }); - } } catch (e) { console.error(e); } diff --git a/src/state/Login.ts b/src/state/Login.ts index c06ad0b5..ef286e0d 100644 --- a/src/state/Login.ts +++ b/src/state/Login.ts @@ -68,7 +68,7 @@ const InitState = { latestRelays: 0, follows: [], notifications: [], - readNotifications: 0, + readNotifications: new Date().getTime(), dms: [], dmInteraction: 0 } as LoginStore;