Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nostr: add nip22::extract_root and nip22:extract_parent #729

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yukibtc
Copy link
Member

@yukibtc yukibtc commented Jan 23, 2025

@yukibtc yukibtc force-pushed the nip22 branch 3 times, most recently from 79a3855 to a436e44 Compare January 23, 2025 10:24
@yukibtc yukibtc changed the title nostr: add nip22::extract_root_data and nip22:extract_parent_data nostr: add nip22::extract_root and nip22:extract_parent Jan 23, 2025
/// Kind
///
/// This isn't properly defined yet but it will surely be needed in the future. It could i.e. be a root domain
kind: Option<&'a Kind>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either remove External::kind because it's not used and not defined yet, or change it's type from Kind to String. The Kind enum is not useful for external things

}

let kind: Option<&Kind> = extract_kind(event, is_root);
let pubkey_hint: Option<&PublicKey> = extract_public_key(event, is_root);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pubkey hint is not a p-tag, it's the item after the relay hint:

["e", "event-id", "relay-hint", "pubkey-hint"],

doesn't apply to i and a, only e

}

fn extract_kind(event: &Event, is_root: bool) -> Option<&Kind> {
let tag = event.tags.find_standardized(TagKind::k())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always consider only the first k|K tag, right? But Comments can have a k and a K tag at the same time.

So you should use filter_standardized then find the first uppercase or lowercase tag depending on is_root. Or whatever way is best to achieve this

}
}

fn extract_event(event: &Event, is_root: bool) -> Option<(&EventId, Option<&RelayUrl>)> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return value is missing the Option<PublicKey> pubkey hint

}

fn extract_coordinate(event: &Event, is_root: bool) -> Option<(&Coordinate, Option<&RelayUrl>)> {
let tag = event.tags.find_standardized(TagKind::a())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Comments can have an A and an a tag at the same time.

}

fn extract_external(event: &Event, is_root: bool) -> Option<(&ExternalContentId, Option<&Url>)> {
let tag = event.tags.find_standardized(TagKind::i())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Comments can have an I and an i tag at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants