diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-08 11:20:35 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-08 11:23:28 +0000 |
| commit | 5d02ad6b893f9059044914c115d77cf9d8e589c3 (patch) | |
| tree | b727f9c44d2f2d4e203dc2344e4c9bd5144a77dd /src/nostr/builder.rs | |
| parent | 075307804bf66bba10f5bc55cb40e2e6a98a65ee (diff) | |
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
Diffstat (limited to 'src/nostr/builder.rs')
| -rw-r--r-- | src/nostr/builder.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index 81f7fbb..939ccef 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs | |||
| @@ -12,10 +12,7 @@ use nostr_lmdb::NostrLmdb; | |||
| 12 | use nostr_relay_builder::prelude::*; | 12 | use nostr_relay_builder::prelude::*; |
| 13 | 13 | ||
| 14 | use crate::config::{Config, DatabaseBackend}; | 14 | use crate::config::{Config, DatabaseBackend}; |
| 15 | use crate::nostr::events::{ | 15 | use crate::nostr::events::RepositoryAnnouncement; |
| 16 | RepositoryAnnouncement, KIND_PR, KIND_PR_UPDATE, KIND_REPOSITORY_ANNOUNCEMENT, | ||
| 17 | KIND_REPOSITORY_STATE, KIND_USER_GRASP_LIST, | ||
| 18 | }; | ||
| 19 | use crate::nostr::policy::{ | 16 | use crate::nostr::policy::{ |
| 20 | AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, ReferenceResult, | 17 | AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, ReferenceResult, |
| 21 | RelatedEventPolicy, StatePolicy, StateResult, | 18 | RelatedEventPolicy, StatePolicy, StateResult, |
| @@ -377,11 +374,13 @@ impl WritePolicy for Nip34WritePolicy { | |||
| 377 | // Sync uses localhost:0 as a dummy address | 374 | // Sync uses localhost:0 as a dummy address |
| 378 | let is_synced = addr.ip().is_loopback() && addr.port() == 0; | 375 | let is_synced = addr.ip().is_loopback() && addr.port() == 0; |
| 379 | 376 | ||
| 380 | match event.kind.as_u16() { | 377 | match event.kind { |
| 381 | KIND_REPOSITORY_ANNOUNCEMENT => self.handle_announcement(event).await, | 378 | Kind::GitRepoAnnouncement => self.handle_announcement(event).await, |
| 382 | KIND_REPOSITORY_STATE => self.handle_state(event, is_synced).await, | 379 | Kind::RepoState => self.handle_state(event, is_synced).await, |
| 383 | KIND_PR | KIND_PR_UPDATE => self.handle_pr_event(event, is_synced).await, | 380 | Kind::GitPullRequest | Kind::GitPullRequestUpdate => { |
| 384 | KIND_USER_GRASP_LIST => { | 381 | self.handle_pr_event(event, is_synced).await |
| 382 | } | ||
| 383 | Kind::GitUserGraspList => { | ||
| 385 | // Accept all kind 10317 (User Grasp List) events | 384 | // Accept all kind 10317 (User Grasp List) events |
| 386 | // for better GRASP repository discovery | 385 | // for better GRASP repository discovery |
| 387 | tracing::debug!( | 386 | tracing::debug!( |