@@ -66,6 +66,7 @@ pub enum IssueStatus {
|
||||
|
||||
impl IssueStatus {
|
||||
/// Maps the issue status to its corresponding Nostr kind.
|
||||
#[inline]
|
||||
pub fn kind(&self) -> Kind {
|
||||
match self {
|
||||
Self::Open => Kind::GitStatusOpen,
|
||||
@@ -75,16 +76,19 @@ impl IssueStatus {
|
||||
}
|
||||
|
||||
/// Check if the issue is open.
|
||||
#[inline]
|
||||
pub fn is_open(&self) -> bool {
|
||||
matches!(self, Self::Open)
|
||||
}
|
||||
|
||||
/// Check if the issue is resolved.
|
||||
#[inline]
|
||||
pub fn is_resolved(&self) -> bool {
|
||||
matches!(self, Self::Resolved)
|
||||
}
|
||||
|
||||
/// Check if the issue is closed.
|
||||
#[inline]
|
||||
pub fn is_closed(&self) -> bool {
|
||||
matches!(self, Self::Closed)
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ pub enum PatchStatus {
|
||||
|
||||
impl PatchStatus {
|
||||
/// Maps the issue status to its corresponding Nostr kind.
|
||||
#[inline]
|
||||
pub fn kind(&self) -> Kind {
|
||||
match self {
|
||||
Self::Open => Kind::GitStatusOpen,
|
||||
@@ -115,21 +116,25 @@ impl PatchStatus {
|
||||
}
|
||||
|
||||
/// Check if the patch is open.
|
||||
#[inline]
|
||||
pub fn is_open(&self) -> bool {
|
||||
matches!(self, Self::Open)
|
||||
}
|
||||
|
||||
/// Check if the patch is merged/applied.
|
||||
#[inline]
|
||||
pub fn is_merged_or_applied(&self) -> bool {
|
||||
matches!(self, Self::MergedApplied)
|
||||
}
|
||||
|
||||
/// Check if the patch is closed.
|
||||
#[inline]
|
||||
pub fn is_closed(&self) -> bool {
|
||||
matches!(self, Self::Closed)
|
||||
}
|
||||
|
||||
/// Check if the patch is drafted
|
||||
#[inline]
|
||||
pub fn is_drafted(&self) -> bool {
|
||||
matches!(self, Self::Draft)
|
||||
}
|
||||
|
||||
@@ -37,12 +37,14 @@ use crate::error::{N34Error, N34Result};
|
||||
#[easy_ext::ext(TagsExt)]
|
||||
impl Tags {
|
||||
/// Search for the given tag and map it value to a function
|
||||
#[inline]
|
||||
pub fn map_tag<T>(&self, kind: TagKind, f: impl FnOnce(&TagStandard) -> T) -> Option<T> {
|
||||
self.find_standardized(kind).map(f)
|
||||
}
|
||||
|
||||
/// Search for the given tag and map it value to a function. If the tag not
|
||||
/// found return the default `T`
|
||||
#[inline]
|
||||
pub fn dmap_tag<T>(&self, kind: TagKind, f: impl FnOnce(&TagStandard) -> T) -> T
|
||||
where
|
||||
T: Default,
|
||||
@@ -52,6 +54,7 @@ impl Tags {
|
||||
|
||||
/// Finds the first standard tag of the given kind with the specified
|
||||
/// marker, then applies the function to the tag and returns the result.
|
||||
#[inline]
|
||||
pub fn map_marker<T>(
|
||||
&self,
|
||||
kind: TagKind,
|
||||
@@ -148,6 +151,7 @@ impl EventBuilder {
|
||||
impl Token<'_> {
|
||||
/// Returns `Some((public_key, relays))` from the givin token if it's npub1
|
||||
/// or nprofile1
|
||||
#[inline]
|
||||
pub fn extract_public_key(&self) -> Option<(PublicKey, Vec<RelayUrl>)> {
|
||||
match self {
|
||||
Token::Nostr(nip21) => {
|
||||
@@ -163,6 +167,7 @@ impl Token<'_> {
|
||||
|
||||
/// Returns `Some((note_id, relays))` from the givin token if it's note1 or
|
||||
/// nevent1
|
||||
#[inline]
|
||||
pub fn extract_event_id(&self) -> Option<(EventId, Vec<RelayUrl>)> {
|
||||
match self {
|
||||
Token::Nostr(nip21) => {
|
||||
@@ -177,6 +182,7 @@ impl Token<'_> {
|
||||
}
|
||||
|
||||
/// Returns `Some(hashtag)` from the givin token if it's a hashtag
|
||||
#[inline]
|
||||
pub fn extract_hashtag(&self) -> Option<String> {
|
||||
match self {
|
||||
Token::Hashtag(tag) => Some(tag.trim().to_owned()),
|
||||
@@ -189,16 +195,19 @@ impl Token<'_> {
|
||||
#[easy_ext::ext(NaddrsUtils)]
|
||||
impl Vec<Nip19Coordinate> {
|
||||
/// Converts these coordinate addresses to basic coordinates
|
||||
#[inline]
|
||||
pub fn into_coordinates(self) -> Vec<Coordinate> {
|
||||
self.into_iter().map(|n| n.coordinate).collect()
|
||||
}
|
||||
|
||||
/// Returns all repository owners' public keys from these coordinates.
|
||||
#[inline]
|
||||
pub fn extract_owners(&self) -> Vec<PublicKey> {
|
||||
self.iter().map(|n| n.public_key).collect()
|
||||
}
|
||||
|
||||
/// Extracts all relay URLs from these coordinates
|
||||
#[inline]
|
||||
pub fn extract_relays(&self) -> Vec<RelayUrl> {
|
||||
self.iter().flat_map(|n| n.relays.clone()).collect()
|
||||
}
|
||||
@@ -208,16 +217,19 @@ impl Vec<Nip19Coordinate> {
|
||||
#[easy_ext::ext(ReposUtils)]
|
||||
impl Vec<GitRepositoryAnnouncement> {
|
||||
/// Extracts all relay URLs from these repositories
|
||||
#[inline]
|
||||
pub fn extract_relays(&self) -> Vec<RelayUrl> {
|
||||
self.iter().flat_map(|n| n.relays.clone()).collect()
|
||||
}
|
||||
|
||||
/// Extract all the maintainers from these repositories
|
||||
#[inline]
|
||||
pub fn extract_maintainers(&self) -> Vec<PublicKey> {
|
||||
self.iter().flat_map(|r| r.maintainers.clone()).collect()
|
||||
}
|
||||
|
||||
/// Gets the first EUC hash from the reposotoies if it exists.
|
||||
#[inline]
|
||||
pub fn extract_euc(&self) -> Option<&Sha1Hash> {
|
||||
self.iter().find_map(|r| r.euc.as_ref())
|
||||
}
|
||||
@@ -227,6 +239,7 @@ impl Vec<GitRepositoryAnnouncement> {
|
||||
#[easy_ext::ext(GitPatchUtils)]
|
||||
impl Event {
|
||||
/// Returns whether the patch is a root or not
|
||||
#[inline]
|
||||
pub fn is_root_patch(&self) -> bool {
|
||||
self.kind == Kind::GitPatch
|
||||
&& self
|
||||
@@ -236,6 +249,7 @@ impl Event {
|
||||
}
|
||||
|
||||
/// Returns whether the patch is patch-revision or not
|
||||
#[inline]
|
||||
pub fn is_revision_patch(&self) -> bool {
|
||||
self.kind == Kind::GitPatch
|
||||
&& self
|
||||
|
||||
@@ -43,17 +43,20 @@ use crate::{
|
||||
};
|
||||
|
||||
/// Returns the value of the given tag
|
||||
#[inline]
|
||||
fn tag_value(tag: &TagStandard) -> String {
|
||||
tag.clone().to_vec().remove(1)
|
||||
}
|
||||
|
||||
/// Parses the tag value into type `T` if possible.
|
||||
#[inline]
|
||||
fn parse_value<T: FromStr>(tag: &TagStandard) -> Option<T> {
|
||||
tag_value(tag).parse().ok()
|
||||
}
|
||||
|
||||
/// Gets all values from the tag. If any value fails to parse, returns an empty
|
||||
/// vector.
|
||||
#[inline]
|
||||
fn tag_values<T>(tag: &TagStandard) -> Vec<T>
|
||||
where
|
||||
T: FromStr + fmt::Debug,
|
||||
@@ -113,6 +116,7 @@ where
|
||||
|
||||
/// Creates a new NIP-19 nevent string from an event ID and up to 3 unique relay
|
||||
/// URLs.
|
||||
#[inline]
|
||||
pub fn new_nevent(event_id: EventId, relays: &[RelayUrl]) -> N34Result<String> {
|
||||
Nip19Event::new(event_id)
|
||||
.relays(
|
||||
@@ -127,6 +131,7 @@ pub fn new_nevent(event_id: EventId, relays: &[RelayUrl]) -> N34Result<String> {
|
||||
|
||||
/// Creates a NIP-19 naddr string for a git repository announcement and up to 3
|
||||
/// unique relay URLs.
|
||||
#[inline]
|
||||
pub fn repo_naddr(
|
||||
repo_id: impl Into<String>,
|
||||
pubk: PublicKey,
|
||||
@@ -223,6 +228,7 @@ pub fn get_content(
|
||||
}
|
||||
|
||||
/// Path to the `nostr-address` file in current directory.
|
||||
#[inline]
|
||||
pub fn nostr_address_path() -> std::io::Result<PathBuf> {
|
||||
std::env::current_dir().map(|p| p.join(NOSTR_ADDRESS_FILE))
|
||||
}
|
||||
@@ -247,6 +253,7 @@ pub fn naddrs_or_file(
|
||||
|
||||
/// Generate a reply tag for an event with the given ID, relay URL (if any), and
|
||||
/// marker.
|
||||
#[inline]
|
||||
pub fn event_reply_tag(reply_to: &EventId, relay: Option<&RelayUrl>, marker: Marker) -> Tag {
|
||||
Tag::custom(
|
||||
TagKind::e(),
|
||||
|
||||
Reference in New Issue
Block a user