feat: editor

This commit is contained in:
2024-02-26 15:10:42 +07:00
parent 63db8b1423
commit 98ef1927f2
12 changed files with 256 additions and 135 deletions

View File

@@ -98,6 +98,7 @@ fn main() {
nostr::keys::verify_nip05,
nostr::metadata::get_profile,
nostr::metadata::get_contact_list,
nostr::metadata::get_contact_metadata,
nostr::metadata::create_profile,
nostr::metadata::follow,
nostr::metadata::unfollow,
@@ -110,7 +111,6 @@ fn main() {
nostr::event::get_global_events,
nostr::event::get_event_thread,
nostr::event::publish,
nostr::event::reply_to,
nostr::event::repost,
nostr::event::upvote,
nostr::event::downvote,

View File

@@ -137,25 +137,6 @@ pub async fn publish(
}
}
#[tauri::command]
pub async fn reply_to(
content: &str,
tags: Vec<String>,
state: State<'_, Nostr>,
) -> Result<EventId, String> {
let client = &state.client;
if let Ok(event_tags) = Tag::parse(tags) {
let event = client
.publish_text_note(content, vec![event_tags])
.await
.expect("Publish reply failed");
Ok(event)
} else {
Err("Reply failed".into())
}
}
#[tauri::command]
pub async fn repost(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
let client = &state.client;

View File

@@ -3,6 +3,12 @@ use nostr_sdk::prelude::*;
use std::{str::FromStr, time::Duration};
use tauri::State;
#[derive(serde::Serialize)]
pub struct CacheContact {
pubkey: String,
profile: Metadata,
}
#[tauri::command]
pub async fn get_profile(id: &str, state: State<'_, Nostr>) -> Result<Metadata, String> {
let client = &state.client;
@@ -46,11 +52,36 @@ pub async fn get_profile(id: &str, state: State<'_, Nostr>) -> Result<Metadata,
#[tauri::command]
pub async fn get_contact_list(state: State<'_, Nostr>) -> Result<Vec<String>, String> {
let client = &state.client;
let contact_list = client.get_contact_list(Some(Duration::from_secs(10))).await;
if let Ok(list) = contact_list {
let v = list.into_iter().map(|f| f.public_key.to_hex()).collect();
Ok(v)
if let Ok(contact_list) = client.get_contact_list(Some(Duration::from_secs(10))).await {
let list = contact_list
.into_iter()
.map(|f| f.public_key.to_hex())
.collect();
Ok(list)
} else {
Err("Contact list not found".into())
}
}
#[tauri::command]
pub async fn get_contact_metadata(state: State<'_, Nostr>) -> Result<Vec<CacheContact>, String> {
let client = &state.client;
if let Ok(contact_list) = client
.get_contact_list_metadata(Some(Duration::from_secs(10)))
.await
{
let list: Vec<CacheContact> = contact_list
.into_iter()
.map(|(id, metadata)| CacheContact {
pubkey: id.to_hex(),
profile: metadata,
})
.collect();
Ok(list)
} else {
Err("Contact list not found".into())
}