feat: add search window (NIP-50) (#181)

* feat: add search window
* chore: improve search ui
This commit is contained in:
雨宮蓮
2024-04-23 15:34:08 +07:00
committed by GitHub
parent c00a7749b4
commit 174a3cc74e
22 changed files with 507 additions and 236 deletions

View File

@@ -221,3 +221,26 @@ pub async fn repost(raw: &str, state: State<'_, Nostr>) -> Result<EventId, Strin
Err("Repost failed".into())
}
}
#[tauri::command]
pub async fn search(
content: &str,
limit: usize,
state: State<'_, Nostr>,
) -> Result<Vec<Event>, String> {
println!("search: {}", content);
let client = &state.client;
let filter = Filter::new()
.kinds(vec![Kind::TextNote, Kind::Metadata])
.search(content)
.limit(limit);
match client
.get_events_of(vec![filter], Some(Duration::from_secs(15)))
.await
{
Ok(events) => Ok(events),
Err(err) => Err(err.to_string()),
}
}