Merge branch 'main' of github.com:lumehq/lume

This commit is contained in:
reya
2024-05-30 15:23:11 +07:00
3 changed files with 388 additions and 281 deletions

608
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -11,16 +11,17 @@ rust-version = "1.68"
tauri-build = { version = "2.0.0-beta", features = [] } tauri-build = { version = "2.0.0-beta", features = [] }
[dependencies] [dependencies]
thiserror = "1.0"
nostr-sdk = { version = "0.31", features = ["sqlite"] } nostr-sdk = { version = "0.31", features = ["sqlite"] }
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
serde_json = "1.0" serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
tauri = { version = "2.0.0-beta", features = [ tauri = { version = "2.0.0-beta", features = [
"unstable", "unstable",
"tray-icon", "tray-icon",
"macos-private-api", "macos-private-api",
"native-tls-vendored", "native-tls-vendored",
"protocol-asset", "protocol-asset",
] } ] }
tauri-plugin-clipboard-manager = "2.1.0-beta" tauri-plugin-clipboard-manager = "2.1.0-beta"
tauri-plugin-dialog = "2.0.0-beta" tauri-plugin-dialog = "2.0.0-beta"

View File

@@ -3,35 +3,45 @@ use keyring::Entry;
use nostr_sdk::prelude::*; use nostr_sdk::prelude::*;
use std::{str::FromStr, time::Duration}; use std::{str::FromStr, time::Duration};
use tauri::State; use tauri::State;
use thiserror::Error;
use url::Url; use url::Url;
#[derive(Debug, Error)]
enum Error {
#[error(transparent)]
Client(#[from] nostr_sdk::client::Error),
#[error(transparent)]
Key(#[from] nostr_sdk::key::Error),
#[error(transparent)]
Num(#[from] std::num::ParseIntError),
}
impl serde::Serialize for Error {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
}
#[tauri::command] #[tauri::command]
#[specta::specta] #[specta::specta]
pub async fn get_activities( pub async fn get_activities(
account: &str, account: &str,
kind: &str, kind: &str,
state: State<'_, Nostr>, state: State<'_, Nostr>,
) -> Result<Vec<String>, String> { ) -> Result<Vec<String>, Error> {
let client = &state.client; let client = &state.client;
let public_key = PublicKey::from_str(account)?;
if let Ok(pubkey) = PublicKey::from_str(account) { let kind = Kind::from_str(kind)?;
if let Ok(kind) = Kind::from_str(kind) { let filter = Filter::new()
let filter = Filter::new() .pubkey(public_key)
.pubkey(pubkey) .kind(kind)
.kind(kind) .limit(100)
.limit(100) .until(Timestamp::now());
.until(Timestamp::now()); let events = client.get_events_of(vec![filter], None).await?;
Ok(events.into_iter().map(|ev| ev.as_json()).collect())
match client.get_events_of(vec![filter], None).await {
Ok(events) => Ok(events.into_iter().map(|ev| ev.as_json()).collect()),
Err(err) => Err(err.to_string()),
}
} else {
Err("Kind is not valid, please check again.".into())
}
} else {
Err("Public Key is not valid, please check again.".into())
}
} }
#[tauri::command] #[tauri::command]