fix some errors cause app crash
This commit is contained in:
@@ -63,7 +63,12 @@ export function useNostr() {
|
||||
}
|
||||
|
||||
// build user's network
|
||||
const events = await ndk.fetchEvents({ kinds: [3], authors: [...follows] });
|
||||
const events = await ndk.fetchEvents({
|
||||
kinds: [3],
|
||||
authors: [...follows],
|
||||
limit: 300,
|
||||
});
|
||||
|
||||
events.forEach((event: NDKEvent) => {
|
||||
event.tags.forEach((tag) => {
|
||||
if (tag[0] === 'p') lruNetwork.set(tag[1], tag[1]);
|
||||
@@ -88,12 +93,11 @@ export function useNostr() {
|
||||
try {
|
||||
if (!ndk) return { status: 'failed', data: [], message: 'NDK instance not found' };
|
||||
|
||||
// setup nostr-fetch
|
||||
const fetcher = NostrFetcher.withCustomPool(ndkAdapter(ndk));
|
||||
const dbEventsEmpty = await db.isEventsEmpty();
|
||||
|
||||
let since: number;
|
||||
if (dbEventsEmpty) {
|
||||
if (dbEventsEmpty || db.account.last_login_at === 0) {
|
||||
since = nHoursAgo(24);
|
||||
} else {
|
||||
since = db.account.last_login_at ?? nHoursAgo(24);
|
||||
@@ -125,6 +129,7 @@ export function useNostr() {
|
||||
event.id,
|
||||
JSON.stringify(event),
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
root,
|
||||
reply,
|
||||
event.created_at
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { NDKUserProfile } from '@nostr-dev-kit/ndk';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useNDK } from '@libs/ndk/provider';
|
||||
|
||||
export function useProfile(pubkey: string, fallback?: string) {
|
||||
export function useProfile(pubkey: string, embed?: string) {
|
||||
const { ndk } = useNDK();
|
||||
const {
|
||||
status,
|
||||
data: user,
|
||||
error,
|
||||
isFetching,
|
||||
} = useQuery(
|
||||
['user', pubkey],
|
||||
async () => {
|
||||
if (!fallback) {
|
||||
const user = ndk.getUser({ hexpubkey: pubkey });
|
||||
if (!embed) {
|
||||
const cleanPubkey = pubkey.replace('-', '');
|
||||
const user = ndk.getUser({ hexpubkey: cleanPubkey });
|
||||
await user.fetchProfile();
|
||||
if (user.profile) {
|
||||
user.profile.display_name = user.profile.displayName;
|
||||
@@ -22,7 +23,7 @@ export function useProfile(pubkey: string, fallback?: string) {
|
||||
throw new Error('User not found');
|
||||
}
|
||||
} else {
|
||||
const profile = JSON.parse(fallback);
|
||||
const profile: NDKUserProfile = JSON.parse(embed);
|
||||
return profile;
|
||||
}
|
||||
},
|
||||
@@ -35,5 +36,5 @@ export function useProfile(pubkey: string, fallback?: string) {
|
||||
}
|
||||
);
|
||||
|
||||
return { status, user, error, isFetching };
|
||||
return { status, user, error };
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ export function useImageUploader() {
|
||||
if (res.ok) {
|
||||
const url =
|
||||
res.file?.metadata?.url ?? `https://void.cat/d/${res.file?.id}.${filetype}`;
|
||||
console.log(url);
|
||||
|
||||
if (nip94) {
|
||||
const tags = [
|
||||
|
||||
@@ -18,6 +18,24 @@ export function parser(event: NDKEvent) {
|
||||
links: [],
|
||||
};
|
||||
|
||||
// parse nostr references
|
||||
references?.forEach((item) => {
|
||||
const profile = item.profile;
|
||||
const event = item.event;
|
||||
const addr = item.address;
|
||||
if (event) {
|
||||
content.notes.push(event.id);
|
||||
content.parsed = content.parsed.replace(item.text, '');
|
||||
}
|
||||
if (profile) {
|
||||
content.parsed = content.parsed.replace(item.text, `~pub-${item.profile.pubkey}~`);
|
||||
}
|
||||
if (addr) {
|
||||
content.notes.push(addr.identifier);
|
||||
content.parsed = content.parsed.replace(item.text, '');
|
||||
}
|
||||
});
|
||||
|
||||
// parse urls
|
||||
urls?.forEach((url: string) => {
|
||||
if (url.match(/\.(jpg|jpeg|gif|png|webp|avif)$/)) {
|
||||
@@ -47,25 +65,7 @@ export function parser(event: NDKEvent) {
|
||||
// parse hashtag
|
||||
const hashtags = content.parsed.split(/\s/gm).filter((s) => s.startsWith('#'));
|
||||
hashtags?.forEach((tag) => {
|
||||
content.parsed = content.parsed.replace(tag, `~tag${tag}~`);
|
||||
});
|
||||
|
||||
// parse nostr
|
||||
references?.forEach((item) => {
|
||||
const profile = item.profile;
|
||||
const event = item.event;
|
||||
const addr = item.address;
|
||||
if (event) {
|
||||
content.notes.push(event.id);
|
||||
content.parsed = content.parsed.replace(item.text, '');
|
||||
}
|
||||
if (profile) {
|
||||
content.parsed = content.parsed.replace(item.text, `~pub${item.profile.pubkey}~`);
|
||||
}
|
||||
if (addr) {
|
||||
content.notes.push(addr.identifier);
|
||||
content.parsed = content.parsed.replace(item.text, '');
|
||||
}
|
||||
content.parsed = content.parsed.replace(tag, ` ~tag-${tag}~ `);
|
||||
});
|
||||
|
||||
return content;
|
||||
|
||||
1
src/utils/types.d.ts
vendored
1
src/utils/types.d.ts
vendored
@@ -13,6 +13,7 @@ export interface DBEvent {
|
||||
account_id: number;
|
||||
event: string | NDKEvent;
|
||||
author: string;
|
||||
kind: number;
|
||||
root_id: string;
|
||||
reply_id: string;
|
||||
created_at: number;
|
||||
|
||||
Reference in New Issue
Block a user