This commit is contained in:
2026-08-06 14:52:43 +07:00
parent 6d5d154486
commit 0c6d700395
4 changed files with 23 additions and 27 deletions
-5
View File
@@ -104,13 +104,8 @@ impl NostrBackend {
/// event is immediately visible to [`NostrBackend::query`]. /// event is immediately visible to [`NostrBackend::query`].
pub async fn send(&self, builder: EventBuilder) -> Result<Event> { pub async fn send(&self, builder: EventBuilder) -> Result<Event> {
let event = builder.finalize_async(&self.signer).await?; let event = builder.finalize_async(&self.signer).await?;
let output = self.client.send_event(&event).await?; let output = self.client.send_event(&event).await?;
// Keep our own events in the local database; the notification pump
// only fires for events received from relays.
self.client.database().save_event(&event).await?;
if output.success.is_empty() && !output.failed.is_empty() { if output.success.is_empty() && !output.failed.is_empty() {
let reasons = output let reasons = output
.failed .failed
+2 -7
View File
@@ -7,7 +7,7 @@ use nostr_sdk::prelude::*;
pub struct Update { pub struct Update {
pub kind: Kind, pub kind: Kind,
/// First `a` tag value of the event, if any (e.g. the repository coordinate). /// First `a` tag value of the event, if any (e.g. the repository coordinate).
pub coordinate: Option<String>, pub coordinate: Option<Coordinate>,
pub author: PublicKey, pub author: PublicKey,
pub event_id: EventId, pub event_id: EventId,
} }
@@ -15,12 +15,7 @@ pub struct Update {
impl Update { impl Update {
/// Build an update from a received event. /// Build an update from a received event.
pub fn from_event(event: &Event) -> Self { pub fn from_event(event: &Event) -> Self {
let coordinate = event let coordinate = event.tags.coordinates().nth(0);
.tags
.iter()
.find(|t| t.kind() == "a")
.and_then(|t| t.content())
.map(str::to_owned);
Self { Self {
kind: event.kind, kind: event.kind,
+16 -11
View File
@@ -9,7 +9,6 @@ use crate::backend::{Backend, BackendEvent};
/// their resolved statuses. Always derived from the local database. /// their resolved statuses. Always derived from the local database.
pub struct RepoStore { pub struct RepoStore {
addr: RepoAddr, addr: RepoAddr,
addr_string: String,
pub announcement: Option<Announcement>, pub announcement: Option<Announcement>,
/// `(refname, commit-id)` pairs from the latest state announcement. /// `(refname, commit-id)` pairs from the latest state announcement.
pub refs: Vec<(String, String)>, pub refs: Vec<(String, String)>,
@@ -29,20 +28,27 @@ pub struct RepoStore {
impl RepoStore { impl RepoStore {
pub fn new(addr: RepoAddr, cx: &mut Context<Self>) -> Self { pub fn new(addr: RepoAddr, cx: &mut Context<Self>) -> Self {
let addr_string = addr.to_string(); let backend = Backend::global(cx);
let subscription = cx.subscribe(&Backend::global(cx), |this, _backend, event, cx| { let subscription = cx.subscribe(&backend, |this, _backend, event, cx| {
let relevant = match event { let relevant = match event {
BackendEvent::NostrUpdate(update) => { BackendEvent::NostrUpdate(update) => {
update.coordinate.as_deref() == Some(this.addr_string.as_str()) let coordinate = update.coordinate.as_ref() == Some(&this.addr.coordinate());
|| (update.kind == Kind::GitRepoAnnouncement let author = update.author == this.addr.owner;
&& update.author == this.addr.owner) let kind = update.kind == Kind::GitRepoAnnouncement;
coordinate || (author && kind)
} }
BackendEvent::Published(event) => { BackendEvent::Published(event) => {
event.kind == Kind::GitRepoAnnouncement && event.pubkey == this.addr.owner let kind = event.kind == Kind::GitRepoAnnouncement;
|| event.tags.iter().any(|t| { let author = event.pubkey == this.addr.owner;
t.kind() == "a" && t.content() == Some(this.addr_string.as_str()) let coordinate = event
}) .tags
.coordinates()
.into_iter()
.any(|c| c == this.addr.coordinate());
coordinate || (kind && author)
} }
_ => false, _ => false,
}; };
@@ -54,7 +60,6 @@ impl RepoStore {
let mut store = Self { let mut store = Self {
addr, addr,
addr_string,
announcement: None, announcement: None,
refs: Vec::new(), refs: Vec::new(),
head: None, head: None,
+5 -4
View File
@@ -21,15 +21,16 @@ impl RepoListStore {
/// Create a store. If `author` is `None`, all announcements are listed. /// Create a store. If `author` is `None`, all announcements are listed.
pub fn new(author: Option<PublicKey>, cx: &mut Context<Self>) -> Self { pub fn new(author: Option<PublicKey>, cx: &mut Context<Self>) -> Self {
let backend = Backend::global(cx); let backend = Backend::global(cx);
let subscription = cx.subscribe(&backend, |this, _backend, event, cx| { let subscription = cx.subscribe(&backend, |this, _backend, event, cx| {
let git_kind = Kind::GitRepoAnnouncement;
let relevant = match event { let relevant = match event {
BackendEvent::NostrUpdate(update) => { BackendEvent::NostrUpdate(update) => {
update.kind == Kind::GitRepoAnnouncement update.kind == git_kind && this.author.is_none_or(|a| a == update.author)
&& this.author.is_none_or(|a| a == update.author)
} }
BackendEvent::Published(event) => { BackendEvent::Published(event) => {
event.kind == Kind::GitRepoAnnouncement event.kind == git_kind && this.author.is_none_or(|a| a == event.pubkey)
&& this.author.is_none_or(|a| a == event.pubkey)
} }
BackendEvent::Synced | BackendEvent::SyncProgress { .. } => true, BackendEvent::Synced | BackendEvent::SyncProgress { .. } => true,
_ => false, _ => false,