From 5d02ad6b893f9059044914c115d77cf9d8e589c3 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 8 Jan 2026 11:20:35 +0000 Subject: refactor: replace hardcoded Kind constants with rust-nostr variants - Replace KIND_REPOSITORY_ANNOUNCEMENT with Kind::GitRepoAnnouncement - Replace KIND_REPOSITORY_STATE with Kind::RepoState - Replace KIND_PR with Kind::GitPullRequest - Replace KIND_PR_UPDATE with Kind::GitPullRequestUpdate - Replace KIND_USER_GRASP_LIST with Kind::GitUserGraspList - Replace KIND_PATCH with Kind::GitPatch - Replace KIND_ISSUE with Kind::GitIssue - Replace KIND_COMMENT with Kind::Comment - Replace all Kind::Custom(30617|30618|1617|1618|1619|1621|1111|10317) patterns - Remove all hardcoded KIND_* constants from events.rs - Update all match statements to use Kind enum directly - Update all filter builders to use Kind variants - Update all test helpers and assertions Benefits: - Type safety: compiler prevents wrong kind numbers - Readability: Kind::GitRepoAnnouncement is self-documenting - Maintainability: single source of truth (rust-nostr) - IDE support: full autocompletion and refactoring - Standards: aligns with rust-nostr best practices Files modified: 21 Constants removed: 9 Patterns replaced: 100+ Tests passing: 222/222 --- src/sync/filters.rs | 6 +++--- src/sync/self_subscriber.rs | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/sync') diff --git a/src/sync/filters.rs b/src/sync/filters.rs index dddc49c..c4e20e7 100644 --- a/src/sync/filters.rs +++ b/src/sync/filters.rs @@ -20,9 +20,9 @@ use nostr_sdk::prelude::*; /// Note: 10317 (User Grasp List) is synced for better GRASP discovery. pub fn build_announcement_filter(since: Option) -> Filter { let filter = Filter::new().kinds([ - Kind::Custom(30617), // Repository announcements - Kind::Custom(30618), // Maintainer lists - Kind::Custom(10317), // User Grasp List + Kind::GitRepoAnnouncement, // Repository announcements + Kind::RepoState, // Repository state + Kind::GitUserGraspList, // User Grasp List ]); match since { diff --git a/src/sync/self_subscriber.rs b/src/sync/self_subscriber.rs index 09e3b56..9f6fa70 100644 --- a/src/sync/self_subscriber.rs +++ b/src/sync/self_subscriber.rs @@ -149,7 +149,7 @@ impl SelfSubscriber { match notification { Ok(RelayPoolNotification::Event { event, .. }) => { // Only process 30617 events that list our relay - if event.kind == Kind::Custom(30617) { + if event.kind == Kind::GitRepoAnnouncement { if !self.lists_our_relay(&event) { return LoopControl::Continue; } @@ -236,7 +236,7 @@ impl SelfSubscriber { /// Format: 30617:pubkey:identifier fn extract_repo_id(event: &Event) -> Option { // For kind 30617, extract d tag and build addressable ref - if event.kind == Kind::Custom(30617) { + if event.kind == Kind::GitRepoAnnouncement { for tag in event.tags.iter() { let tag_vec = tag.as_slice(); if tag_vec.len() >= 2 && tag_vec[0] == "d" { @@ -296,21 +296,21 @@ impl SelfSubscriber { ); Filter::new() .kinds(vec![ - Kind::Custom(30617), // Repository Announcements - Kind::Custom(1617), // Patches - Kind::Custom(1621), // Issues - Kind::Custom(1618), // Pull Requests - Kind::Custom(10317), // User Grasp List + Kind::GitRepoAnnouncement, // Repository Announcements + Kind::GitPatch, // Patches + Kind::GitIssue, // Issues + Kind::GitPullRequest, // Pull Requests + Kind::GitUserGraspList, // User Grasp List ]) .since(since) } else { // First connection - no since filter Filter::new().kinds(vec![ - Kind::Custom(30617), // Repository Announcements - Kind::Custom(1617), // Patches - Kind::Custom(1621), // Issues - Kind::Custom(1618), // Pull Requests - Kind::Custom(10317), // User Grasp List + Kind::GitRepoAnnouncement, // Repository Announcements + Kind::GitPatch, // Patches + Kind::GitIssue, // Issues + Kind::GitPullRequest, // Pull Requests + Kind::GitUserGraspList, // User Grasp List ]) }; -- cgit v1.2.3