add fetch events when follow user
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user