diff --git a/src/app/chat/components/modal.tsx b/src/app/chat/components/modal.tsx index 6b3c1416..f671e13e 100644 --- a/src/app/chat/components/modal.tsx +++ b/src/app/chat/components/modal.tsx @@ -64,7 +64,7 @@ export function NewMessageModal() { >
-
+
-
+
-
+
-
- - 24 hours ago - - +
+
+ + Notification + + +
+ + All things happen when you rest in 48 hours ago +
@@ -139,6 +144,13 @@ export function NotificationModal({ pubkey }: { pubkey: string }) {
+ ) : data.length < 1 ? ( +
+

🎉

+

+ Yo!, you've no new notifications +

+
) : ( data.map((event) => renderItem(event)) )} diff --git a/src/utils/hooks/useSocial.tsx b/src/utils/hooks/useSocial.tsx index f22db0fe..ab4930a3 100644 --- a/src/utils/hooks/useSocial.tsx +++ b/src/utils/hooks/useSocial.tsx @@ -1,7 +1,10 @@ import { useAccount } from "./useAccount"; import { usePublish } from "@libs/ndk"; +import { createNote } from "@libs/storage"; +import { NDKEvent, NDKFilter } from "@nostr-dev-kit/ndk"; import { RelayContext } from "@shared/relayProvider"; import { useQuery, useQueryClient } from "@tanstack/react-query"; +import { dateToUnix, getHourAgo } from "@utils/date"; import { nip02ToArray } from "@utils/transform"; import { useContext } from "react"; @@ -47,7 +50,7 @@ export function useSocial() { }); }; - const follow = (pubkey: string) => { + const follow = async (pubkey: string) => { const followsAsSet = new Set(userFollows); followsAsSet.add(pubkey); @@ -62,6 +65,24 @@ export function useSocial() { queryClient.invalidateQueries({ queryKey: ["userFollows", account.pubkey], }); + + // fetch events + const filter: NDKFilter = { + authors: [pubkey], + kinds: [1, 6], + since: dateToUnix(getHourAgo(48, new Date())), + }; + const events = await ndk.fetchEvents(filter); + events.forEach((event: NDKEvent) => { + createNote( + event.id, + event.pubkey, + event.kind, + event.tags, + event.content, + event.created_at, + ); + }); }; return { status, userFollows, follow, unfollow };