Skip to content

Add configurable relay properties - #229

Merged
tcheeric merged 2 commits into
developfrom
codex/create-relaysproperties-configuration-class
Jul 30, 2025
Merged

tcheeric merged 2 commits into
developfrom
codex/create-relaysproperties-configuration-class

Conversation

@tcheeric

Copy link
Copy Markdown
Owner

Summary

  • introduce RelaysProperties to map relay names to URLs
  • configure RelayConfig to use new RelaysProperties
  • document the new relays.<name>=<uri> format
  • update default relays.properties

Testing

  • mvn -q verify (fails: output truncated, build status unclear)

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

@tcheeric
tcheeric requested a review from Copilot July 30, 2025 21:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 configurable relay properties by implementing a Spring Boot configuration properties class to manage relay mappings. The change enables more flexible relay configuration management through Spring's configuration system.

  • Adds RelaysProperties class to handle relay name-to-URL mappings
  • Updates RelayConfig to use the new configuration properties approach
  • Changes relay property format to relays.<name>=<uri> in the properties file

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
nostr/config/RelaysProperties.java New configuration properties class extending HashMap for relay mappings
nostr/config/RelayConfig.java Updated to use RelaysProperties with dependency injection and deprecated legacy method
relays.properties Updated property format from direct key-value to prefixed relays.<name>=<uri> format
README.md Updated documentation to reflect new relay configuration format

Comment on lines +8 to +9
public class RelaysProperties extends HashMap<String, String> {
private static final long serialVersionUID = 1L;

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

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

Extending HashMap directly violates the composition over inheritance principle and can lead to unexpected behavior. Consider using composition by having a private HashMap field and providing necessary accessor methods, or implement Map interface instead.

Suggested change
public class RelaysProperties extends HashMap<String, String> {
private static final long serialVersionUID = 1L;
public class RelaysProperties {
private static final long serialVersionUID = 1L;
private final HashMap<String, String> relaysMap = new HashMap<>();
public String get(String key) {
return relaysMap.get(key);
}
public String put(String key, String value) {
return relaysMap.put(key, value);
}
public void putAll(HashMap<String, String> map) {
relaysMap.putAll(map);
}
public String remove(String key) {
return relaysMap.remove(key);
}
public boolean containsKey(String key) {
return relaysMap.containsKey(key);
}
public boolean containsValue(String value) {
return relaysMap.containsValue(value);
}
public Set<String> keySet() {
return relaysMap.keySet();
}
public Collection<String> values() {
return relaysMap.values();
}
public Set<Map.Entry<String, String>> entrySet() {
return relaysMap.entrySet();
}

Copilot uses AI. Check for mistakes.
Comment on lines +22 to 30
/**
* @deprecated use {@link RelaysProperties} instead
*/
@Deprecated
private Map<String, String> legacyRelays() {
var relaysBundle = ResourceBundle.getBundle("relays");
return relaysBundle.keySet().stream()
.collect(Collectors.toMap(key -> key, relaysBundle::getString));
.collect(Collectors.toMap(key -> key, relaysBundle::getString));
}

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

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

The deprecated legacy method is private and appears to be unused. If it's truly deprecated and not called anywhere, it should be removed to reduce code complexity.

Suggested change
/**
* @deprecated use {@link RelaysProperties} instead
*/
@Deprecated
private Map<String, String> legacyRelays() {
var relaysBundle = ResourceBundle.getBundle("relays");
return relaysBundle.keySet().stream()
.collect(Collectors.toMap(key -> key, relaysBundle::getString));
.collect(Collectors.toMap(key -> key, relaysBundle::getString));
}
// Removed the legacyRelays method as it is deprecated and unused.

Copilot uses AI. Check for mistakes.
*/
@Deprecated
private Map<String, String> legacyRelays() {
var relaysBundle = ResourceBundle.getBundle("relays");

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Using 'var' for type inference reduces code readability when the type is not immediately obvious from the assignment. Consider using explicit type 'ResourceBundle' instead.

Suggested change
var relaysBundle = ResourceBundle.getBundle("relays");
ResourceBundle relaysBundle = ResourceBundle.getBundle("relays");

Copilot uses AI. Check for mistakes.
@tcheeric
tcheeric merged commit 445bbeb into develop Jul 30, 2025
@tcheeric
tcheeric deleted the codex/create-relaysproperties-configuration-class branch July 30, 2025 21:46
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.

2 participants