lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

commit 33e813eeb2f969227deb875a94833c2361febaed
parent 2e0bc517499df7efebda9eaf6a25ca82038daec2
Author: triesap <tyson@radroots.org>
Date:   Wed, 24 Dec 2025 23:29:28 +0000

nostr: unify post event sending and filtering


- Replace direct send_event_builder calls with radroots_nostr_send_event
- Return event ID from profile metadata publish
- Introduce shared post events filter helper
- Reuse post filter across manager and fetch paths

Diffstat:
Mnet-core/src/nostr_client/events/post.rs | 11+++--------
Mnet-core/src/nostr_client/events/profile.rs | 8++++----
Mnet-core/src/nostr_client/manager.rs | 9+++------
Mnostr/src/events/post.rs | 27++++++++++++++++++---------
Mnostr/src/lib.rs | 1+
5 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/net-core/src/nostr_client/events/post.rs b/net-core/src/nostr_client/events/post.rs @@ -4,6 +4,7 @@ use radroots_nostr::prelude::{ radroots_nostr_build_post_event, radroots_nostr_build_post_reply_event, radroots_nostr_fetch_post_events, + radroots_nostr_send_event, }; use crate::nostr_client::manager::NostrClientManager; @@ -11,10 +12,7 @@ use crate::nostr_client::manager::NostrClientManager; impl NostrClientManager { pub async fn publish_post_event(&self, content: String) -> Result<String> { let builder = radroots_nostr_build_post_event(content); - let out = self - .inner - .client - .send_event_builder(builder) + let out = radroots_nostr_send_event(&self.inner.client, builder) .await .map_err(|e| NetError::Msg(e.to_string()))?; Ok(out.val.to_string()) @@ -41,10 +39,7 @@ impl NostrClientManager { ) .map_err(|e| NetError::Msg(e.to_string()))?; - let out = self - .inner - .client - .send_event_builder(builder) + let out = radroots_nostr_send_event(&self.inner.client, builder) .await .map_err(|e| NetError::Msg(e.to_string()))?; diff --git a/net-core/src/nostr_client/events/profile.rs b/net-core/src/nostr_client/events/profile.rs @@ -50,7 +50,7 @@ impl NostrClientManager { ) -> Result<String> { let rt = self.inner.rt.clone(); let inner_for_task = self.inner.clone(); - rt.block_on(async move { + let event_id = rt.block_on(async move { let mut md = RadrootsNostrMetadata::new(); if let Some(v) = name { md = md.name(v); @@ -64,11 +64,11 @@ impl NostrClientManager { if let Some(v) = about { md = md.about(v); } - let _ = radroots_nostr_post_metadata_event(&inner_for_task.client, &md) + let out = radroots_nostr_post_metadata_event(&inner_for_task.client, &md) .await .map_err(|e| NetError::Msg(e.to_string()))?; - Ok::<(), NetError>(()) + Ok::<String, NetError>(out.val.to_string()) })?; - Ok("ok".to_string()) + Ok(event_id) } } diff --git a/net-core/src/nostr_client/manager.rs b/net-core/src/nostr_client/manager.rs @@ -3,10 +3,9 @@ use tokio::runtime::Handle; use super::inner::Inner; use radroots_nostr::prelude::{ - RadrootsNostrFilter, - RadrootsNostrKind, RadrootsNostrKeys, RadrootsNostrTimestamp, + radroots_nostr_post_events_filter, }; #[derive(Clone)] @@ -44,11 +43,9 @@ impl NostrClientManager { async move { use futures::StreamExt; - let mut since = since_unix.unwrap_or_else(|| RadrootsNostrTimestamp::now().as_u64()); + let mut since = since_unix.unwrap_or_else(|| RadrootsNostrTimestamp::now().as_u64()); loop { - let filter = RadrootsNostrFilter::new() - .kind(RadrootsNostrKind::TextNote) - .since(RadrootsNostrTimestamp::from(since)); + let filter = radroots_nostr_post_events_filter(None, Some(since)); let mut stream = match inner .client diff --git a/nostr/src/events/post.rs b/nostr/src/events/post.rs @@ -2,21 +2,36 @@ use crate::error::RadrootsNostrError; use crate::types::{ RadrootsNostrEventBuilder, RadrootsNostrEventId, + RadrootsNostrFilter, + RadrootsNostrKind, RadrootsNostrPublicKey, RadrootsNostrTag, + RadrootsNostrTimestamp, }; #[cfg(all(feature = "client", feature = "events"))] use core::time::Duration; #[cfg(all(feature = "client", feature = "events"))] use crate::client::RadrootsNostrClient; -#[cfg(all(feature = "client", feature = "events"))] -use crate::types::{RadrootsNostrFilter, RadrootsNostrKind, RadrootsNostrTimestamp}; pub fn radroots_nostr_build_post_event(content: impl Into<String>) -> RadrootsNostrEventBuilder { RadrootsNostrEventBuilder::text_note(content) } +pub fn radroots_nostr_post_events_filter( + limit: Option<u16>, + since_unix: Option<u64>, +) -> RadrootsNostrFilter { + let mut filter = RadrootsNostrFilter::new().kind(RadrootsNostrKind::TextNote); + if let Some(limit) = limit { + filter = filter.limit(limit.into()); + } + if let Some(since) = since_unix { + filter = filter.since(RadrootsNostrTimestamp::from(since)); + } + filter +} + pub fn radroots_nostr_build_post_reply_event( parent_event_id_hex: &str, parent_author_hex: &str, @@ -47,13 +62,7 @@ pub async fn radroots_nostr_fetch_post_events( limit: u16, since_unix: Option<u64>, ) -> Result<Vec<radroots_events::post::RadrootsPostEventMetadata>, RadrootsNostrError> { - let mut filter = RadrootsNostrFilter::new() - .kind(RadrootsNostrKind::TextNote) - .limit(limit.into()); - - if let Some(s) = since_unix { - filter = filter.since(RadrootsNostrTimestamp::from(s)); - } + let filter = radroots_nostr_post_events_filter(Some(limit), since_unix); let events = client.fetch_events(filter, Duration::from_secs(10)).await?; let out = events diff --git a/nostr/src/lib.rs b/nostr/src/lib.rs @@ -56,6 +56,7 @@ pub mod prelude { post::{ radroots_nostr_build_post_event, radroots_nostr_build_post_reply_event, + radroots_nostr_post_events_filter, }, };