diff --git a/no2all-nostr/src/main/java/love/distributedrebirth/no2all/nostr/model/event/NoStrEventTag.java b/no2all-nostr/src/main/java/love/distributedrebirth/no2all/nostr/model/event/NoStrEventTag.java index d6fee12..6812ce2 100644 --- a/no2all-nostr/src/main/java/love/distributedrebirth/no2all/nostr/model/event/NoStrEventTag.java +++ b/no2all-nostr/src/main/java/love/distributedrebirth/no2all/nostr/model/event/NoStrEventTag.java @@ -10,8 +10,6 @@ import jakarta.json.Json; import jakarta.json.JsonArray; import jakarta.json.JsonValue; import love.distributedrebirth.no2all.nostr.NoStrGospel; -import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagE; -import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagNonce; import love.distributedrebirth.no2all.nostr.nip.NoStrImplEventTag; import love.distributedrebirth.no2all.nostr.nip.NoStrImplEventTagArgument; @@ -72,11 +70,11 @@ public interface NoStrEventTag extends NoStrGospel { static NoStrEventTag valueOf(NoStrEventTagMeta meta, String[] args) { Objects.requireNonNull(meta); Objects.requireNonNull(args); - if (NoStrImplEventTag.E.equals(meta)) { - return new NoStrTagE(args); - } - if (NoStrImplEventTag.NONCE.equals(meta)) { - return new NoStrTagNonce(args); + if (meta instanceof NoStrImplEventTag) { + NoStrImplEventTag metaTag = NoStrImplEventTag.class.cast(meta); + if (metaTag.getMapperToEventTag().isPresent()) { + return metaTag.getMapperToEventTag().get().apply(args); + } } return new NoStrEventTagCustom(meta, args); } diff --git a/no2all-nostr/src/main/java/love/distributedrebirth/no2all/nostr/nip/NoStrImplEventTag.java b/no2all-nostr/src/main/java/love/distributedrebirth/no2all/nostr/nip/NoStrImplEventTag.java index 83e0a18..2469f16 100644 --- a/no2all-nostr/src/main/java/love/distributedrebirth/no2all/nostr/nip/NoStrImplEventTag.java +++ b/no2all-nostr/src/main/java/love/distributedrebirth/no2all/nostr/nip/NoStrImplEventTag.java @@ -4,52 +4,73 @@ import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.Objects; +import java.util.Optional; +import java.util.function.Function; import java.util.stream.Collectors; +import love.distributedrebirth.no2all.nostr.model.event.NoStrEventTag; import love.distributedrebirth.no2all.nostr.model.event.NoStrEventTagMeta; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagA; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagClient; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagContentWarning; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagD; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagDescription; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagE; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagI; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagImage; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagName; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagNonce; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagP; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagPublishedAt; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagR; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagSubject; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagSummary; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagT; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagThumb; +import love.distributedrebirth.no2all.nostr.model.tag.NoStrTagTitle; public enum NoStrImplEventTag implements NoStrEventTagMeta { // the "p" tag is used for referencing public keys - P (NoStrImpl.NIP_1_BASE_PROTOCOL), + P (v -> new NoStrTagP(v), NoStrImpl.NIP_1_BASE_PROTOCOL), // the "e" tag for referencing event ids - E (NoStrImpl.NIP_1_BASE_PROTOCOL, NoStrImpl.NIP_10_CORRECT_BASE_TAGS), + E (v -> new NoStrTagE(v), NoStrImpl.NIP_1_BASE_PROTOCOL, NoStrImpl.NIP_10_CORRECT_BASE_TAGS), // ["a", "::", ""] - A (NoStrImpl.NIP_23_LONG_FORM_CONTENT, NoStrImpl.NIP_33_PARA_REPLACEABLE_EVENTS), - I (NoStrImpl.NIP_39_EXT_INDENTITIES_IN_PROFILE), + A (v -> new NoStrTagA(v), NoStrImpl.NIP_23_LONG_FORM_CONTENT, NoStrImpl.NIP_33_PARA_REPLACEABLE_EVENTS), + I (v -> new NoStrTagI(v), NoStrImpl.NIP_39_EXT_INDENTITIES_IN_PROFILE), // the "d" tag is a delete slug key for "pubkey:kind:d" + time, empty is def key - D (NoStrImpl.NIP_33_PARA_REPLACEABLE_EVENTS), // TODO: add single tag info + check - T (NoStrImpl.NIP_12_GENERIC_TAG_QUERY), - R (NoStrImpl.NIP_12_GENERIC_TAG_QUERY), + D (v -> new NoStrTagD(v), NoStrImpl.NIP_33_PARA_REPLACEABLE_EVENTS), // TODO: add single tag info + check + T (v -> new NoStrTagT(v), NoStrImpl.NIP_12_GENERIC_TAG_QUERY), + R (v -> new NoStrTagR(v), NoStrImpl.NIP_12_GENERIC_TAG_QUERY), G (NoStrImpl.NIP_12_GENERIC_TAG_QUERY), CHALLENGE (NoStrImpl.NIP_42_AUTH_RELAY), RELAY (NoStrImpl.NIP_42_AUTH_RELAY), - TITLE (NoStrImpl.NIP_23_LONG_FORM_CONTENT), - SUMMARY (NoStrImpl.NIP_23_LONG_FORM_CONTENT), - PUBLISHED_AT (NoStrImpl.NIP_23_LONG_FORM_CONTENT), - IMAGE (NoStrImpl.NIP_23_LONG_FORM_CONTENT, NoStrImpl.NIP_58_BADGES), + TITLE (v -> new NoStrTagTitle(v), NoStrImpl.NIP_23_LONG_FORM_CONTENT), + SUMMARY (v -> new NoStrTagSummary(v), NoStrImpl.NIP_23_LONG_FORM_CONTENT), + PUBLISHED_AT (v -> new NoStrTagPublishedAt(v), NoStrImpl.NIP_23_LONG_FORM_CONTENT), + IMAGE (v -> new NoStrTagImage(v), NoStrImpl.NIP_23_LONG_FORM_CONTENT, NoStrImpl.NIP_58_BADGES), ZAP (NoStrImpl.NIP_57_LIGHTING_ZAPS), LNURL (NoStrImpl.NIP_57_LIGHTING_ZAPS), AMOUNT (NoStrImpl.NIP_57_LIGHTING_ZAPS), BOLT11 (NoStrImpl.NIP_57_LIGHTING_ZAPS), PREIMAGE (NoStrImpl.NIP_57_LIGHTING_ZAPS), - DESCRIPTION (NoStrImpl.NIP_57_LIGHTING_ZAPS, NoStrImpl.NIP_58_BADGES), + DESCRIPTION (v -> new NoStrTagDescription(v), NoStrImpl.NIP_57_LIGHTING_ZAPS, NoStrImpl.NIP_58_BADGES), RELAYS (NoStrImpl.NIP_57_LIGHTING_ZAPS), - CLIENT (true, NoStrImpl.NIP_0_UNKNOWN), - NONCE (true, NoStrImpl.NIP_13_PROOF_OF_WORK), - SUBJECT (NoStrImpl.NIP_14_TEXT_SUBJECT), + CLIENT (v -> new NoStrTagClient(v), true, NoStrImpl.NIP_0_UNKNOWN), + NONCE (v -> new NoStrTagNonce(v), true, NoStrImpl.NIP_13_PROOF_OF_WORK), + SUBJECT (v -> new NoStrTagSubject(v), NoStrImpl.NIP_14_TEXT_SUBJECT), DELEGATION (NoStrImpl.NIP_26_DELEGATED_EVENT_SIGN), EMOJI (NoStrImpl.NIP_30_CUSTOM_EMOJI), - CONTENT_WARNING (NoStrImpl.NIP_36_SENSITIVE_CONTENT), + CONTENT_WARNING (v -> new NoStrTagContentWarning(v), NoStrImpl.NIP_36_SENSITIVE_CONTENT), EXPIRATION (NoStrImpl.NIP_40_EXPIRATION_TIMESTAMP), ALT (NoStrImpl.NIP_31_ALT_FOR_UNKNOWN), - NAME (NoStrImpl.NIP_58_BADGES), - THUMB (NoStrImpl.NIP_58_BADGES), + NAME (v -> new NoStrTagName(v), NoStrImpl.NIP_58_BADGES), + THUMB (v -> new NoStrTagThumb(v), NoStrImpl.NIP_58_BADGES), // Dat Package extensions DPFH (NoStrImpl.NIP_0_UNKNOWN), // "DAT Package File Hash" with event content = maven://ndaturl+versionhash @@ -57,22 +78,32 @@ public enum NoStrImplEventTag implements NoStrEventTagMeta { private static final Map MAP_QNAME = Collections.unmodifiableMap( Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getQName(), v -> v))); + private final Optional> mapperToEventTag; private final String jsonQName; private final NoStrImplPossibility[] nips; private final boolean quariable; private final boolean singleton; private NoStrImplEventTag(NoStrImpl... nips) { - this(false, nips); // TODO: add info on all needed tags + this(null, nips); + } + + private NoStrImplEventTag(Function mapper, NoStrImpl... nips) { + this(mapper, false, nips); // TODO: add info on all needed tags } - private NoStrImplEventTag(boolean singleton, NoStrImpl... nips) { + private NoStrImplEventTag(Function mapper, boolean singleton, NoStrImpl... nips) { + this.mapperToEventTag = Optional.ofNullable(mapper); this.jsonQName = name().toLowerCase().replaceAll("_", "-"); this.nips = nips; this.quariable = isQuariable(name()); this.singleton = singleton; } + public Optional> getMapperToEventTag() { + return mapperToEventTag; + } + @Override public String getQName() { return jsonQName;