Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package nostr.event.json.codec;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

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

The JsonNode import is now unused after the refactor. Consider removing this import to keep the code clean.

Copilot uses AI. Check for mistakes.
import lombok.Data;
import lombok.NonNull;
import lombok.SneakyThrows;
Expand All @@ -8,6 +10,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static nostr.base.IEvent.MAPPER_AFTERBURNER;

Expand All @@ -21,11 +24,16 @@ public class FiltersDecoder implements FDecoder<Filters> {
public Filters decode(@NonNull String jsonFiltersList) {
final List<Filterable> filterables = new ArrayList<>();

MAPPER_AFTERBURNER.readTree(jsonFiltersList).fields().forEachRemaining(node ->
filterables.addAll(
FilterableProvider.getFilterFunction(
node.getValue(),
node.getKey())));
Map<String, JsonNode> filtersMap = MAPPER_AFTERBURNER.readValue(
jsonFiltersList,
new TypeReference<Map<String, JsonNode>>() {});

for (Map.Entry<String, JsonNode> entry : filtersMap.entrySet()) {
filterables.addAll(
FilterableProvider.getFilterFunction(
entry.getValue(),
entry.getKey()));
}

return new Filters(filterables);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,25 @@ public void testUntilFiltersDecoder() {
assertEquals(new Filters(new UntilFilter(until)), decodedFilters);
}

@Test
public void testDecoderMultipleFilterTypes() {
log.info("testDecoderMultipleFilterTypes");

String eventId = "f1b419a95cb0233a11d431423b41a42734e7165fcab16081cd08ef1c90e0be75";
Kind kind = Kind.valueOf(1);
Long since = Date.from(Instant.now()).getTime();

String expected = "{\"ids\":[\"" + eventId + "\"],\"kinds\":[" + kind.toString() + "],\"since\":" + since + "}";
Filters decodedFilters = new FiltersDecoder().decode(expected);

assertEquals(
new Filters(
new EventFilter<>(new GenericEvent(eventId)),
new KindFilter<>(kind),
new SinceFilter(since)),
decodedFilters);
}

@Test
public void testFailedAddressableTagMalformedSeparator() {
log.info("testFailedAddressableTagMalformedSeparator");
Expand Down