chore: add some small improvements

This commit is contained in:
2024-09-30 04:49:17 +07:00
parent f0fc89724d
commit 09db39fce1
6 changed files with 53 additions and 49 deletions

View File

@@ -324,6 +324,8 @@ pub async fn login(
.await .await
.unwrap(); .unwrap();
state.contact_list.lock().await.clone_from(&contact_list);
// Get user's contact list // Get user's contact list
if !contact_list.is_empty() { if !contact_list.is_empty() {
let authors: Vec<PublicKey> = contact_list.iter().map(|f| f.public_key).collect(); let authors: Vec<PublicKey> = contact_list.iter().map(|f| f.public_key).collect();

View File

@@ -154,19 +154,13 @@ pub async fn set_profile(profile: Profile, state: State<'_, Nostr>) -> Result<St
#[tauri::command] #[tauri::command]
#[specta::specta] #[specta::specta]
pub async fn check_contact(hex: String, state: State<'_, Nostr>) -> Result<bool, String> { pub async fn check_contact(id: String, state: State<'_, Nostr>) -> Result<bool, String> {
let client = &state.client; let contact_list = &state.contact_list.lock().await;
let contact_list = client let public_key = PublicKey::from_str(&id).map_err(|e| e.to_string())?;
.get_contact_list(Some(Duration::from_secs(5)))
.await
.map_err(|e| e.to_string())?;
match PublicKey::parse(&hex) { match contact_list.iter().position(|x| x.public_key == public_key) {
Ok(public_key) => match contact_list.iter().position(|x| x.public_key == public_key) { Some(_) => Ok(true),
Some(_) => Ok(true), None => Ok(false),
None => Ok(false),
},
Err(e) => Err(e.to_string()),
} }
} }

View File

@@ -31,6 +31,7 @@ pub mod common;
pub struct Nostr { pub struct Nostr {
client: Client, client: Client,
settings: Mutex<Settings>, settings: Mutex<Settings>,
contact_list: Mutex<Vec<Contact>>,
circles: Mutex<HashMap<PublicKey, Vec<PublicKey>>>, circles: Mutex<HashMap<PublicKey, Vec<PublicKey>>>,
} }
@@ -277,6 +278,7 @@ fn main() {
app.manage(Nostr { app.manage(Nostr {
client, client,
settings: Mutex::new(Settings::default()), settings: Mutex::new(Settings::default()),
contact_list: Mutex::new(Vec::new()),
circles: Mutex::new(HashMap::new()), circles: Mutex::new(HashMap::new()),
}); });

View File

@@ -139,9 +139,9 @@ async setContactList(publicKeys: string[]) : Promise<Result<boolean, string>> {
else return { status: "error", error: e as any }; else return { status: "error", error: e as any };
} }
}, },
async checkContact(hex: string) : Promise<Result<boolean, string>> { async checkContact(id: string) : Promise<Result<boolean, string>> {
try { try {
return { status: "ok", data: await TAURI_INVOKE("check_contact", { hex }) }; return { status: "ok", data: await TAURI_INVOKE("check_contact", { id }) };
} catch (e) { } catch (e) {
if(e instanceof Error) throw e; if(e instanceof Error) throw e;
else return { status: "error", error: e as any }; else return { status: "error", error: e as any };

View File

@@ -87,7 +87,7 @@ export const Column = memo(function Column({ column }: { column: LumeColumn }) {
return ( return (
<div className="h-full w-[440px] shrink-0 p-2"> <div className="h-full w-[440px] shrink-0 p-2">
<div className="flex flex-col w-full h-full rounded-xl bg-black/5 dark:bg-white/15"> <div className="flex flex-col w-full h-full rounded-xl bg-black/5 dark:bg-white/20">
<Header label={column.label} name={column.name} /> <Header label={column.label} name={column.name} />
<div ref={container} className="flex-1 w-full h-full"> <div ref={container} className="flex-1 w-full h-full">
{!isCreated ? ( {!isCreated ? (

View File

@@ -1,7 +1,7 @@
import { commands } from "@/commands.gen"; import { commands } from "@/commands.gen";
import { decodeZapInvoice, formatCreatedAt } from "@/commons"; import { decodeZapInvoice, formatCreatedAt } from "@/commons";
import { Note, Spinner, User } from "@/components"; import { Note, Spinner, User } from "@/components";
import { LumeEvent, useEvent } from "@/system"; import { LumeEvent, LumeWindow, useEvent } from "@/system";
import { Kind, type NostrEvent } from "@/types"; import { Kind, type NostrEvent } from "@/types";
import { Info, Repeat } from "@phosphor-icons/react"; import { Info, Repeat } from "@phosphor-icons/react";
import * as ScrollArea from "@radix-ui/react-scroll-area"; import * as ScrollArea from "@radix-ui/react-scroll-area";
@@ -264,40 +264,46 @@ function TextNote({ event }: { event: LumeEvent }) {
.slice(0, 3); .slice(0, 3);
return ( return (
<Note.Provider event={event}> <button
<Note.Root className="flex flex-col p-3 mb-3 bg-white dark:bg-black/20 rounded-xl shadow-primary dark:ring-1 dark:ring-white/5"> type="button"
<User.Provider pubkey={event.pubkey}> onClick={() => LumeWindow.openEvent(event)}
<User.Root className="inline-flex items-center gap-2"> className="w-full rounded-xl hover:ring-1 ring-blue-500 mb-3"
<User.Avatar className="rounded-full size-9" /> >
<div className="flex flex-col flex-1"> <Note.Provider event={event}>
<div className="flex items-baseline justify-between w-full"> <Note.Root className="flex flex-col p-3 rounded-xl bg-white dark:bg-black/20 shadow-primary dark:ring-1 dark:ring-white/5">
<User.Name className="text-sm font-semibold leading-tight" /> <User.Provider pubkey={event.pubkey}>
<span className="text-sm leading-tight text-black/50 dark:text-white/50"> <User.Root className="inline-flex items-center gap-2">
{formatCreatedAt(event.created_at)} <User.Avatar className="rounded-full size-9" />
</span> <div className="flex flex-col flex-1">
</div> <div className="flex items-baseline justify-between w-full">
<div className="inline-flex items-baseline gap-1 text-xs"> <User.Name className="text-sm font-semibold leading-tight" />
<span className="leading-tight text-black/50 dark:text-white/50"> <span className="text-sm leading-tight text-black/50 dark:text-white/50">
Reply to: {formatCreatedAt(event.created_at)}
</span> </span>
<div className="inline-flex items-baseline gap-1"> </div>
{[...new Set(pTags)].map((replyTo) => ( <div className="inline-flex items-baseline gap-1 text-xs">
<User.Provider key={replyTo} pubkey={replyTo}> <span className="leading-tight text-black/50 dark:text-white/50">
<User.Root> Reply to:
<User.Name className="font-medium leading-tight" /> </span>
</User.Root> <div className="inline-flex items-baseline gap-1">
</User.Provider> {[...new Set(pTags)].map((replyTo) => (
))} <User.Provider key={replyTo} pubkey={replyTo}>
<User.Root>
<User.Name className="font-medium leading-tight" />
</User.Root>
</User.Provider>
))}
</div>
</div> </div>
</div> </div>
</div> </User.Root>
</User.Root> </User.Provider>
</User.Provider> <div className="flex gap-2">
<div className="flex gap-2"> <div className="w-9 shrink-0" />
<div className="w-9 shrink-0" /> <div className="line-clamp-1 text-start">{event.content}</div>
<div className="line-clamp-1 text-start">{event.content}</div> </div>
</div> </Note.Root>
</Note.Root> </Note.Provider>
</Note.Provider> </button>
); );
} }