chore: use latest nostr sdk
This commit is contained in:
20
src-tauri/Cargo.lock
generated
20
src-tauri/Cargo.lock
generated
@@ -3081,7 +3081,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
|
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"windows-targets 0.52.6",
|
"windows-targets 0.48.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3480,7 +3480,7 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nostr"
|
name = "nostr"
|
||||||
version = "0.35.0"
|
version = "0.35.0"
|
||||||
source = "git+https://github.com/rust-nostr/nostr#677da267a80838d66b2ea627d2d08bca837495c9"
|
source = "git+https://github.com/rust-nostr/nostr#282fbc39373674b7394806d47311a8e483da0ef0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
"aes",
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
@@ -3510,7 +3510,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nostr-database"
|
name = "nostr-database"
|
||||||
version = "0.35.0"
|
version = "0.35.0"
|
||||||
source = "git+https://github.com/rust-nostr/nostr#677da267a80838d66b2ea627d2d08bca837495c9"
|
source = "git+https://github.com/rust-nostr/nostr#282fbc39373674b7394806d47311a8e483da0ef0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"flatbuffers",
|
"flatbuffers",
|
||||||
@@ -3524,7 +3524,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nostr-lmdb"
|
name = "nostr-lmdb"
|
||||||
version = "0.35.0"
|
version = "0.35.0"
|
||||||
source = "git+https://github.com/rust-nostr/nostr#677da267a80838d66b2ea627d2d08bca837495c9"
|
source = "git+https://github.com/rust-nostr/nostr#282fbc39373674b7394806d47311a8e483da0ef0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heed",
|
"heed",
|
||||||
"nostr",
|
"nostr",
|
||||||
@@ -3537,7 +3537,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nostr-relay-pool"
|
name = "nostr-relay-pool"
|
||||||
version = "0.35.0"
|
version = "0.35.0"
|
||||||
source = "git+https://github.com/rust-nostr/nostr#677da267a80838d66b2ea627d2d08bca837495c9"
|
source = "git+https://github.com/rust-nostr/nostr#282fbc39373674b7394806d47311a8e483da0ef0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-utility",
|
"async-utility",
|
||||||
"async-wsocket",
|
"async-wsocket",
|
||||||
@@ -3555,7 +3555,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nostr-sdk"
|
name = "nostr-sdk"
|
||||||
version = "0.35.0"
|
version = "0.35.0"
|
||||||
source = "git+https://github.com/rust-nostr/nostr#677da267a80838d66b2ea627d2d08bca837495c9"
|
source = "git+https://github.com/rust-nostr/nostr#282fbc39373674b7394806d47311a8e483da0ef0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-utility",
|
"async-utility",
|
||||||
"atomic-destructor",
|
"atomic-destructor",
|
||||||
@@ -3575,7 +3575,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nostr-signer"
|
name = "nostr-signer"
|
||||||
version = "0.35.0"
|
version = "0.35.0"
|
||||||
source = "git+https://github.com/rust-nostr/nostr#677da267a80838d66b2ea627d2d08bca837495c9"
|
source = "git+https://github.com/rust-nostr/nostr#282fbc39373674b7394806d47311a8e483da0ef0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-utility",
|
"async-utility",
|
||||||
"nostr",
|
"nostr",
|
||||||
@@ -3588,7 +3588,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nostr-zapper"
|
name = "nostr-zapper"
|
||||||
version = "0.35.0"
|
version = "0.35.0"
|
||||||
source = "git+https://github.com/rust-nostr/nostr#677da267a80838d66b2ea627d2d08bca837495c9"
|
source = "git+https://github.com/rust-nostr/nostr#282fbc39373674b7394806d47311a8e483da0ef0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"nostr",
|
"nostr",
|
||||||
@@ -3732,7 +3732,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nwc"
|
name = "nwc"
|
||||||
version = "0.35.0"
|
version = "0.35.0"
|
||||||
source = "git+https://github.com/rust-nostr/nostr#677da267a80838d66b2ea627d2d08bca837495c9"
|
source = "git+https://github.com/rust-nostr/nostr#282fbc39373674b7394806d47311a8e483da0ef0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-utility",
|
"async-utility",
|
||||||
"nostr",
|
"nostr",
|
||||||
@@ -7223,7 +7223,7 @@ version = "0.1.9"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -30,10 +30,6 @@ pub async fn watch_account(id: String, state: State<'_, Nostr>) -> Result<String
|
|||||||
// Set empty password
|
// Set empty password
|
||||||
keyring.set_password("").map_err(|e| e.to_string())?;
|
keyring.set_password("").map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
// Update state
|
|
||||||
let mut accounts = state.accounts.lock().unwrap().clone();
|
|
||||||
accounts.push(npub.clone());
|
|
||||||
|
|
||||||
// Get user's profile
|
// Get user's profile
|
||||||
let _ = client
|
let _ = client
|
||||||
.fetch_metadata(public_key, Some(Duration::from_secs(4)))
|
.fetch_metadata(public_key, Some(Duration::from_secs(4)))
|
||||||
@@ -80,10 +76,6 @@ pub async fn import_account(
|
|||||||
// Update signer
|
// Update signer
|
||||||
client.set_signer(Some(signer)).await;
|
client.set_signer(Some(signer)).await;
|
||||||
|
|
||||||
// Update state
|
|
||||||
let mut accounts = state.accounts.lock().unwrap().clone();
|
|
||||||
accounts.push(npub.clone());
|
|
||||||
|
|
||||||
// Get user's profile
|
// Get user's profile
|
||||||
let _ = client
|
let _ = client
|
||||||
.fetch_metadata(public_key, Some(Duration::from_secs(4)))
|
.fetch_metadata(public_key, Some(Duration::from_secs(4)))
|
||||||
@@ -131,10 +123,6 @@ pub async fn connect_account(uri: String, state: State<'_, Nostr>) -> Result<Str
|
|||||||
// Update signer
|
// Update signer
|
||||||
let _ = client.set_signer(Some(signer.into())).await;
|
let _ = client.set_signer(Some(signer.into())).await;
|
||||||
|
|
||||||
// Update state
|
|
||||||
let mut accounts = state.accounts.lock().unwrap().clone();
|
|
||||||
accounts.push(remote_npub.clone());
|
|
||||||
|
|
||||||
// Get user's profile
|
// Get user's profile
|
||||||
let _ = client
|
let _ = client
|
||||||
.fetch_metadata(remote_user, Some(Duration::from_secs(4)))
|
.fetch_metadata(remote_user, Some(Duration::from_secs(4)))
|
||||||
|
|||||||
@@ -19,42 +19,44 @@ pub async fn get_event(id: String, state: State<'_, Nostr>) -> Result<RichEvent,
|
|||||||
let client = &state.client;
|
let client = &state.client;
|
||||||
let event_id = EventId::from_str(&id).map_err(|err| err.to_string())?;
|
let event_id = EventId::from_str(&id).map_err(|err| err.to_string())?;
|
||||||
|
|
||||||
match client.database().event_by_id(&event_id).await {
|
let events = client
|
||||||
Ok(events) => {
|
.database()
|
||||||
if let Some(event) = events {
|
.event_by_id(&event_id)
|
||||||
let raw = event.as_json();
|
.await
|
||||||
let parsed = if event.kind == Kind::TextNote {
|
.map_err(|err| err.to_string())?;
|
||||||
Some(parse_event(&event.content).await)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(RichEvent { raw, parsed })
|
if let Some(event) = events {
|
||||||
|
let raw = event.as_json();
|
||||||
|
let parsed = if event.kind == Kind::TextNote {
|
||||||
|
Some(parse_event(&event.content).await)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(RichEvent { raw, parsed })
|
||||||
|
} else {
|
||||||
|
let filter = Filter::new().id(event_id);
|
||||||
|
let mut rich_event = RichEvent {
|
||||||
|
raw: "".to_string(),
|
||||||
|
parsed: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut rx = client
|
||||||
|
.stream_events(vec![filter], Some(Duration::from_secs(5)))
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
while let Some(event) = rx.next().await {
|
||||||
|
let raw = event.as_json();
|
||||||
|
let parsed = if event.kind == Kind::TextNote {
|
||||||
|
Some(parse_event(&event.content).await)
|
||||||
} else {
|
} else {
|
||||||
let filter = Filter::new().id(event_id);
|
None
|
||||||
|
};
|
||||||
match client
|
rich_event = RichEvent { raw, parsed }
|
||||||
.fetch_events(vec![filter], Some(Duration::from_secs(3)))
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(events) => {
|
|
||||||
if let Some(event) = events.iter().next() {
|
|
||||||
let raw = event.as_json();
|
|
||||||
let parsed = if event.kind == Kind::TextNote {
|
|
||||||
Some(parse_event(&event.content).await)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
Ok(RichEvent { raw, parsed })
|
|
||||||
} else {
|
|
||||||
Err(format!("Cannot found the event with ID {}", id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => Err(err.to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(err) => Err(err.to_string()),
|
|
||||||
|
Ok(rich_event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,25 +334,15 @@ pub async fn repost(raw: String, state: State<'_, Nostr>) -> Result<String, Stri
|
|||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
pub async fn is_reposted(id: String, state: State<'_, Nostr>) -> Result<bool, String> {
|
pub async fn is_reposted(id: String, state: State<'_, Nostr>) -> Result<bool, String> {
|
||||||
let client = &state.client;
|
let client = &state.client;
|
||||||
let accounts = state.accounts.lock().unwrap().clone();
|
let signer = client.signer().await.map_err(|err| err.to_string())?;
|
||||||
|
let public_key = signer.public_key().await.map_err(|err| err.to_string())?;
|
||||||
|
|
||||||
let event_id = EventId::parse(&id).map_err(|err| err.to_string())?;
|
let event_id = EventId::parse(&id).map_err(|err| err.to_string())?;
|
||||||
|
|
||||||
let authors: Vec<PublicKey> = accounts
|
|
||||||
.iter()
|
|
||||||
.filter_map(|acc| {
|
|
||||||
if let Ok(pk) = PublicKey::from_str(acc) {
|
|
||||||
Some(pk)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let filter = Filter::new()
|
let filter = Filter::new()
|
||||||
.event(event_id)
|
.event(event_id)
|
||||||
.kind(Kind::Repost)
|
.kind(Kind::Repost)
|
||||||
.authors(authors);
|
.author(public_key);
|
||||||
|
|
||||||
match client.database().query(vec![filter]).await {
|
match client.database().query(vec![filter]).await {
|
||||||
Ok(events) => Ok(!events.is_empty()),
|
Ok(events) => Ok(!events.is_empty()),
|
||||||
|
|||||||
@@ -50,11 +50,22 @@ pub async fn get_profile(
|
|||||||
return Ok(profile.metadata().as_json());
|
return Ok(profile.metadata().as_json());
|
||||||
};
|
};
|
||||||
|
|
||||||
let metadata = client
|
let filter = Filter::new()
|
||||||
.fetch_metadata(public_key, Some(Duration::from_secs(3)))
|
.author(public_key)
|
||||||
|
.kind(Kind::Metadata)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
let mut metadata = Metadata::new();
|
||||||
|
|
||||||
|
let mut rx = client
|
||||||
|
.stream_events(vec![filter], Some(Duration::from_secs(5)))
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
while let Some(event) = rx.next().await {
|
||||||
|
metadata = Metadata::from_json(&event.content).map_err(|e| e.to_string())?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(metadata.as_json())
|
Ok(metadata.as_json())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ pub async fn sync_account(
|
|||||||
app_handle: tauri::AppHandle,
|
app_handle: tauri::AppHandle,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let client = &state.client;
|
let client = &state.client;
|
||||||
let bootstrap_relays = state.bootstrap_relays.lock().unwrap().clone();
|
|
||||||
|
|
||||||
let public_key = PublicKey::from_bech32(&id).map_err(|e| e.to_string())?;
|
let public_key = PublicKey::from_bech32(&id).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
let filter = Filter::new().author(public_key).kinds(vec![
|
let filter = Filter::new().author(public_key).kinds(vec![
|
||||||
@@ -60,7 +58,7 @@ pub async fn sync_account(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Ok(output) = client.sync_with(&bootstrap_relays, filter, &opts).await {
|
if let Ok(output) = client.sync(filter, &opts).await {
|
||||||
println!("Success: {:?}", output.success);
|
println!("Success: {:?}", output.success);
|
||||||
println!("Failed: {:?}", output.failed);
|
println!("Failed: {:?}", output.failed);
|
||||||
|
|
||||||
@@ -101,7 +99,7 @@ pub async fn sync_account(
|
|||||||
])
|
])
|
||||||
.limit(10000);
|
.limit(10000);
|
||||||
|
|
||||||
if let Ok(output) = client.sync_with(&bootstrap_relays, filter, &opts).await {
|
if let Ok(output) = client.sync(filter, &opts).await {
|
||||||
println!("Success: {:?}", output.success);
|
println!("Success: {:?}", output.success);
|
||||||
println!("Failed: {:?}", output.failed);
|
println!("Failed: {:?}", output.failed);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ pub mod common;
|
|||||||
pub struct Nostr {
|
pub struct Nostr {
|
||||||
client: Client,
|
client: Client,
|
||||||
settings: Mutex<Settings>,
|
settings: Mutex<Settings>,
|
||||||
accounts: Mutex<Vec<String>>,
|
|
||||||
bootstrap_relays: Mutex<Vec<Url>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize, Type)]
|
#[derive(Clone, Serialize, Deserialize, Type)]
|
||||||
@@ -169,7 +167,7 @@ fn main() {
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
main_window.set_traffic_lights_inset(7.0, 10.0).unwrap();
|
main_window.set_traffic_lights_inset(7.0, 10.0).unwrap();
|
||||||
|
|
||||||
let (client, bootstrap_relays) = tauri::async_runtime::block_on(async move {
|
let client = tauri::async_runtime::block_on(async move {
|
||||||
// Setup database
|
// Setup database
|
||||||
let database = NostrLMDB::open(config_dir.join("nostr"))
|
let database = NostrLMDB::open(config_dir.join("nostr"))
|
||||||
.expect("Error: cannot create database.");
|
.expect("Error: cannot create database.");
|
||||||
@@ -225,21 +223,13 @@ fn main() {
|
|||||||
// Connect
|
// Connect
|
||||||
client.connect_with_timeout(Duration::from_secs(10)).await;
|
client.connect_with_timeout(Duration::from_secs(10)).await;
|
||||||
|
|
||||||
// Get all bootstrap relays
|
client
|
||||||
let bootstrap_relays: Vec<Url> =
|
|
||||||
client.pool().all_relays().await.into_keys().collect();
|
|
||||||
|
|
||||||
(client, bootstrap_relays)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let accounts = get_all_accounts();
|
|
||||||
|
|
||||||
// Create global state
|
// Create global state
|
||||||
app.manage(Nostr {
|
app.manage(Nostr {
|
||||||
client,
|
client,
|
||||||
accounts: Mutex::new(accounts),
|
|
||||||
settings: Mutex::new(Settings::default()),
|
settings: Mutex::new(Settings::default()),
|
||||||
bootstrap_relays: Mutex::new(bootstrap_relays),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Run notification thread
|
// Run notification thread
|
||||||
|
|||||||
Reference in New Issue
Block a user