From abb14743009baa3965ec723ebd4734a788ff08f3 Mon Sep 17 00:00:00 2001 From: reya Date: Mon, 30 Jun 2025 08:20:15 +0700 Subject: [PATCH] chore: update gpui and nostr-sdk --- Cargo.lock | 66 +++++++++------------- Cargo.toml | 10 +++- crates/auto_update/src/lib.rs | 6 +- crates/common/src/lib.rs | 35 +----------- crates/common/src/nip05.rs | 31 +++++++++++ crates/common/src/nip96.rs | 82 ++++++++++++++++++++++++++++ crates/common/src/profile.rs | 3 +- crates/coop/src/views/chat.rs | 13 +---- crates/coop/src/views/compose.rs | 2 +- crates/coop/src/views/login.rs | 3 +- crates/coop/src/views/new_account.rs | 4 +- crates/coop/src/views/profile.rs | 7 ++- crates/coop/src/views/relays.rs | 4 +- crates/coop/src/views/sidebar/mod.rs | 6 +- crates/global/src/lib.rs | 8 +-- crates/identity/src/lib.rs | 4 +- crates/ui/src/dock_area/tab_panel.rs | 2 +- crates/ui/src/emoji_picker.rs | 6 +- crates/ui/src/input/mask_pattern.rs | 2 +- crates/ui/src/popup_menu.rs | 4 +- crates/ui/src/text.rs | 8 +-- rust-toolchain.toml | 10 ++++ 22 files changed, 196 insertions(+), 120 deletions(-) create mode 100644 crates/common/src/nip05.rs create mode 100644 crates/common/src/nip96.rs create mode 100644 rust-toolchain.toml diff --git a/Cargo.lock b/Cargo.lock index 8a2eb66..16c0940 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1079,7 +1079,7 @@ dependencies = [ [[package]] name = "collections" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "indexmap", "rustc-hash 2.1.1", @@ -1412,9 +1412,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crunchy" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" [[package]] name = "crypto-common" @@ -1477,7 +1477,7 @@ dependencies = [ [[package]] name = "derive_refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "proc-macro2", "quote", @@ -2318,7 +2318,7 @@ dependencies = [ [[package]] name = "gpui" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "anyhow", "as-raw-xcb-connection", @@ -2411,7 +2411,7 @@ dependencies = [ [[package]] name = "gpui_macros" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -2634,7 +2634,7 @@ dependencies = [ [[package]] name = "http_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "anyhow", "bytes", @@ -2651,7 +2651,7 @@ dependencies = [ [[package]] name = "http_client_tls" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "rustls", "rustls-platform-verifier", @@ -2699,7 +2699,6 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", - "webpki-roots 1.0.1", ] [[package]] @@ -2940,9 +2939,9 @@ checksum = "d0263a3d970d5c054ed9312c0057b4f3bde9c0b33836d3637361d4a9e6e7a408" [[package]] name = "indexmap" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", "hashbrown 0.15.4", @@ -3209,9 +3208,9 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] name = "libredox" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +checksum = "1580801010e535496706ba011c15f8532df6b42297d2e471fec38ceadd8c0638" dependencies = [ "bitflags 2.9.1", "libc", @@ -3386,7 +3385,7 @@ dependencies = [ [[package]] name = "media" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "anyhow", "bindgen 0.71.1", @@ -3600,8 +3599,7 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" [[package]] name = "nostr" version = "0.42.1" -source = "git+https://github.com/rust-nostr/nostr#ecf711ee9f3bca83c2a31a1de0f2977cd2845af5" - +source = "git+https://github.com/rust-nostr/nostr#d7b4e225704337be23b54cde8d91458972ac87c8" dependencies = [ "aes", "base64", @@ -3613,8 +3611,6 @@ dependencies = [ "chacha20poly1305", "getrandom 0.2.16", "instant", - "regex", - "reqwest 0.12.20", "scrypt", "secp256k1", "serde", @@ -3626,8 +3622,7 @@ dependencies = [ [[package]] name = "nostr-connect" version = "0.42.0" -source = "git+https://github.com/rust-nostr/nostr#ecf711ee9f3bca83c2a31a1de0f2977cd2845af5" - +source = "git+https://github.com/rust-nostr/nostr#d7b4e225704337be23b54cde8d91458972ac87c8" dependencies = [ "async-utility", "nostr", @@ -3639,8 +3634,7 @@ dependencies = [ [[package]] name = "nostr-database" version = "0.42.0" -source = "git+https://github.com/rust-nostr/nostr#ecf711ee9f3bca83c2a31a1de0f2977cd2845af5" - +source = "git+https://github.com/rust-nostr/nostr#d7b4e225704337be23b54cde8d91458972ac87c8" dependencies = [ "flatbuffers", "lru", @@ -3651,8 +3645,7 @@ dependencies = [ [[package]] name = "nostr-lmdb" version = "0.42.0" -source = "git+https://github.com/rust-nostr/nostr#ecf711ee9f3bca83c2a31a1de0f2977cd2845af5" - +source = "git+https://github.com/rust-nostr/nostr#d7b4e225704337be23b54cde8d91458972ac87c8" dependencies = [ "async-utility", "heed", @@ -3665,8 +3658,7 @@ dependencies = [ [[package]] name = "nostr-relay-pool" version = "0.42.0" -source = "git+https://github.com/rust-nostr/nostr#ecf711ee9f3bca83c2a31a1de0f2977cd2845af5" - +source = "git+https://github.com/rust-nostr/nostr#d7b4e225704337be23b54cde8d91458972ac87c8" dependencies = [ "async-utility", "async-wsocket", @@ -3682,8 +3674,7 @@ dependencies = [ [[package]] name = "nostr-sdk" version = "0.42.0" -source = "git+https://github.com/rust-nostr/nostr#ecf711ee9f3bca83c2a31a1de0f2977cd2845af5" - +source = "git+https://github.com/rust-nostr/nostr#d7b4e225704337be23b54cde8d91458972ac87c8" dependencies = [ "async-utility", "nostr", @@ -3691,7 +3682,6 @@ dependencies = [ "nostr-lmdb", "nostr-relay-pool", "tokio", - "tracing", ] [[package]] @@ -4719,7 +4709,7 @@ dependencies = [ [[package]] name = "refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "derive_refineable", "workspace-hack", @@ -4828,8 +4818,6 @@ dependencies = [ "native-tls", "percent-encoding", "pin-project-lite", - "quinn", - "rustls", "rustls-pki-types", "serde", "serde_json", @@ -4837,7 +4825,6 @@ dependencies = [ "sync_wrapper", "tokio", "tokio-native-tls", - "tokio-rustls", "tokio-util", "tower", "tower-http", @@ -4847,13 +4834,12 @@ dependencies = [ "wasm-bindgen-futures", "wasm-streams", "web-sys", - "webpki-roots 1.0.1", ] [[package]] name = "reqwest_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "anyhow", "bytes", @@ -5324,7 +5310,7 @@ checksum = "0f7d95a54511e0c7be3f51e8867aa8cf35148d7b9445d44de2f943e2b206e749" [[package]] name = "semantic_version" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "anyhow", "serde", @@ -5687,7 +5673,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sum_tree" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "arrayvec", "log", @@ -6601,7 +6587,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "util" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#108162423da6d5d37bd78bffed74e7ebc2e8a83b" +source = "git+https://github.com/zed-industries/zed#c3d0230f89ff21257d965d4c410a274e52c4fe35" dependencies = [ "anyhow", "async-fs", @@ -7108,9 +7094,9 @@ dependencies = [ [[package]] name = "windows-capture" -version = "1.4.4" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "757c9e7b920233fec91cb314ad92b96853ba2907e3482a193d290d33838e3fc5" +checksum = "3a4df73e95feddb9ec1a7e9c2ca6323b8c97d5eeeff78d28f1eccdf19c882b24" dependencies = [ "parking_lot", "rayon", diff --git a/Cargo.toml b/Cargo.toml index 6a60a62..5a6e0c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,11 +17,17 @@ reqwest_client = { git = "https://github.com/zed-industries/zed" } # Nostr nostr = { git = "https://github.com/rust-nostr/nostr" } -nostr-sdk = { git = "https://github.com/rust-nostr/nostr", features = ["lmdb", "nip96", "nip59", "nip49", "nip44"] } +nostr-sdk = { git = "https://github.com/rust-nostr/nostr", features = [ + "lmdb", + "nip96", + "nip59", + "nip49", + "nip44", +] } nostr-connect = { git = "https://github.com/rust-nostr/nostr" } # Others -reqwest = { version = "0.12", features = ["stream"] } +reqwest = { version = "0.12", features = ["multipart", "stream", "json"] } emojis = "0.6.4" smol = "2" futures = "0.3" diff --git a/crates/auto_update/src/lib.rs b/crates/auto_update/src/lib.rs index 943b1d5..0bf838b 100644 --- a/crates/auto_update/src/lib.rs +++ b/crates/auto_update/src/lib.rs @@ -51,7 +51,7 @@ impl Drop for MacOsUnmounter { ); } Err(error) => { - log::error!("Error while trying to unmount disk image: {:?}", error); + log::error!("Error while trying to unmount disk image: {error:?}"); } } } @@ -154,7 +154,7 @@ impl AutoUpdater { target_file.write_all(&chunk).await?; } - log::info!("downloaded update. path:{:?}", downloaded_asset); + log::info!("downloaded update. path: {downloaded_asset:?}"); Ok((temp_dir, downloaded_asset)) } else { @@ -271,7 +271,7 @@ impl AutoUpdater { let from = extracted.join(&app_folder_name); let mut to = home_dir.join(".local"); - let expected_suffix = format!("{}/libexec/coop", app_folder_name); + let expected_suffix = format!("{app_folder_name}/libexec/coop"); if let Some(prefix) = running_app_path .to_str() diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index c3f8cfe..cc38757 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -2,48 +2,17 @@ use std::collections::HashSet; use std::hash::{DefaultHasher, Hash, Hasher}; use std::sync::Arc; -use anyhow::{anyhow, Error, Result}; use gpui::{Image, ImageFormat}; use itertools::Itertools; use nostr_sdk::prelude::*; use qrcode_generator::QrCodeEcc; -use reqwest::Client as ReqClient; pub mod debounced_delay; pub mod handle_auth; +pub mod nip05; +pub mod nip96; pub mod profile; -pub async fn verify_nip05(public_key: PublicKey, address: &str) -> Result { - let req_client = ReqClient::new(); - let address = Nip05Address::parse(address)?; - let res = req_client.get(address.url().to_string()).send().await?; - let json: Value = res.json().await?; - let verify = nip05::verify_from_json(&public_key, &address, &json); - - Ok(verify) -} - -pub async fn nip05_profile(address: &str) -> Result { - let req_client = ReqClient::new(); - let address = Nip05Address::parse(address)?; - let res = req_client.get(address.url().to_string()).send().await?; - let json: Value = res.json().await?; - - if let Ok(profile) = Nip05Profile::from_json(&address, &json) { - Ok(profile) - } else { - Err(anyhow!("Failed to get NIP-05 profile")) - } -} - -pub async fn nip96_upload(client: &Client, server: Url, file: Vec) -> Result { - let signer = client.signer().await?; - let config = nip96::get_server_config(server.to_owned(), None).await?; - let url = nip96::upload_data(&signer, &config, file, None, None).await?; - - Ok(url) -} - pub fn room_hash(event: &Event) -> u64 { let mut hasher = DefaultHasher::new(); let mut pubkeys: Vec = vec![]; diff --git a/crates/common/src/nip05.rs b/crates/common/src/nip05.rs new file mode 100644 index 0000000..1286033 --- /dev/null +++ b/crates/common/src/nip05.rs @@ -0,0 +1,31 @@ +use anyhow::anyhow; +use nostr::prelude::*; +use reqwest::Client as ReqClient; + +pub async fn nip05_verify(public_key: PublicKey, address: &str) -> Result { + let req_client = ReqClient::new(); + let address = Nip05Address::parse(address)?; + + // Get NIP-05 response + let res = req_client.get(address.url().to_string()).send().await?; + let json: Value = res.json().await?; + + let verify = nip05::verify_from_json(&public_key, &address, &json); + + Ok(verify) +} + +pub async fn nip05_profile(address: &str) -> Result { + let req_client = ReqClient::new(); + let address = Nip05Address::parse(address)?; + + // Get NIP-05 response + let res = req_client.get(address.url().to_string()).send().await?; + let json: Value = res.json().await?; + + if let Ok(profile) = Nip05Profile::from_json(&address, &json) { + Ok(profile) + } else { + Err(anyhow!("Failed to get NIP-05 profile")) + } +} diff --git a/crates/common/src/nip96.rs b/crates/common/src/nip96.rs new file mode 100644 index 0000000..521da3b --- /dev/null +++ b/crates/common/src/nip96.rs @@ -0,0 +1,82 @@ +use anyhow::anyhow; +use nostr::hashes::sha256::Hash as Sha256Hash; +use nostr::hashes::Hash; +use nostr::prelude::*; +use nostr_sdk::prelude::*; +use reqwest::multipart; +use reqwest::Client as ReqClient; +use reqwest::Response; + +pub(crate) fn make_multipart_form( + file_data: Vec, + mime_type: Option<&str>, +) -> Result { + let form_file_part = multipart::Part::bytes(file_data).file_name("filename"); + + // Set the part's MIME type, or leave it as is if mime_type is None + + let part = match mime_type { + Some(mime) => form_file_part.mime_str(mime)?, + None => form_file_part, + }; + + Ok(multipart::Form::new().part("file", part)) +} + +pub(crate) async fn upload( + signer: &T, + desc: &ServerConfig, + file_data: Vec, + mime_type: Option<&str>, +) -> Result +where + T: NostrSigner, +{ + let payload: Sha256Hash = Sha256Hash::hash(&file_data); + let data: HttpData = HttpData::new(desc.api_url.clone(), HttpMethod::POST).payload(payload); + let nip98_auth: String = data.to_authorization(signer).await?; + + // Make form + let form: multipart::Form = make_multipart_form(file_data, mime_type)?; + + // Make req client + let req_client = ReqClient::new(); + + // Send + let response: Response = req_client + .post(desc.api_url.clone()) + .header("Authorization", nip98_auth) + .multipart(form) + .send() + .await?; + + // Parse response + let json: Value = response.json().await?; + let upload_response = nip96::UploadResponse::from_json(json.to_string())?; + + if upload_response.status == UploadResponseStatus::Error { + return Err(anyhow!(upload_response.message)); + } + + Ok(upload_response.download_url()?.to_owned()) +} + +pub async fn nip96_upload( + client: &Client, + server: &Url, + file: Vec, +) -> Result { + let req_client = ReqClient::new(); + let config_url = nip96::get_server_config_url(server)?; + + // Get + let res = req_client.get(config_url.to_string()).send().await?; + let json: Value = res.json().await?; + + let config = nip96::ServerConfig::from_json(json.to_string())?; + let signer = client.signer().await?; + + let url = upload(&signer, &config, file, None).await?; + + Ok(url) +} diff --git a/crates/common/src/profile.rs b/crates/common/src/profile.rs index cffcb61..d08b61c 100644 --- a/crates/common/src/profile.rs +++ b/crates/common/src/profile.rs @@ -18,8 +18,7 @@ impl RenderProfile for Profile { .map(|picture| { if proxy { format!( - "{}/?url={}&w=100&h=100&fit=cover&mask=circle&default={}&n=-1", - IMAGE_RESIZE_SERVICE, picture, FALLBACK_IMG + "{IMAGE_RESIZE_SERVICE}/?url={picture}&w=100&h=100&fit=cover&mask=circle&default={FALLBACK_IMG}&n=-1" ) .into() } else { diff --git a/crates/coop/src/views/chat.rs b/crates/coop/src/views/chat.rs index 28b91d8..52aa248 100644 --- a/crates/coop/src/views/chat.rs +++ b/crates/coop/src/views/chat.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use chats::message::Message; use chats::room::{Room, RoomKind, SendError}; -use common::nip96_upload; +use common::nip96::nip96_upload; use common::profile::RenderProfile; use global::shared_state; use gpui::prelude::FluentBuilder; @@ -390,16 +390,9 @@ impl Chat { // Spawn task via async utility instead of GPUI context nostr_sdk::async_utility::task::spawn(async move { - let url = match nip96_upload(shared_state().client(), nip96, file_data) + let url = nip96_upload(shared_state().client(), &nip96, file_data) .await - { - Ok(url) => Some(url), - Err(e) => { - log::error!("Upload error: {e}"); - None - } - }; - + .ok(); _ = tx.send(url); }); diff --git a/crates/coop/src/views/compose.rs b/crates/coop/src/views/compose.rs index 3cf79df..595c3b4 100644 --- a/crates/coop/src/views/compose.rs +++ b/crates/coop/src/views/compose.rs @@ -4,7 +4,7 @@ use std::time::Duration; use anyhow::{anyhow, Error}; use chats::room::{Room, RoomKind}; use chats::ChatRegistry; -use common::nip05_profile; +use common::nip05::nip05_profile; use common::profile::RenderProfile; use global::shared_state; use gpui::prelude::FluentBuilder; diff --git a/crates/coop/src/views/login.rs b/crates/coop/src/views/login.rs index 624acea..ee3a27e 100644 --- a/crates/coop/src/views/login.rs +++ b/crates/coop/src/views/login.rs @@ -592,8 +592,7 @@ impl Render for Login { .text_center() .text_color(cx.theme().text_muted) .child(SharedString::from(format!( - "Approve connection request from your signer in {} seconds", - i + "Approve connection request from your signer in {i} seconds" ))), ) }) diff --git a/crates/coop/src/views/new_account.rs b/crates/coop/src/views/new_account.rs index da8f7f6..89be1ad 100644 --- a/crates/coop/src/views/new_account.rs +++ b/crates/coop/src/views/new_account.rs @@ -1,4 +1,4 @@ -use common::nip96_upload; +use common::nip96::nip96_upload; use global::shared_state; use gpui::prelude::FluentBuilder; use gpui::{ @@ -158,7 +158,7 @@ impl NewAccount { nostr_sdk::async_utility::task::spawn(async move { if let Ok(url) = - nip96_upload(shared_state().client(), nip96, file_data).await + nip96_upload(shared_state().client(), &nip96, file_data).await { _ = tx.send(url); } diff --git a/crates/coop/src/views/profile.rs b/crates/coop/src/views/profile.rs index babaa24..7ea8308 100644 --- a/crates/coop/src/views/profile.rs +++ b/crates/coop/src/views/profile.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use std::time::Duration; -use common::nip96_upload; +use common::nip96::nip96_upload; use global::shared_state; use gpui::prelude::FluentBuilder; use gpui::{ @@ -104,7 +104,7 @@ impl Profile { } fn upload(&mut self, window: &mut Window, cx: &mut Context) { - let nip96 = AppSettings::get_global(cx).settings.media_server.clone(); + let nip96_server = AppSettings::get_global(cx).settings.media_server.clone(); let avatar_input = self.avatar_input.downgrade(); let paths = cx.prompt_for_paths(PathPromptOptions { files: true, @@ -125,7 +125,8 @@ impl Profile { nostr_sdk::async_utility::task::spawn(async move { if let Ok(url) = - nip96_upload(shared_state().client(), nip96, file_data).await + nip96_upload(shared_state().client(), &nip96_server, file_data) + .await { _ = tx.send(url); } diff --git a/crates/coop/src/views/relays.rs b/crates/coop/src/views/relays.rs index 6f963fd..331fd4d 100644 --- a/crates/coop/src/views/relays.rs +++ b/crates/coop/src/views/relays.rs @@ -118,7 +118,7 @@ impl Relays { ]); if let Err(e) = client.send_event_builder(builder).await { - log::error!("Failed to send relay list event: {}", e); + log::error!("Failed to send relay list event: {e}"); } } @@ -153,7 +153,7 @@ impl Relays { ) .await { - log::error!("Failed to subscribe to new messages: {}", e); + log::error!("Failed to subscribe to new messages: {e}"); } Ok(output.val) diff --git a/crates/coop/src/views/sidebar/mod.rs b/crates/coop/src/views/sidebar/mod.rs index f0ea5f8..a8fb465 100644 --- a/crates/coop/src/views/sidebar/mod.rs +++ b/crates/coop/src/views/sidebar/mod.rs @@ -6,8 +6,8 @@ use anyhow::Error; use chats::room::{Room, RoomKind}; use chats::{ChatRegistry, RoomEmitter}; use common::debounced_delay::DebouncedDelay; +use common::nip05::nip05_verify; use common::profile::RenderProfile; -use common::verify_nip05; use element::DisplayRoom; use global::constants::{DEFAULT_MODAL_WIDTH, SEARCH_RELAYS}; use global::shared_state; @@ -185,7 +185,7 @@ impl Sidebar { continue; }; - if !verify_nip05(event.pubkey, target).await.unwrap_or(false) { + if !nip05_verify(event.pubkey, target).await.unwrap_or(false) { // Skip if NIP-05 is not valid or failed to verify continue; }; @@ -218,7 +218,7 @@ impl Sidebar { this.update(cx, |this, cx| { if result.is_empty() { let msg = - format!("There are no users matching query {}", query_cloned); + format!("There are no users matching query {query_cloned}"); window.push_notification(Notification::info(msg), cx); this.set_finding(false, cx); } else { diff --git a/crates/global/src/lib.rs b/crates/global/src/lib.rs index 13d38e2..06fa109 100644 --- a/crates/global/src/lib.rs +++ b/crates/global/src/lib.rs @@ -369,13 +369,13 @@ impl Globals { pub(crate) async fn connect(&self) { for relay in BOOTSTRAP_RELAYS.into_iter() { if let Err(e) = self.client.add_relay(relay).await { - log::error!("Failed to add relay {}: {}", relay, e); + log::error!("Failed to add relay {relay}: {e}"); } } for relay in SEARCH_RELAYS.into_iter() { if let Err(e) = self.client.add_relay(relay).await { - log::error!("Failed to add relay {}: {}", relay, e); + log::error!("Failed to add relay {relay}: {e}"); } } @@ -470,7 +470,7 @@ impl Globals { .subscribe_to(BOOTSTRAP_RELAYS, filter, Some(opts)) .await { - log::error!("Failed to subscribe for app updates: {}", e); + log::error!("Failed to subscribe for app updates: {e}"); } log::info!("Subscribed to app updates"); @@ -623,7 +623,7 @@ impl Globals { .subscribe_to(BOOTSTRAP_RELAYS, filter, Some(opts)) .await { - log::error!("Failed to subscribe for file metadata: {}", e); + log::error!("Failed to subscribe for file metadata: {e}"); } else { self.send_signal(NostrSignal::AppUpdate(event.to_owned())) .await; diff --git a/crates/identity/src/lib.rs b/crates/identity/src/lib.rs index 7b737af..9eaccb2 100644 --- a/crates/identity/src/lib.rs +++ b/crates/identity/src/lib.rs @@ -408,7 +408,7 @@ impl Identity { ); if let Err(e) = client.send_event_builder(builder).await { - log::error!("Failed to send relay list event: {}", e); + log::error!("Failed to send relay list event: {e}"); }; // Create messaging relay list @@ -423,7 +423,7 @@ impl Identity { ); if let Err(e) = client.send_event_builder(builder).await { - log::error!("Failed to send messaging relay list event: {}", e); + log::error!("Failed to send messaging relay list event: {e}"); }; // Subscribe for user's data diff --git a/crates/ui/src/dock_area/tab_panel.rs b/crates/ui/src/dock_area/tab_panel.rs index 8ec93ca..6f71666 100644 --- a/crates/ui/src/dock_area/tab_panel.rs +++ b/crates/ui/src/dock_area/tab_panel.rs @@ -518,7 +518,7 @@ impl TabPanel { }; Some( - Button::new(SharedString::from(format!("toggle-dock:{:?}", placement))) + Button::new(SharedString::from(format!("toggle-dock:{placement:?}"))) .icon(icon) .small() .ghost() diff --git a/crates/ui/src/emoji_picker.rs b/crates/ui/src/emoji_picker.rs index c838cc9..759d787 100644 --- a/crates/ui/src/emoji_picker.rs +++ b/crates/ui/src/emoji_picker.rs @@ -102,11 +102,11 @@ impl RenderOnce for EmojiPicker { input.update(cx, |this, cx| { let current = this.value(); let new_text = if current.is_empty() { - format!("{}", item) + format!("{item}") } else if current.ends_with(" ") { - format!("{}{}", current, item) + format!("{current}{item}") } else { - format!("{} {}", current, item) + format!("{current} {item}") }; this.set_value(new_text, window, cx); }); diff --git a/crates/ui/src/input/mask_pattern.rs b/crates/ui/src/input/mask_pattern.rs index 9ea6737..f126c78 100644 --- a/crates/ui/src/input/mask_pattern.rs +++ b/crates/ui/src/input/mask_pattern.rs @@ -302,7 +302,7 @@ impl MaskPattern { if fraction == &Some(0) { int_with_sep } else { - format!("{}.{}", int_with_sep, frac) + format!("{int_with_sep}.{frac}") } } else { int_with_sep diff --git a/crates/ui/src/popup_menu.rs b/crates/ui/src/popup_menu.rs index 76e5ce9..6894538 100644 --- a/crates/ui/src/popup_menu.rs +++ b/crates/ui/src/popup_menu.rs @@ -50,7 +50,7 @@ pub trait PopupMenuExt: Styled + Selectable + IntoElement + 'static { let style = self.style().clone(); let element_id = self.element_id(); - Popover::new(SharedString::from(format!("popup-menu:{:?}", element_id))) + Popover::new(SharedString::from(format!("popup-menu:{element_id:?}"))) .no_style() .trigger(self) .trigger_style(style) @@ -716,7 +716,7 @@ impl Render for PopupMenu { /// Return the Platform specific keybinding string by KeyStroke pub fn key_shortcut(key: Keystroke) -> String { if cfg!(target_os = "macos") { - return format!("{}", key); + return format!("{key}"); } let mut parts = vec![]; diff --git a/crates/ui/src/text.rs b/crates/ui/src/text.rs index 3cec16b..c9eaee2 100644 --- a/crates/ui/src/text.rs +++ b/crates/ui/src/text.rs @@ -293,7 +293,7 @@ pub fn render_plain_text_mut( // Make it clickable link_ranges.push(new_range); - link_urls.push(format!("mention:{}", entity_without_prefix)); + link_urls.push(format!("mention:{entity_without_prefix}")); // Adjust subsequent ranges if needed if length_diff != 0 { @@ -301,11 +301,11 @@ pub fn render_plain_text_mut( } } else { // No profile match or not a profile entity - create njump.me link - let njump_url = format!("https://njump.me/{}", entity_without_prefix); + let njump_url = format!("https://njump.me/{entity_without_prefix}"); // Create a shortened display format for the URL let shortened_entity = format_shortened_entity(entity_without_prefix); - let display_text = format!("https://njump.me/{}", shortened_entity); + let display_text = format!("https://njump.me/{shortened_entity}"); // Replace the original entity with the shortened display version text.replace_range(range.clone(), &display_text); @@ -350,7 +350,7 @@ fn format_shortened_entity(entity: &str) -> String { let prefix = &entity[0..=prefix_end]; // Include the '1' let suffix = &entity[entity.len() - 4..]; // Last 4 chars - format!("{}...{}", prefix, suffix) + format!("{prefix}...{suffix}") } else { entity.to_string() } diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..e9326a9 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,10 @@ +[toolchain] +channel = "1.88" +profile = "minimal" +components = ["rustfmt", "clippy"] +targets = [ + "x86_64-apple-darwin", + "aarch64-apple-darwin", + "x86_64-unknown-linux-gnu", + "x86_64-pc-windows-msvc", +]