feat: support nip-36

This commit is contained in:
2024-04-16 07:49:44 +07:00
parent 09b143cb08
commit 94d400cab2
16 changed files with 253 additions and 150 deletions

View File

@@ -222,16 +222,15 @@ pub async fn get_event_thread(id: &str, state: State<'_, Nostr>) -> Result<Vec<E
#[tauri::command]
pub async fn publish(
content: &str,
tags: Vec<Vec<String>>,
tags: Vec<Vec<&str>>,
state: State<'_, Nostr>,
) -> Result<String, String> {
let client = &state.client;
let final_tags = tags.into_iter().map(|val| Tag::parse(&val).unwrap());
if let Ok(event_id) = client.publish_text_note(content, final_tags).await {
Ok(event_id.to_bech32().unwrap())
} else {
Err("Publish text note failed".into())
match client.publish_text_note(content, final_tags).await {
Ok(event_id) => Ok(event_id.to_bech32().unwrap()),
Err(err) => Err(err.to_string()),
}
}
@@ -246,27 +245,3 @@ pub async fn repost(raw: &str, state: State<'_, Nostr>) -> Result<EventId, Strin
Err("Repost failed".into())
}
}
#[tauri::command]
pub async fn upvote(raw: &str, state: State<'_, Nostr>) -> Result<EventId, String> {
let client = &state.client;
let event = Event::from_json(raw).unwrap();
if let Ok(event_id) = client.like(&event).await {
Ok(event_id)
} else {
Err("Upvote failed".into())
}
}
#[tauri::command]
pub async fn downvote(raw: &str, state: State<'_, Nostr>) -> Result<EventId, String> {
let client = &state.client;
let event = Event::from_json(raw).unwrap();
if let Ok(event_id) = client.dislike(&event).await {
Ok(event_id)
} else {
Err("Downvote failed".into())
}
}