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]]
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"

View File

@@ -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)

View File

@@ -46,16 +46,13 @@ pub async fn get_chats(state: State<'_, Nostr>) -> Result<Vec<String>, String> {
#[tauri::command]
#[specta::specta]
pub async fn get_chat_messages(
sender: String,
state: State<'_, Nostr>,
) -> Result<Vec<String>, String> {
pub async fn get_chat_messages(id: String, state: State<'_, Nostr>) -> Result<Vec<String>, 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::<Vec<_>>()
.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()),
}
}

View File

@@ -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();

View File

@@ -63,9 +63,9 @@ try {
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 {
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 };

View File

@@ -12,7 +12,7 @@ export function UserName({ className }: { className?: string }) {
if (user.isLoading) {
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}
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 ? (
<div className="w-full h-56 flex items-center justify-center">
<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">
{isLoading ? (
<div>
{Array.from(Array(5)).map((index) => (
{Array.from(Array(5)).map((_, index) => (
<div
key={index}
className="flex items-center rounded-lg p-2 mb-1 gap-2"
@@ -138,7 +138,7 @@ function ChatList() {
))}
</div>
) : isError ? (
<div>Error</div>
<div className="p-2">Error</div>
) : (
data.map((item) => (
<Link