Skip to content

Add tag helper methods and refactor events #232

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

Merged

Conversation

tcheeric
Copy link
Owner

Summary

  • add requireTag and requireTagInstance helpers
  • use new helpers in ReactionEvent, ZapReceiptEvent, and MuteUserEvent
  • add unit test for ReactionEvent
  • document tag helper methods in README

Testing

  • mvn -q verify

https://chatgpt.com/codex/tasks/task_b_688a8500df4c833192e7879aea6d2535

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces tag helper methods to improve validation and retrieval of required tags in Nostr events. The changes simplify the codebase by replacing repetitive validation logic with reusable helper methods.

  • Added requireTag and requireTagInstance helper methods to GenericEvent class
  • Refactored validation logic in ReactionEvent, ZapReceiptEvent, and MuteUserEvent to use the new helpers
  • Added unit tests for ReactionEvent to verify tag validation behavior

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
nostr-java-event/src/main/java/nostr/event/impl/GenericEvent.java Added requireTag and requireTagInstance helper methods with proper documentation
nostr-java-event/src/main/java/nostr/event/impl/ReactionEvent.java Refactored to use requireTagInstance for EventTag validation and retrieval
nostr-java-event/src/main/java/nostr/event/impl/ZapReceiptEvent.java Simplified validation logic using requireTag for multiple required tags
nostr-java-event/src/main/java/nostr/event/impl/MuteUserEvent.java Replaced manual validation with requireTagInstance for PubKeyTag
nostr-java-id/src/test/java/nostr/id/ReactionEventTest.java Added unit tests covering both successful tag retrieval and missing tag scenarios
README.md Updated documentation to mention the new tag helper methods

Comment on lines +25 to +32
return requireTagInstance(PubKeyTag.class).getPublicKey();
}

@Override
protected void validateTags() {
super.validateTags();

// Validate `tags` field for at least one PubKeyTag
boolean hasValidPubKeyTag = this.getTags().stream()
.anyMatch(tag -> tag instanceof PubKeyTag);
if (!hasValidPubKeyTag) {
throw new AssertionError("Invalid `tags`: Must include at least one valid PubKeyTag.");
}
requireTagInstance(PubKeyTag.class);
Copy link
Preview

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The original implementation used getTags().get(0) which suggests it expected the first tag to be a PubKeyTag. The new implementation returns the first PubKeyTag found anywhere in the tags list, which may have different behavior if there are non-PubKeyTag tags before the actual PubKeyTag.

Copilot uses AI. Check for mistakes.

@tcheeric tcheeric merged commit 5840dd5 into develop Jul 30, 2025
@tcheeric tcheeric deleted the codex/introduce-requiretag-methods-in-genericevent branch July 30, 2025 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant