pub struct Comment {
pub root: CommentScope,
pub root_kind: Option<Kind>,
pub root_author: Option<PublicKey>,
pub parent: CommentScope,
pub parent_kind: Option<Kind>,
pub parent_author: Option<PublicKey>,
pub content: String,
}Expand description
A NIP-22 kind: 1111 comment ready to be turned into an Event.
Both root and parent are mandatory; if the comment replies directly
to the root, set both fields to the same scope.
§Spec note on K / P tags
NIP-22 declares that the K (root kind) and P (root pubkey) tags
“MUST be” present alongside an E/A root scope. The crate stores
them as Options for two practical reasons:
- the
CommentScope::Externalflavour has no inherent kind or author (the comment targets a URL, podcast, or NIP-73 identifier), - real-world events from Coracle, Damus and others sometimes ship a comment without the K/P columns, and the lenient parser would otherwise reject them.
Authors writing new NIP-22 events targeting CommentScope::Event /
CommentScope::Address roots SHOULD set Self::root_kind (and
the matching parent kind / author hints) so downstream relays can
index the comment correctly.
Fields§
§root: CommentScopeTop of the conversation.
root_kind: Option<Kind>Optional kind hint for the root.
Optional author hint for the root.
parent: CommentScopeDirect parent (the message being replied to).
parent_kind: Option<Kind>Optional kind hint for the parent.
Optional author hint for the parent.
content: StringFree-form comment text.
Implementations§
Source§impl Comment
impl Comment
Sourcepub fn top_level(root: CommentScope, content: impl Into<String>) -> Self
pub fn top_level(root: CommentScope, content: impl Into<String>) -> Self
Construct a comment whose parent equals its root.
Sourcepub const fn with_root_kind(self, kind: Kind) -> Self
pub const fn with_root_kind(self, kind: Kind) -> Self
Set the root kind hint.
Set the root author hint.
Sourcepub const fn with_parent_kind(self, kind: Kind) -> Self
pub const fn with_parent_kind(self, kind: Kind) -> Self
Set the parent kind hint.
Set the parent author hint.
Sourcepub fn with_parent(self, parent: CommentScope) -> Self
pub fn with_parent(self, parent: CommentScope) -> Self
Override the parent scope (use when the parent differs from the root).
Render the comment as the Tags that go into its kind: 1111
event.
Sourcepub fn from_event(event: &Event) -> Result<Self, CommentError>
pub fn from_event(event: &Event) -> Result<Self, CommentError>
Reconstruct a Comment from a kind: 1111 Event.
§Errors
Returns the matching CommentError when the event is the wrong
kind, missing one of the required scope tags, or carries malformed
values.
Trait Implementations§
impl Eq for Comment
impl StructuralPartialEq for Comment
Auto Trait Implementations§
impl Freeze for Comment
impl RefUnwindSafe for Comment
impl Send for Comment
impl Sync for Comment
impl Unpin for Comment
impl UnsafeUnpin for Comment
impl UnwindSafe for Comment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.