This commit is contained in:
Ren Amamiya
2023-08-09 13:17:07 +07:00
parent d1d0a462f4
commit edf56bc97b
7 changed files with 27 additions and 26 deletions

View File

@@ -18,22 +18,25 @@ import { nHoursAgo } from '@utils/date';
export function useNostr() {
const { ndk, relayUrls, fetcher } = useNDK();
async function fetchNetwork() {
async function fetchNetwork(prevFollow?: string[]) {
const account = await getActiveAccount();
const follows = new Set<string>();
const follows = new Set<string>(prevFollow || []);
const lruNetwork = new LRUCache<string, string, void>({ max: 300 });
let network: string[];
// fetch user's follows
const user = ndk.getUser({ hexpubkey: account.pubkey });
const list = await user.follows();
list.forEach((item: NDKUser) => {
follows.add(nip19.decode(item.npub).data as string);
});
if (!prevFollow) {
const user = ndk.getUser({ hexpubkey: account.pubkey });
const list = await user.follows();
list.forEach((item: NDKUser) => {
follows.add(nip19.decode(item.npub).data as string);
});
}
// fetch network
if (!account.network) {
console.log('fetching network...', follows.size);
const events = await fetcher.fetchAllEvents(
relayUrls,
{ kinds: [3], authors: [...follows] },
@@ -59,9 +62,9 @@ export function useNostr() {
return [...new Set([...follows, ...network])];
}
const fetchNotes = async () => {
const fetchNotes = async (prevFollow?: string[]) => {
try {
const network = (await fetchNetwork()) as string[];
const network = (await fetchNetwork(prevFollow)) as string[];
const totalNotes = await countTotalNotes();
const lastLogin = await getLastLogin();

View File

@@ -20,8 +20,8 @@ export interface Account extends NDKUserProfile {
id: number;
npub: string;
pubkey: string;
follows: string[];
network: string[];
follows: null | string[];
network: null | string[];
is_active: number;
privkey?: string; // deprecated
}