This commit is contained in:
Ren Amamiya
2023-08-12 11:18:10 +07:00
parent 36b2acba6a
commit bb089bb259
27 changed files with 502 additions and 481 deletions

View File

@@ -5,25 +5,26 @@ import { createNote } from '@libs/storage';
import { nHoursAgo } from '@utils/date';
import { useAccount } from '@utils/hooks/useAccount';
import { nip02ToArray } from '@utils/transform';
import { useNostr } from './useNostr';
import { useNostr } from '@utils/hooks/useNostr';
export function useSocial() {
const queryClient = useQueryClient();
const { publish } = useNostr();
const { fetcher, relayUrls } = useNDK();
const { ndk } = useNDK();
const { account } = useAccount();
const { status, data: userFollows } = useQuery(
['userFollows', account.pubkey],
async () => {
const res = await fetcher.fetchLastEvent(relayUrls, {
kinds: [3],
authors: [account.pubkey],
const keys = [];
const user = ndk.getUser({ hexpubkey: account.pubkey });
const follows = await user.follows();
follows.forEach((item) => {
keys.push(item.hexpubkey);
});
const list = nip02ToArray(res.tags);
return list;
return keys;
},
{
enabled: account ? true : false,
@@ -67,11 +68,11 @@ export function useSocial() {
});
// fetch events
const events = await fetcher.fetchAllEvents(
relayUrls,
{ authors: [pubkey], kinds: [1, 6] },
{ since: nHoursAgo(48) }
);
const events = await ndk.fetchEvents({
authors: [pubkey],
kinds: [1, 6],
since: nHoursAgo(24),
});
for (const event of events) {
await createNote(