diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-07-31 16:28:04 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-07-31 16:38:45 +0100 |
| commit | 436ff29135e3deade80a6e53e53d74dddb613481 (patch) | |
| tree | 53c086492fd710f9f289c756ec511f8b3d3819f3 /src | |
| parent | 9d4adb9afd591ccef8827902034378acd700c6f8 (diff) | |
fix: mention marker ~> q tag NIP-10 update
required for rust-nostr v0.43 update
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 4 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/send.rs | 23 | ||||
| -rw-r--r-- | src/lib/git_events.rs | 38 |
3 files changed, 46 insertions, 19 deletions
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 73d76b4..9ba7c30 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -1209,12 +1209,10 @@ async fn create_merge_status( | |||
| 1209 | merged_patches | 1209 | merged_patches |
| 1210 | .iter() | 1210 | .iter() |
| 1211 | .map(|merged_patch| { | 1211 | .map(|merged_patch| { |
| 1212 | Tag::from_standardized(nostr::TagStandard::Event { | 1212 | Tag::from_standardized(nostr::TagStandard::Quote { |
| 1213 | event_id: *merged_patch, | 1213 | event_id: *merged_patch, |
| 1214 | relay_url: repo_ref.relays.first().cloned(), | 1214 | relay_url: repo_ref.relays.first().cloned(), |
| 1215 | marker: Some(Marker::Mention), | ||
| 1216 | public_key: None, | 1215 | public_key: None, |
| 1217 | uppercase: false, | ||
| 1218 | }) | 1216 | }) |
| 1219 | }) | 1217 | }) |
| 1220 | .collect::<Vec<Tag>>(), | 1218 | .collect::<Vec<Tag>>(), |
diff --git a/src/bin/ngit/sub_commands/send.rs b/src/bin/ngit/sub_commands/send.rs index c84e339..8b49e37 100644 --- a/src/bin/ngit/sub_commands/send.rs +++ b/src/bin/ngit/sub_commands/send.rs | |||
| @@ -4,12 +4,9 @@ use anyhow::{Context, Result, bail}; | |||
| 4 | use console::Style; | 4 | use console::Style; |
| 5 | use ngit::{ | 5 | use ngit::{ |
| 6 | client::{Params, send_events}, | 6 | client::{Params, send_events}, |
| 7 | git_events::generate_cover_letter_and_patch_events, | 7 | git_events::{EventRefType, generate_cover_letter_and_patch_events}, |
| 8 | }; | ||
| 9 | use nostr::{ | ||
| 10 | ToBech32, | ||
| 11 | nips::{nip10::Marker, nip19::Nip19Event}, | ||
| 12 | }; | 8 | }; |
| 9 | use nostr::{ToBech32, nips::nip19::Nip19Event}; | ||
| 13 | use nostr_sdk::hashes::sha1::Hash as Sha1Hash; | 10 | use nostr_sdk::hashes::sha1::Hash as Sha1Hash; |
| 14 | 11 | ||
| 15 | use crate::{ | 12 | use crate::{ |
| @@ -368,7 +365,7 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to( | |||
| 368 | in_reply_to: &[String], | 365 | in_reply_to: &[String], |
| 369 | ) -> Result<(Option<String>, Vec<nostr::Tag>)> { | 366 | ) -> Result<(Option<String>, Vec<nostr::Tag>)> { |
| 370 | let root_proposal_id = if let Some(first) = in_reply_to.first() { | 367 | let root_proposal_id = if let Some(first) = in_reply_to.first() { |
| 371 | match event_tag_from_nip19_or_hex(first, "in-reply-to", Marker::Root, true, false)? | 368 | match event_tag_from_nip19_or_hex(first, "in-reply-to", EventRefType::Root, true, false)? |
| 372 | .as_standardized() | 369 | .as_standardized() |
| 373 | { | 370 | { |
| 374 | Some(nostr_sdk::TagStandard::Event { | 371 | Some(nostr_sdk::TagStandard::Event { |
| @@ -404,10 +401,16 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to( | |||
| 404 | for (i, reply_to) in in_reply_to.iter().enumerate() { | 401 | for (i, reply_to) in in_reply_to.iter().enumerate() { |
| 405 | if i.ne(&0) || root_proposal_id.is_none() { | 402 | if i.ne(&0) || root_proposal_id.is_none() { |
| 406 | mention_tags.push( | 403 | mention_tags.push( |
| 407 | event_tag_from_nip19_or_hex(reply_to, "in-reply-to", Marker::Mention, true, false) | 404 | event_tag_from_nip19_or_hex( |
| 408 | .context(format!( | 405 | reply_to, |
| 409 | "{reply_to} in 'in-reply-to' not a valid nostr reference" | 406 | "in-reply-to", |
| 410 | ))?, | 407 | EventRefType::Quote, |
| 408 | true, | ||
| 409 | false, | ||
| 410 | ) | ||
| 411 | .context(format!( | ||
| 412 | "{reply_to} in 'in-reply-to' not a valid nostr reference" | ||
| 413 | ))?, | ||
| 411 | ); | 414 | ); |
| 412 | } | 415 | } |
| 413 | } | 416 | } |
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index 2e1f215..79f5772 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs | |||
| @@ -184,7 +184,7 @@ pub async fn generate_patch_event( | |||
| 184 | event_tag_from_nip19_or_hex( | 184 | event_tag_from_nip19_or_hex( |
| 185 | &event_ref, | 185 | &event_ref, |
| 186 | "proposal", | 186 | "proposal", |
| 187 | Marker::Reply, | 187 | EventRefType::Reply, |
| 188 | false, | 188 | false, |
| 189 | false, | 189 | false, |
| 190 | )?, | 190 | )?, |
| @@ -277,10 +277,17 @@ pub async fn generate_patch_event( | |||
| 277 | .context("failed to sign event") | 277 | .context("failed to sign event") |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | #[derive(Debug, PartialEq)] | ||
| 281 | pub enum EventRefType { | ||
| 282 | Root, | ||
| 283 | Reply, | ||
| 284 | Quote, | ||
| 285 | } | ||
| 286 | |||
| 280 | pub fn event_tag_from_nip19_or_hex( | 287 | pub fn event_tag_from_nip19_or_hex( |
| 281 | reference: &str, | 288 | reference: &str, |
| 282 | reference_name: &str, | 289 | reference_name: &str, |
| 283 | marker: Marker, | 290 | ref_type: EventRefType, |
| 284 | allow_npub_reference: bool, | 291 | allow_npub_reference: bool, |
| 285 | prompt_for_correction: bool, | 292 | prompt_for_correction: bool, |
| 286 | ) -> Result<nostr::Tag> { | 293 | ) -> Result<nostr::Tag> { |
| @@ -291,22 +298,41 @@ pub fn event_tag_from_nip19_or_hex( | |||
| 291 | PromptInputParms::default().with_prompt(format!("{reference_name} reference")), | 298 | PromptInputParms::default().with_prompt(format!("{reference_name} reference")), |
| 292 | )?; | 299 | )?; |
| 293 | } | 300 | } |
| 301 | let marker = match ref_type { | ||
| 302 | EventRefType::Root => Some(Marker::Root), | ||
| 303 | EventRefType::Reply => Some(Marker::Reply), | ||
| 304 | EventRefType::Quote => None, | ||
| 305 | }; | ||
| 294 | if let Ok(nip19) = Nip19::from_bech32(&bech32) { | 306 | if let Ok(nip19) = Nip19::from_bech32(&bech32) { |
| 295 | match nip19 { | 307 | match nip19 { |
| 296 | Nip19::Event(n) => { | 308 | Nip19::Event(n) => { |
| 309 | if ref_type == EventRefType::Quote { | ||
| 310 | break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Quote { | ||
| 311 | event_id: n.event_id, | ||
| 312 | relay_url: n.relays.first().cloned(), | ||
| 313 | public_key: None, | ||
| 314 | })); | ||
| 315 | } | ||
| 297 | break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event { | 316 | break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event { |
| 298 | event_id: n.event_id, | 317 | event_id: n.event_id, |
| 299 | relay_url: n.relays.first().cloned(), | 318 | relay_url: n.relays.first().cloned(), |
| 300 | marker: Some(marker), | 319 | marker, |
| 301 | public_key: None, | 320 | public_key: None, |
| 302 | uppercase: false, | 321 | uppercase: false, |
| 303 | })); | 322 | })); |
| 304 | } | 323 | } |
| 305 | Nip19::EventId(id) => { | 324 | Nip19::EventId(id) => { |
| 325 | if ref_type == EventRefType::Quote { | ||
| 326 | break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Quote { | ||
| 327 | event_id: id, | ||
| 328 | relay_url: None, | ||
| 329 | public_key: None, | ||
| 330 | })); | ||
| 331 | } | ||
| 306 | break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event { | 332 | break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event { |
| 307 | event_id: id, | 333 | event_id: id, |
| 308 | relay_url: None, | 334 | relay_url: None, |
| 309 | marker: Some(marker), | 335 | marker, |
| 310 | public_key: None, | 336 | public_key: None, |
| 311 | uppercase: false, | 337 | uppercase: false, |
| 312 | })); | 338 | })); |
| @@ -335,7 +361,7 @@ pub fn event_tag_from_nip19_or_hex( | |||
| 335 | break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event { | 361 | break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event { |
| 336 | event_id: id, | 362 | event_id: id, |
| 337 | relay_url: None, | 363 | relay_url: None, |
| 338 | marker: Some(marker), | 364 | marker, |
| 339 | public_key: None, | 365 | public_key: None, |
| 340 | uppercase: false, | 366 | uppercase: false, |
| 341 | })); | 367 | })); |
| @@ -574,7 +600,7 @@ pub async fn generate_cover_letter_and_patch_events( | |||
| 574 | Tag::hashtag("root"), | 600 | Tag::hashtag("root"), |
| 575 | Tag::hashtag("revision-root"), | 601 | Tag::hashtag("revision-root"), |
| 576 | // TODO check if id is for a root proposal (perhaps its for an issue?) | 602 | // TODO check if id is for a root proposal (perhaps its for an issue?) |
| 577 | event_tag_from_nip19_or_hex(&event_ref,"proposal",Marker::Reply, false, false)?, | 603 | event_tag_from_nip19_or_hex(&event_ref,"proposal",EventRefType::Reply, false, false)?, |
| 578 | ] | 604 | ] |
| 579 | } else { | 605 | } else { |
| 580 | vec![ | 606 | vec![ |