Send notifications
This commit is contained in:
parent
1d56c47322
commit
ebd66d6c1a
@ -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));
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user