diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 637095b..7e94d8f 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2874,7 +2874,7 @@ checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" [[package]] name = "nostr" version = "0.33.0" -source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" +source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395" dependencies = [ "aes", "base64 0.21.7", @@ -2903,7 +2903,7 @@ dependencies = [ [[package]] name = "nostr-database" version = "0.33.0" -source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" +source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395" dependencies = [ "async-trait", "flatbuffers", @@ -2917,7 +2917,7 @@ dependencies = [ [[package]] name = "nostr-relay-pool" version = "0.33.0" -source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" +source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395" dependencies = [ "async-utility", "async-wsocket", @@ -2932,7 +2932,7 @@ dependencies = [ [[package]] name = "nostr-sdk" version = "0.33.0" -source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" +source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395" dependencies = [ "async-utility", "atomic-destructor", @@ -2952,7 +2952,7 @@ dependencies = [ [[package]] name = "nostr-signer" version = "0.33.0" -source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" +source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395" dependencies = [ "async-utility", "nostr", @@ -2965,7 +2965,7 @@ dependencies = [ [[package]] name = "nostr-sqlite" version = "0.33.0" -source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" +source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395" dependencies = [ "async-trait", "nostr", @@ -2979,7 +2979,7 @@ dependencies = [ [[package]] name = "nostr-zapper" version = "0.33.0" -source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" +source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395" dependencies = [ "async-trait", "nostr", @@ -3099,7 +3099,7 @@ dependencies = [ [[package]] name = "nwc" version = "0.33.0" -source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" +source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395" dependencies = [ "async-utility", "nostr", @@ -4418,9 +4418,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" dependencies = [ "serde", ] @@ -5901,9 +5901,9 @@ checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "vswhom" diff --git a/src-tauri/src/commands/account.rs b/src-tauri/src/commands/account.rs index 9f5a995..ec86ec9 100644 --- a/src-tauri/src/commands/account.rs +++ b/src-tauri/src/commands/account.rs @@ -224,18 +224,25 @@ pub async fn login( client .handle_notifications(|notification| async { - if let RelayPoolNotification::Event { event, .. } = notification { - if event.kind == Kind::GiftWrap { - if let Ok(UnwrappedGift { rumor, sender }) = - client.unwrap_gift_wrap(&event).await - { - window - .emit( - "event", - Payload { event: rumor.as_json(), sender: sender.to_hex() }, - ) - .unwrap(); + if let RelayPoolNotification::Message { message, relay_url } = notification { + if let RelayMessage::Event { event, .. } = message { + if event.kind == Kind::GiftWrap { + match client.unwrap_gift_wrap(&event).await { + Ok(UnwrappedGift { rumor, sender }) => { + let payload = + Payload { event: rumor.as_json(), sender: sender.to_hex() }; + + if window.emit("event", payload).is_err() { + println!("Failed") + } + } + Err(e) => { + println!("Unwrapped Error: {} from {}", e, relay_url) + } + } } + } else { + println!("message: {}", message.as_json()) } } Ok(false) diff --git a/src-tauri/src/commands/chat.rs b/src-tauri/src/commands/chat.rs index 8ee1499..f0bb197 100644 --- a/src-tauri/src/commands/chat.rs +++ b/src-tauri/src/commands/chat.rs @@ -46,16 +46,13 @@ pub async fn get_chats(state: State<'_, Nostr>) -> Result, String> { #[tauri::command] #[specta::specta] -pub async fn get_chat_messages( - sender: String, - state: State<'_, Nostr>, -) -> Result, String> { +pub async fn get_chat_messages(id: String, state: State<'_, Nostr>) -> Result, String> { let client = &state.client; let signer = client.signer().await.map_err(|e| e.to_string())?; let receiver_pk = signer.public_key().await.map_err(|e| e.to_string())?; - let sender_pk = PublicKey::parse(sender).map_err(|e| e.to_string())?; + let sender_pk = PublicKey::parse(id).map_err(|e| e.to_string())?; - let filter = Filter::new().kind(Kind::GiftWrap).pubkeys(vec![receiver_pk, sender_pk]); + let filter = Filter::new().kind(Kind::GiftWrap).pubkeys(vec![sender_pk, receiver_pk]); match client.get_events_of(vec![filter], None).await { Ok(events) => { @@ -63,15 +60,17 @@ pub async fn get_chat_messages( .filter_map(|ev| async move { if let Ok(UnwrappedGift { rumor, sender }) = client.unwrap_gift_wrap(&ev).await { - if rumor.kind == Kind::PrivateDirectMessage - && (sender == sender_pk || is_target(&sender_pk, &rumor.tags)) - { - return Some(rumor); + let is_target = is_target(&sender_pk, &rumor.tags); + let is_member = sender == sender_pk; + if rumor.kind == Kind::PrivateDirectMessage && (is_member || is_target) { + Some(rumor.as_json()) + } else { + None } + } else { + None } - None }) - .map(|ev| ev.as_json()) .collect::>() .await; @@ -152,7 +151,10 @@ pub async fn send_message( let receiver = PublicKey::parse(&to).map_err(|e| e.to_string())?; match client.send_private_msg_to(relays, receiver, message, None).await { - Ok(_) => Ok(()), + Ok(output) => { + println!("send to: {}", output.success.iter().join(", ")); + Ok(()) + } Err(e) => Err(e.to_string()), } } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index d77c23f..d0af5b2 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -53,6 +53,10 @@ fn main() { #[cfg(not(target_os = "linux"))] let main_window = app.get_webview_window("main").unwrap(); + // Open devtools + #[cfg(debug_assertions)] + main_window.open_devtools(); + // Set custom decoration #[cfg(target_os = "windows")] main_window.create_overlay_titlebar().unwrap(); diff --git a/src/commands.ts b/src/commands.ts index a0fc3ec..b7ec936 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -63,9 +63,9 @@ try { else return { status: "error", error: e as any }; } }, -async getChatMessages(sender: string) : Promise> { +async getChatMessages(id: string) : Promise> { try { - return { status: "ok", data: await TAURI_INVOKE("get_chat_messages", { sender }) }; + return { status: "ok", data: await TAURI_INVOKE("get_chat_messages", { id }) }; } catch (e) { if(e instanceof Error) throw e; else return { status: "error", error: e as any }; diff --git a/src/components/user/name.tsx b/src/components/user/name.tsx index 760eaaa..2394b0c 100644 --- a/src/components/user/name.tsx +++ b/src/components/user/name.tsx @@ -12,7 +12,7 @@ export function UserName({ className }: { className?: string }) { if (user.isLoading) { return ( -
+
); } diff --git a/src/routes/$account.chats.$id.lazy.tsx b/src/routes/$account.chats.$id.lazy.tsx index 85ca79d..cdd64a2 100644 --- a/src/routes/$account.chats.$id.lazy.tsx +++ b/src/routes/$account.chats.$id.lazy.tsx @@ -144,7 +144,7 @@ function List() { ref={ref} className="relative h-full py-2 [&>div]:!flex [&>div]:flex-col [&>div]:justify-end [&>div]:min-h-full" > - + {isLoading || !data ? (
diff --git a/src/routes/$account.chats.lazy.tsx b/src/routes/$account.chats.lazy.tsx index 33870ca..68b1c3d 100644 --- a/src/routes/$account.chats.lazy.tsx +++ b/src/routes/$account.chats.lazy.tsx @@ -127,7 +127,7 @@ function ChatList() { {isLoading ? (
- {Array.from(Array(5)).map((index) => ( + {Array.from(Array(5)).map((_, index) => (
) : isError ? ( -
Error
+
Error
) : ( data.map((item) => (