diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 45828d1f..406c996a 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3481,7 +3481,7 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" [[package]] name = "nostr" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr#0ffae5b49f14d88d704fdd804969302533b5c576" +source = "git+https://github.com/rust-nostr/nostr#7587fba8ee72041689aa46c1436ecfa73d75d381" dependencies = [ "aes", "async-trait", @@ -3512,7 +3512,7 @@ dependencies = [ [[package]] name = "nostr-connect" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr#0ffae5b49f14d88d704fdd804969302533b5c576" +source = "git+https://github.com/rust-nostr/nostr#7587fba8ee72041689aa46c1436ecfa73d75d381" dependencies = [ "async-trait", "async-utility", @@ -3526,7 +3526,7 @@ dependencies = [ [[package]] name = "nostr-database" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr#0ffae5b49f14d88d704fdd804969302533b5c576" +source = "git+https://github.com/rust-nostr/nostr#7587fba8ee72041689aa46c1436ecfa73d75d381" dependencies = [ "async-trait", "flatbuffers", @@ -3540,7 +3540,7 @@ dependencies = [ [[package]] name = "nostr-lmdb" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr#0ffae5b49f14d88d704fdd804969302533b5c576" +source = "git+https://github.com/rust-nostr/nostr#7587fba8ee72041689aa46c1436ecfa73d75d381" dependencies = [ "heed", "nostr", @@ -3553,7 +3553,7 @@ dependencies = [ [[package]] name = "nostr-relay-pool" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr#0ffae5b49f14d88d704fdd804969302533b5c576" +source = "git+https://github.com/rust-nostr/nostr#7587fba8ee72041689aa46c1436ecfa73d75d381" dependencies = [ "async-utility", "async-wsocket", @@ -3571,7 +3571,7 @@ dependencies = [ [[package]] name = "nostr-sdk" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr#0ffae5b49f14d88d704fdd804969302533b5c576" +source = "git+https://github.com/rust-nostr/nostr#7587fba8ee72041689aa46c1436ecfa73d75d381" dependencies = [ "async-utility", "atomic-destructor", @@ -3590,7 +3590,7 @@ dependencies = [ [[package]] name = "nostr-zapper" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr#0ffae5b49f14d88d704fdd804969302533b5c576" +source = "git+https://github.com/rust-nostr/nostr#7587fba8ee72041689aa46c1436ecfa73d75d381" dependencies = [ "async-trait", "nostr", @@ -3734,7 +3734,7 @@ dependencies = [ [[package]] name = "nwc" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr#0ffae5b49f14d88d704fdd804969302533b5c576" +source = "git+https://github.com/rust-nostr/nostr#7587fba8ee72041689aa46c1436ecfa73d75d381" dependencies = [ "async-trait", "async-utility", diff --git a/src-tauri/src/commands/event.rs b/src-tauri/src/commands/event.rs index d69180b6..03a2872f 100644 --- a/src-tauri/src/commands/event.rs +++ b/src-tauri/src/commands/event.rs @@ -35,29 +35,29 @@ pub async fn get_event(id: String, state: State<'_, Nostr>) -> Result, - state: State<'_, Nostr>, -) -> Result { +pub async fn reply(content: String, to: String, state: State<'_, Nostr>) -> Result { let client = &state.client; // Create event tags from content @@ -349,6 +344,7 @@ pub async fn reply( // Get reply event let reply_id = EventId::parse(&to).map_err(|err| err.to_string())?; + let reply_to = match client.database().event_by_id(&reply_id).await { Ok(event) => { if let Some(event) = event { @@ -360,12 +356,35 @@ pub async fn reply( Err(e) => return Err(e.to_string()), }; + // Detect root event from reply + let root_ids: Vec<&EventId> = reply_to + .tags + .filter_standardized(TagKind::e()) + .filter_map(|t| match t { + TagStandard::Event { + event_id, marker, .. + } => { + if let Some(mkr) = marker { + match mkr { + Marker::Root => Some(event_id), + Marker::Reply => Some(event_id), + _ => None, + } + } else { + Some(event_id) + } + } + _ => None, + }) + .collect(); + // Get root event if exist - let root = match root { - Some(id) => { - let root_id = EventId::parse(&id).map_err(|err| err.to_string())?; - (client.database().event_by_id(&root_id).await).unwrap_or_default() - } + let root = match root_ids.first() { + Some(&id) => client + .database() + .event_by_id(id) + .await + .map_err(|err| err.to_string())?, None => None, }; diff --git a/src-tauri/src/commands/window.rs b/src-tauri/src/commands/window.rs index 97177013..c034a162 100644 --- a/src-tauri/src/commands/window.rs +++ b/src-tauri/src/commands/window.rs @@ -3,7 +3,7 @@ use border::WebviewWindowExt as BorderWebviewWindowExt; use nostr_sdk::prelude::*; use serde::{Deserialize, Serialize}; use specta::Type; -use std::{path::PathBuf, str::FromStr}; +use std::path::PathBuf; #[cfg(target_os = "macos")] use tauri::TitleBarStyle; use tauri::{ @@ -68,7 +68,7 @@ pub async fn create_column( .on_page_load(|webview, payload| match payload.event() { PageLoadEvent::Started => { if let Ok(id) = get_last_segment(payload.url()) { - if let Ok(public_key) = PublicKey::from_str(&id) { + if let Ok(public_key) = PublicKey::parse(&id) { let is_newsfeed = payload.url().to_string().contains("newsfeed"); tauri::async_runtime::spawn(async move { @@ -104,7 +104,7 @@ pub async fn create_column( } } }); - } else if let Ok(event_id) = EventId::from_str(&id) { + } else if let Ok(event_id) = EventId::parse(&id) { tauri::async_runtime::spawn(async move { let state = webview.state::(); let client = &state.client; @@ -117,11 +117,7 @@ pub async fn create_column( .since(Timestamp::now()); if let Err(e) = client - .subscribe_with_id( - subscription_id, - vec![filter.clone().since(Timestamp::now())], - None, - ) + .subscribe_with_id(subscription_id, vec![filter], None) .await { println!("Subscription error: {}", e); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 59e346f3..e9187331 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -457,7 +457,7 @@ fn main() { if let Err(e) = handle_clone.emit("metadata", event.as_json()) { println!("Emit error: {}", e) } - } else if event.kind != Kind::RelayList { + } else if event.kind == Kind::TextNote { let payload = RichEvent { raw: event.as_json(), parsed: if event.kind == Kind::TextNote { diff --git a/src/commands.gen.ts b/src/commands.gen.ts index fdb2ac32..ad529397 100644 --- a/src/commands.gen.ts +++ b/src/commands.gen.ts @@ -400,9 +400,9 @@ async publish(content: string, warning: string | null, difficulty: number | null else return { status: "error", error: e as any }; } }, -async reply(content: string, to: string, root: string | null) : Promise> { +async reply(content: string, to: string) : Promise> { try { - return { status: "ok", data: await TAURI_INVOKE("reply", { content, to, root }) }; + return { status: "ok", data: await TAURI_INVOKE("reply", { content, to }) }; } catch (e) { if(e instanceof Error) throw e; else return { status: "error", error: e as any }; diff --git a/src/components/note/buttons/open.tsx b/src/components/note/buttons/open.tsx index d0da9e75..5ec4cf7c 100644 --- a/src/components/note/buttons/open.tsx +++ b/src/components/note/buttons/open.tsx @@ -12,7 +12,14 @@ export function NoteOpenThread() {