Skip to main content

nmp_threading/
pointer.rs

1//! `ThreadPointer` — what a reply / comment is anchored to.
2//!
3//! Three variants cover every NIP-10 / NIP-22 anchor shape: a Nostr event id,
4//! a parameterized-replaceable address, or an external URI.
5
6use serde::{Deserialize, Serialize};
7
8/// Anchor for a reply / comment. Address and External variants terminate
9/// ancestor-walk: there is no event id to hydrate.
10#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
11pub enum ThreadPointer {
12    Event {
13        id: String,
14        #[serde(default, skip_serializing_if = "Option::is_none")]
15        relay: Option<String>,
16        #[serde(default, skip_serializing_if = "Option::is_none")]
17        kind: Option<u32>,
18    },
19    Address {
20        coord: String,
21        #[serde(default, skip_serializing_if = "Option::is_none")]
22        relay: Option<String>,
23        #[serde(default, skip_serializing_if = "Option::is_none")]
24        kind: Option<u32>,
25    },
26    External {
27        uri: String,
28    },
29}
30
31impl ThreadPointer {
32    /// Event id when this pointer names a specific event; `None` for
33    /// `Address` and `External` (they terminate ancestor-walk).
34    #[must_use]
35    pub fn event_id(&self) -> Option<&str> {
36        match self {
37            Self::Event { id, .. } => Some(id.as_str()),
38            _ => None,
39        }
40    }
41}