feat: child webview

This commit is contained in:
2024-03-16 15:05:06 +07:00
parent 16e6d234e5
commit 46cc01e0ee
37 changed files with 1686 additions and 1403 deletions

View File

@@ -171,43 +171,37 @@ pub async fn publish(
}
#[tauri::command]
pub async fn repost(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
pub async fn repost(raw: &str, state: State<'_, Nostr>) -> Result<EventId, String> {
let client = &state.client;
let public_key = PublicKey::from_str(pubkey).unwrap();
let event_id = EventId::from_hex(id).unwrap();
let event = Event::from_json(raw).unwrap();
let event = client
.repost_event(event_id, public_key)
.await
.expect("Repost failed");
Ok(event)
if let Ok(event_id) = client.repost(&event, None).await {
Ok(event_id)
} else {
Err("Repost failed".into())
}
}
#[tauri::command]
pub async fn upvote(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
pub async fn upvote(raw: &str, state: State<'_, Nostr>) -> Result<EventId, String> {
let client = &state.client;
let public_key = PublicKey::from_str(pubkey).unwrap();
let event_id = EventId::from_hex(id).unwrap();
let event = Event::from_json(raw).unwrap();
let event = client
.like(event_id, public_key)
.await
.expect("Upvote failed");
Ok(event)
if let Ok(event_id) = client.like(&event).await {
Ok(event_id)
} else {
Err("Upvote failed".into())
}
}
#[tauri::command]
pub async fn downvote(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
pub async fn downvote(raw: &str, state: State<'_, Nostr>) -> Result<EventId, String> {
let client = &state.client;
let public_key = PublicKey::from_str(pubkey).unwrap();
let event_id = EventId::from_hex(id).unwrap();
let event = Event::from_json(raw).unwrap();
let event = client
.dislike(event_id, public_key)
.await
.expect("Downvote failed");
Ok(event)
if let Ok(event_id) = client.dislike(&event).await {
Ok(event_id)
} else {
Err("Downvote failed".into())
}
}

View File

@@ -161,7 +161,7 @@ pub fn event_to_bech32(id: &str, relays: Vec<String>) -> Result<String, ()> {
#[tauri::command]
pub fn user_to_bech32(key: &str, relays: Vec<String>) -> Result<String, ()> {
let pubkey = PublicKey::from_str(key).unwrap();
let profile = Nip19Profile::new(pubkey, relays);
let profile = Nip19Profile::new(pubkey, relays).unwrap();
Ok(profile.to_bech32().unwrap())
}