clean up
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user