feat: update commands

This commit is contained in:
reya
2024-07-26 12:57:26 +07:00
parent ccc5d85fc2
commit 268c1af5b1
8 changed files with 55 additions and 42 deletions

24
src-tauri/Cargo.lock generated
View File

@@ -2874,7 +2874,7 @@ checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
[[package]] [[package]]
name = "nostr" name = "nostr"
version = "0.33.0" version = "0.33.0"
source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395"
dependencies = [ dependencies = [
"aes", "aes",
"base64 0.21.7", "base64 0.21.7",
@@ -2903,7 +2903,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-database" name = "nostr-database"
version = "0.33.0" version = "0.33.0"
source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"flatbuffers", "flatbuffers",
@@ -2917,7 +2917,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-relay-pool" name = "nostr-relay-pool"
version = "0.33.0" version = "0.33.0"
source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395"
dependencies = [ dependencies = [
"async-utility", "async-utility",
"async-wsocket", "async-wsocket",
@@ -2932,7 +2932,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-sdk" name = "nostr-sdk"
version = "0.33.0" version = "0.33.0"
source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395"
dependencies = [ dependencies = [
"async-utility", "async-utility",
"atomic-destructor", "atomic-destructor",
@@ -2952,7 +2952,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-signer" name = "nostr-signer"
version = "0.33.0" version = "0.33.0"
source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395"
dependencies = [ dependencies = [
"async-utility", "async-utility",
"nostr", "nostr",
@@ -2965,7 +2965,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-sqlite" name = "nostr-sqlite"
version = "0.33.0" version = "0.33.0"
source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"nostr", "nostr",
@@ -2979,7 +2979,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-zapper" name = "nostr-zapper"
version = "0.33.0" version = "0.33.0"
source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"nostr", "nostr",
@@ -3099,7 +3099,7 @@ dependencies = [
[[package]] [[package]]
name = "nwc" name = "nwc"
version = "0.33.0" version = "0.33.0"
source = "git+https://github.com/rust-nostr/nostr#79b84f618d2e339f13c763f697c6fd56d8062aec" source = "git+https://github.com/rust-nostr/nostr#66d4b5905c8722952644d914ca480b2c33fa1395"
dependencies = [ dependencies = [
"async-utility", "async-utility",
"nostr", "nostr",
@@ -4418,9 +4418,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_spanned" name = "serde_spanned"
version = "0.6.6" version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d"
dependencies = [ dependencies = [
"serde", "serde",
] ]
@@ -5901,9 +5901,9 @@ checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]] [[package]]
name = "vswhom" name = "vswhom"

View File

@@ -224,18 +224,25 @@ pub async fn login(
client client
.handle_notifications(|notification| async { .handle_notifications(|notification| async {
if let RelayPoolNotification::Event { event, .. } = notification { if let RelayPoolNotification::Message { message, relay_url } = notification {
if event.kind == Kind::GiftWrap { if let RelayMessage::Event { event, .. } = message {
if let Ok(UnwrappedGift { rumor, sender }) = if event.kind == Kind::GiftWrap {
client.unwrap_gift_wrap(&event).await match client.unwrap_gift_wrap(&event).await {
{ Ok(UnwrappedGift { rumor, sender }) => {
window let payload =
.emit( Payload { event: rumor.as_json(), sender: sender.to_hex() };
"event",
Payload { event: rumor.as_json(), sender: sender.to_hex() }, if window.emit("event", payload).is_err() {
) println!("Failed")
.unwrap(); }
}
Err(e) => {
println!("Unwrapped Error: {} from {}", e, relay_url)
}
}
} }
} else {
println!("message: {}", message.as_json())
} }
} }
Ok(false) Ok(false)

View File

@@ -46,16 +46,13 @@ pub async fn get_chats(state: State<'_, Nostr>) -> Result<Vec<String>, String> {
#[tauri::command] #[tauri::command]
#[specta::specta] #[specta::specta]
pub async fn get_chat_messages( pub async fn get_chat_messages(id: String, state: State<'_, Nostr>) -> Result<Vec<String>, String> {
sender: String,
state: State<'_, Nostr>,
) -> Result<Vec<String>, String> {
let client = &state.client; let client = &state.client;
let signer = client.signer().await.map_err(|e| e.to_string())?; 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 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 { match client.get_events_of(vec![filter], None).await {
Ok(events) => { Ok(events) => {
@@ -63,15 +60,17 @@ pub async fn get_chat_messages(
.filter_map(|ev| async move { .filter_map(|ev| async move {
if let Ok(UnwrappedGift { rumor, sender }) = client.unwrap_gift_wrap(&ev).await if let Ok(UnwrappedGift { rumor, sender }) = client.unwrap_gift_wrap(&ev).await
{ {
if rumor.kind == Kind::PrivateDirectMessage let is_target = is_target(&sender_pk, &rumor.tags);
&& (sender == sender_pk || is_target(&sender_pk, &rumor.tags)) let is_member = sender == sender_pk;
{ if rumor.kind == Kind::PrivateDirectMessage && (is_member || is_target) {
return Some(rumor); Some(rumor.as_json())
} else {
None
} }
} else {
None
} }
None
}) })
.map(|ev| ev.as_json())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.await; .await;
@@ -152,7 +151,10 @@ pub async fn send_message(
let receiver = PublicKey::parse(&to).map_err(|e| e.to_string())?; let receiver = PublicKey::parse(&to).map_err(|e| e.to_string())?;
match client.send_private_msg_to(relays, receiver, message, None).await { 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()), Err(e) => Err(e.to_string()),
} }
} }

View File

@@ -53,6 +53,10 @@ fn main() {
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]
let main_window = app.get_webview_window("main").unwrap(); let main_window = app.get_webview_window("main").unwrap();
// Open devtools
#[cfg(debug_assertions)]
main_window.open_devtools();
// Set custom decoration // Set custom decoration
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
main_window.create_overlay_titlebar().unwrap(); main_window.create_overlay_titlebar().unwrap();

View File

@@ -63,9 +63,9 @@ try {
else return { status: "error", error: e as any }; else return { status: "error", error: e as any };
} }
}, },
async getChatMessages(sender: string) : Promise<Result<string[], string>> { async getChatMessages(id: string) : Promise<Result<string[], string>> {
try { 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) { } 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

@@ -12,7 +12,7 @@ export function UserName({ className }: { className?: string }) {
if (user.isLoading) { if (user.isLoading) {
return ( return (
<div className="size-4 w-20 bg-black/10 dark:bg-white/10 animate-pulse" /> <div className="size-4 w-20 rounded bg-black/10 dark:bg-white/10 animate-pulse" />
); );
} }

View File

@@ -144,7 +144,7 @@ function List() {
ref={ref} ref={ref}
className="relative h-full py-2 [&>div]:!flex [&>div]:flex-col [&>div]:justify-end [&>div]:min-h-full" className="relative h-full py-2 [&>div]:!flex [&>div]:flex-col [&>div]:justify-end [&>div]:min-h-full"
> >
<Virtualizer scrollRef={ref} shift> <Virtualizer scrollRef={ref}>
{isLoading || !data ? ( {isLoading || !data ? (
<div className="w-full h-56 flex items-center justify-center"> <div className="w-full h-56 flex items-center justify-center">
<div className="flex items-center gap-1.5"> <div className="flex items-center gap-1.5">

View File

@@ -127,7 +127,7 @@ function ChatList() {
<ScrollArea.Viewport className="relative h-full px-1.5"> <ScrollArea.Viewport className="relative h-full px-1.5">
{isLoading ? ( {isLoading ? (
<div> <div>
{Array.from(Array(5)).map((index) => ( {Array.from(Array(5)).map((_, index) => (
<div <div
key={index} key={index}
className="flex items-center rounded-lg p-2 mb-1 gap-2" className="flex items-center rounded-lg p-2 mb-1 gap-2"
@@ -138,7 +138,7 @@ function ChatList() {
))} ))}
</div> </div>
) : isError ? ( ) : isError ? (
<div>Error</div> <div className="p-2">Error</div>
) : ( ) : (
data.map((item) => ( data.map((item) => (
<Link <Link