feat: pow by default
This commit is contained in:
@@ -6,7 +6,7 @@ use std::{str::FromStr, time::Duration};
|
||||
use tauri::State;
|
||||
|
||||
use crate::common::{create_event_tags, filter_converstation, parse_event, Meta};
|
||||
use crate::{Nostr, FETCH_LIMIT};
|
||||
use crate::{Nostr, DEFAULT_DIFFICULTY, FETCH_LIMIT};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Type)]
|
||||
pub struct RichEvent {
|
||||
@@ -442,23 +442,13 @@ pub async fn publish(
|
||||
tags.push(tag)
|
||||
};
|
||||
|
||||
let signer = client.signer().await.map_err(|err| err.to_string())?;
|
||||
let public_key = signer.public_key().await.map_err(|err| err.to_string())?;
|
||||
|
||||
// Create unsigned event
|
||||
let unsigned_event = match difficulty {
|
||||
Some(num) => EventBuilder::text_note(content, tags)
|
||||
.pow(num)
|
||||
.to_unsigned_event(public_key),
|
||||
None => EventBuilder::text_note(content, tags).to_unsigned_event(public_key),
|
||||
};
|
||||
let builder =
|
||||
EventBuilder::text_note(content, tags).pow(difficulty.unwrap_or(DEFAULT_DIFFICULTY));
|
||||
|
||||
// Publish
|
||||
match signer.sign_event(unsigned_event).await {
|
||||
Ok(event) => match client.send_event(event).await {
|
||||
Ok(event_id) => Ok(event_id.to_bech32().map_err(|err| err.to_string())?),
|
||||
Err(err) => Err(err.to_string()),
|
||||
},
|
||||
match client.send_event_builder(builder).await {
|
||||
Ok(event_id) => Ok(event_id.to_bech32().unwrap()),
|
||||
Err(err) => Err(err.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,13 @@ pub struct Profile {
|
||||
#[specta::specta]
|
||||
pub async fn get_profile(id: Option<String>, state: State<'_, Nostr>) -> Result<String, String> {
|
||||
let client = &state.client;
|
||||
|
||||
let public_key: PublicKey = match id {
|
||||
Some(user_id) => PublicKey::parse(&user_id).map_err(|e| e.to_string())?,
|
||||
None => client.signer().await.unwrap().public_key().await.unwrap(),
|
||||
None => {
|
||||
let signer = client.signer().await.map_err(|e| e.to_string())?;
|
||||
signer.public_key().await.map_err(|e| e.to_string())?
|
||||
}
|
||||
};
|
||||
|
||||
let filter = Filter::new()
|
||||
@@ -35,10 +39,7 @@ pub async fn get_profile(id: Option<String>, state: State<'_, Nostr>) -> Result<
|
||||
.limit(1);
|
||||
|
||||
match client
|
||||
.get_events_of(
|
||||
vec![filter],
|
||||
EventSource::both(Some(Duration::from_secs(3))),
|
||||
)
|
||||
.get_events_of(vec![filter], EventSource::Database)
|
||||
.await
|
||||
{
|
||||
Ok(events) => {
|
||||
|
||||
@@ -81,6 +81,7 @@ struct Subscription {
|
||||
#[derive(Serialize, Deserialize, Type, Clone, TauriEvent)]
|
||||
struct NewSettings(Settings);
|
||||
|
||||
pub const DEFAULT_DIFFICULTY: u8 = 21;
|
||||
pub const FETCH_LIMIT: usize = 20;
|
||||
pub const NEWSFEED_NEG_LIMIT: usize = 256;
|
||||
pub const NOTIFICATION_NEG_LIMIT: usize = 64;
|
||||
|
||||
Reference in New Issue
Block a user