Send notifications

This commit is contained in:
Kieran 2023-01-19 12:09:34 +00:00
parent 1d56c47322
commit ebd66d6c1a
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
3 changed files with 15 additions and 13 deletions

View File

@ -1,3 +1,4 @@
import Nostrich from "./nostrich.jpg";
import { useEffect, useMemo } from "react"; import { useEffect, useMemo } from "react";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { HexKey } from "../nostr"; import { HexKey } from "../nostr";
@ -61,9 +62,19 @@ export default function useLoginFeed() {
} }
if ("Notification" in window && Notification.permission === "granted") { if ("Notification" in window && Notification.permission === "granted") {
for (let nx in notifications.filter(a => (a.created_at * 1000) > readNotifications)) { for (let nx of notifications.filter(a => (a.created_at * 1000) > readNotifications)) {
//let n = new Notification(`New reply!`, { body: nx.content, icon: Nostrich }); if (Notification.permission === "granted") {
//console.log(n); 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)); dispatch(addNotifications(notifications));

View File

@ -51,15 +51,6 @@ export default function Layout() {
let res = await Notification.requestPermission(); let res = await Notification.requestPermission();
console.debug(res); 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) { } catch (e) {
console.error(e); console.error(e);
} }

View File

@ -68,7 +68,7 @@ const InitState = {
latestRelays: 0, latestRelays: 0,
follows: [], follows: [],
notifications: [], notifications: [],
readNotifications: 0, readNotifications: new Date().getTime(),
dms: [], dms: [],
dmInteraction: 0 dmInteraction: 0
} as LoginStore; } as LoginStore;