diff --git a/src/Feed/LoginFeed.ts b/src/Feed/LoginFeed.ts index 027c47a6..89c76356 100644 --- a/src/Feed/LoginFeed.ts +++ b/src/Feed/LoginFeed.ts @@ -6,7 +6,7 @@ import { TaggedRawEvent, HexKey, Lists } from "Nostr"; import EventKind from "Nostr/EventKind"; import Event from "Nostr/Event"; import { Subscriptions } from "Nostr/Subscriptions"; -import { addDirectMessage, setFollows, setRelays, setMuted, setBlocked, sendNotification } from "State/Login"; +import { addDirectMessage, setFollows, setRelays, setMuted, setBlocked, sendNotification, setLatestNotifications } from "State/Login"; import { RootState } from "State/Store"; import { mapEventToProfile, MetadataCache } from "State/Users"; import { useDb } from "State/Users/Db"; @@ -20,7 +20,7 @@ import useModeration from "Hooks/useModeration"; */ export default function useLoginFeed() { const dispatch = useDispatch(); - const { publicKey: pubKey, privateKey: privKey, latestMuted } = useSelector((s: RootState) => s.login); + const { publicKey: pubKey, privateKey: privKey, latestMuted, readNotifications } = useSelector((s: RootState) => s.login); const { isMuted } = useModeration(); const db = useDb(); @@ -116,8 +116,10 @@ export default function useLoginFeed() { }, [dispatch, metadataFeed.store, db]); useEffect(() => { - const replies = notificationFeed.store.notes.filter(a => a.kind === EventKind.TextNote && !isMuted(a.pubkey)) + const replies = notificationFeed.store.notes. + filter(a => a.kind === EventKind.TextNote && !isMuted(a.pubkey) && a.created_at > readNotifications) replies.forEach(nx => { + dispatch(setLatestNotifications(nx.created_at)); makeNotification(db, nx).then(notification => { if (notification) { // @ts-ignore @@ -125,7 +127,7 @@ export default function useLoginFeed() { } }) }) - }, [dispatch, notificationFeed.store, db]); + }, [dispatch, notificationFeed.store, db, readNotifications]); useEffect(() => { const muted = getMutedKeys(mutedFeed.store.notes) diff --git a/src/Pages/Layout.tsx b/src/Pages/Layout.tsx index da6c410a..b3bb28c0 100644 --- a/src/Pages/Layout.tsx +++ b/src/Pages/Layout.tsx @@ -27,9 +27,9 @@ export default function Layout() { const [show, setShow] = useState(false) const dispatch = useDispatch(); const navigate = useNavigate(); - const { loggedOut, publicKey, relays, notifications, readNotifications, dms, preferences, newUserKey } = useSelector((s: RootState) => s.login); + const { loggedOut, publicKey, relays, latestNotification, readNotifications, dms, preferences, newUserKey } = useSelector((s: RootState) => s.login); const { isMuted } = useModeration(); - const filteredDms = dms.filter(a => !isMuted(a.pubkey)) + const usingDb = useDb(); const pub = useEventPublisher(); useLoginFeed(); @@ -39,6 +39,9 @@ export default function Layout() { return hideNoteCreator.some(a => location.pathname.startsWith(a)); }, [location]); + const hasNotifications = useMemo(() => latestNotification > readNotifications, [latestNotification, readNotifications]); + const unreadDms = useMemo(() => publicKey ? totalUnread(dms.filter(a => !isMuted(a.pubkey)), publicKey) : 0, [dms, publicKey]); + useEffect(() => { System.nip42Auth = pub.nip42Auth }, [pub]) @@ -153,8 +156,6 @@ export default function Layout() { } function accountHeader() { - const unreadNotifications = notifications?.filter(a => (a.created_at * 1000) > readNotifications).length; - const unreadDms = publicKey ? totalUnread(filteredDms, publicKey) : 0; return (