From 09db39fce17356b3487472502142bd2d5656639e Mon Sep 17 00:00:00 2001 From: reya Date: Mon, 30 Sep 2024 04:49:17 +0700 Subject: [PATCH] chore: add some small improvements --- src-tauri/src/commands/account.rs | 2 + src-tauri/src/commands/metadata.rs | 18 ++--- src-tauri/src/main.rs | 2 + src/commands.gen.ts | 4 +- src/components/column.tsx | 2 +- .../columns/_layout/notification.lazy.tsx | 74 ++++++++++--------- 6 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src-tauri/src/commands/account.rs b/src-tauri/src/commands/account.rs index a058d468..57f7fd55 100644 --- a/src-tauri/src/commands/account.rs +++ b/src-tauri/src/commands/account.rs @@ -324,6 +324,8 @@ pub async fn login( .await .unwrap(); + state.contact_list.lock().await.clone_from(&contact_list); + // Get user's contact list if !contact_list.is_empty() { let authors: Vec = contact_list.iter().map(|f| f.public_key).collect(); diff --git a/src-tauri/src/commands/metadata.rs b/src-tauri/src/commands/metadata.rs index 3efb0a87..1152c826 100644 --- a/src-tauri/src/commands/metadata.rs +++ b/src-tauri/src/commands/metadata.rs @@ -154,19 +154,13 @@ pub async fn set_profile(profile: Profile, state: State<'_, Nostr>) -> Result) -> Result { - let client = &state.client; - let contact_list = client - .get_contact_list(Some(Duration::from_secs(5))) - .await - .map_err(|e| e.to_string())?; +pub async fn check_contact(id: String, state: State<'_, Nostr>) -> Result { + let contact_list = &state.contact_list.lock().await; + let public_key = PublicKey::from_str(&id).map_err(|e| e.to_string())?; - match PublicKey::parse(&hex) { - Ok(public_key) => match contact_list.iter().position(|x| x.public_key == public_key) { - Some(_) => Ok(true), - None => Ok(false), - }, - Err(e) => Err(e.to_string()), + match contact_list.iter().position(|x| x.public_key == public_key) { + Some(_) => Ok(true), + None => Ok(false), } } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 274ab5f5..9c6d8b17 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -31,6 +31,7 @@ pub mod common; pub struct Nostr { client: Client, settings: Mutex, + contact_list: Mutex>, circles: Mutex>>, } @@ -277,6 +278,7 @@ fn main() { app.manage(Nostr { client, settings: Mutex::new(Settings::default()), + contact_list: Mutex::new(Vec::new()), circles: Mutex::new(HashMap::new()), }); diff --git a/src/commands.gen.ts b/src/commands.gen.ts index 5a4a82e7..605affc6 100644 --- a/src/commands.gen.ts +++ b/src/commands.gen.ts @@ -139,9 +139,9 @@ async setContactList(publicKeys: string[]) : Promise> { else return { status: "error", error: e as any }; } }, -async checkContact(hex: string) : Promise> { +async checkContact(id: string) : Promise> { try { - return { status: "ok", data: await TAURI_INVOKE("check_contact", { hex }) }; + return { status: "ok", data: await TAURI_INVOKE("check_contact", { id }) }; } catch (e) { if(e instanceof Error) throw e; else return { status: "error", error: e as any }; diff --git a/src/components/column.tsx b/src/components/column.tsx index fc686acc..85c22c54 100644 --- a/src/components/column.tsx +++ b/src/components/column.tsx @@ -87,7 +87,7 @@ export const Column = memo(function Column({ column }: { column: LumeColumn }) { return (
-
+
{!isCreated ? ( diff --git a/src/routes/columns/_layout/notification.lazy.tsx b/src/routes/columns/_layout/notification.lazy.tsx index 329413ee..77c5cf93 100644 --- a/src/routes/columns/_layout/notification.lazy.tsx +++ b/src/routes/columns/_layout/notification.lazy.tsx @@ -1,7 +1,7 @@ import { commands } from "@/commands.gen"; import { decodeZapInvoice, formatCreatedAt } from "@/commons"; import { Note, Spinner, User } from "@/components"; -import { LumeEvent, useEvent } from "@/system"; +import { LumeEvent, LumeWindow, useEvent } from "@/system"; import { Kind, type NostrEvent } from "@/types"; import { Info, Repeat } from "@phosphor-icons/react"; import * as ScrollArea from "@radix-ui/react-scroll-area"; @@ -264,40 +264,46 @@ function TextNote({ event }: { event: LumeEvent }) { .slice(0, 3); return ( - - - - - -
-
- - - {formatCreatedAt(event.created_at)} - -
-
- - Reply to: - -
- {[...new Set(pTags)].map((replyTo) => ( - - - - - - ))} +
- - -
-
-
{event.content}
-
- - + + +
+
+
{event.content}
+
+ + + ); }