This commit is contained in:
2026-08-04 15:22:18 +07:00
parent 5c005e281d
commit 8707e71b53
7 changed files with 214 additions and 121 deletions
-1
View File
@@ -12,7 +12,6 @@ nostr-sdk.workspace = true
nostr-connect.workspace = true
nostr-gossip-memory.workspace = true
flume.workspace = true
anyhow.workspace = true
webbrowser.workspace = true
+2 -2
View File
@@ -1,7 +1,7 @@
mod backend;
pub mod pump;
mod signer;
mod update;
pub use backend::NostrBackend;
pub use pump::Update;
pub use signer::{SignedAuthUrlHandler, UniversalSigner};
pub use update::Update;
@@ -1,4 +1,3 @@
use flume::Sender;
use nostr_sdk::prelude::*;
/// A lightweight "something changed" signal for the UI.
@@ -13,18 +12,9 @@ pub struct Update {
pub event_id: EventId,
}
/// Consume the client notification stream and forward [`Update`]s into `tx`
/// until the receiving end is dropped or the client shuts down.
///
/// Spawn this once, e.g. inside `cx.background_spawn`.
pub async fn run(client: Client, tx: Sender<Update>) {
let mut notifications = client.notifications();
while let Some(notification) = notifications.next().await {
let ClientNotification::Event { event, .. } = notification else {
continue;
};
impl Update {
/// Build an update from a received event.
pub fn from_event(event: &Event) -> Self {
let coordinate = event
.tags
.iter()
@@ -32,15 +22,11 @@ pub async fn run(client: Client, tx: Sender<Update>) {
.and_then(|t| t.content())
.map(str::to_owned);
let update = Update {
Self {
kind: event.kind,
coordinate,
author: event.pubkey,
event_id: event.id,
};
if tx.send_async(update).await.is_err() {
break;
}
}
}