diff --git a/src-tauri/src/commands/metadata.rs b/src-tauri/src/commands/metadata.rs index 3ce5773f..4c2df820 100644 --- a/src-tauri/src/commands/metadata.rs +++ b/src-tauri/src/commands/metadata.rs @@ -32,10 +32,24 @@ pub struct Mention { #[tauri::command] #[specta::specta] -pub async fn get_profile(id: String, state: State<'_, Nostr>) -> Result { +pub async fn get_profile( + id: String, + cache_only: bool, + state: State<'_, Nostr>, +) -> Result { let client = &state.client; let public_key = PublicKey::parse(&id).map_err(|e| e.to_string())?; + if cache_only { + let profile = client + .database() + .profile(public_key) + .await + .map_err(|e| e.to_string())?; + + return Ok(profile.metadata().as_json()); + }; + let metadata = client .fetch_metadata(public_key, Some(Duration::from_secs(3))) .await diff --git a/src/commands.gen.ts b/src/commands.gen.ts index 5da3edda..a6aad974 100644 --- a/src/commands.gen.ts +++ b/src/commands.gen.ts @@ -128,9 +128,9 @@ async setSigner(id: string) : Promise> { else return { status: "error", error: e as any }; } }, -async getProfile(id: string) : Promise> { +async getProfile(id: string, cacheOnly: boolean) : Promise> { try { - return { status: "ok", data: await TAURI_INVOKE("get_profile", { id }) }; + return { status: "ok", data: await TAURI_INVOKE("get_profile", { id, cacheOnly }) }; } catch (e) { if(e instanceof Error) throw e; else return { status: "error", error: e as any }; diff --git a/src/components/note/buttons/repost.tsx b/src/components/note/buttons/repost.tsx index bf6215fb..192e8e87 100644 --- a/src/components/note/buttons/repost.tsx +++ b/src/components/note/buttons/repost.tsx @@ -45,12 +45,12 @@ export function NoteRepost({ const list: Promise[] = []; for (const account of accounts) { - const res = await commands.getProfile(account); + const res = await commands.getProfile(account, true); let name = "unknown"; if (res.status === "ok") { const profile: Metadata = JSON.parse(res.data); - name = profile.display_name ?? profile.name ?? "unknown"; + name = profile.display_name ?? profile.name ?? "anon"; } list.push( diff --git a/src/routes/_app/index.lazy.tsx b/src/routes/_app/index.lazy.tsx index 442ea43d..983e7285 100644 --- a/src/routes/_app/index.lazy.tsx +++ b/src/routes/_app/index.lazy.tsx @@ -199,12 +199,12 @@ function OpenLaunchpad() { const list: Promise[] = []; for (const account of accounts) { - const res = await commands.getProfile(account); + const res = await commands.getProfile(account, true); let name = "unknown"; if (res.status === "ok") { const profile: Metadata = JSON.parse(res.data); - name = profile.display_name ?? profile.name ?? "unknown"; + name = profile.display_name ?? profile.name ?? "anon"; } list.push( diff --git a/src/routes/new-post/index.lazy.tsx b/src/routes/new-post/index.lazy.tsx index 3c15fa7b..4116c3d8 100644 --- a/src/routes/new-post/index.lazy.tsx +++ b/src/routes/new-post/index.lazy.tsx @@ -104,12 +104,12 @@ function Screen() { const list: Promise[] = []; for (const account of accounts) { - const res = await commands.getProfile(account); + const res = await commands.getProfile(account, true); let name = "unknown"; if (res.status === "ok") { const profile: Metadata = JSON.parse(res.data); - name = profile.display_name ?? profile.name ?? "unknown"; + name = profile.display_name ?? profile.name ?? "anon"; } list.push( diff --git a/src/routes/settings.$id/profile.tsx b/src/routes/settings.$id/profile.tsx index 640ca1cd..da2d6f29 100644 --- a/src/routes/settings.$id/profile.tsx +++ b/src/routes/settings.$id/profile.tsx @@ -3,7 +3,7 @@ import { createFileRoute } from "@tanstack/react-router"; export const Route = createFileRoute("/settings/$id/profile")({ beforeLoad: async ({ params }) => { - const res = await commands.getProfile(params.id); + const res = await commands.getProfile(params.id, true); if (res.status === "ok") { const profile: Profile = JSON.parse(res.data); diff --git a/src/routes/zap.$id.lazy.tsx b/src/routes/zap.$id.lazy.tsx index a2edf49a..71f5b7c9 100644 --- a/src/routes/zap.$id.lazy.tsx +++ b/src/routes/zap.$id.lazy.tsx @@ -31,12 +31,12 @@ function Screen() { const list: Promise[] = []; for (const account of accounts) { - const res = await commands.getProfile(account); + const res = await commands.getProfile(account, true); let name = "unknown"; if (res.status === "ok") { const profile: Metadata = JSON.parse(res.data); - name = profile.display_name ?? profile.name ?? "unknown"; + name = profile.display_name ?? profile.name ?? "anon"; } list.push( diff --git a/src/system/useProfile.ts b/src/system/useProfile.ts index ff95b79e..eaf9ff1d 100644 --- a/src/system/useProfile.ts +++ b/src/system/useProfile.ts @@ -26,7 +26,7 @@ export function useProfile(pubkey: string, embed?: string) { } } - const query = await commands.getProfile(normalizedId); + const query = await commands.getProfile(normalizedId, false); if (query.status === "ok") { return JSON.parse(query.data) as Metadata;