Skip to content

Commit

Permalink
Adopt changes from branch
Browse files Browse the repository at this point in the history
  • Loading branch information
erict875 committed Jun 17, 2024
1 parent d51ce30 commit 8578de0
Showing 1 changed file with 79 additions and 42 deletions.
121 changes: 79 additions & 42 deletions nostr-java-api/src/main/java/nostr/api/NIP01.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
import nostr.api.factory.impl.NIP01Impl.ReplaceableEventFactory;
import nostr.api.factory.impl.NIP01Impl.ReqMessageFactory;
import nostr.api.factory.impl.NIP01Impl.TextNoteEventFactory;
import nostr.base.GenericTagQuery;
import nostr.base.IEvent;
import nostr.base.PublicKey;
import nostr.base.Relay;
import nostr.base.UserProfile;
import nostr.event.BaseTag;
import nostr.event.Kind;
import nostr.event.Marker;
import nostr.event.NIP01Event;
import nostr.event.list.FiltersList;
import nostr.event.impl.Filters;
import nostr.event.impl.GenericEvent;
import nostr.event.message.CloseMessage;
import nostr.event.message.EoseMessage;
import nostr.event.message.EventMessage;
Expand All @@ -45,29 +48,29 @@
* @author eric
*/
public class NIP01<T extends NIP01Event> extends EventNostr<T> {
public NIP01(@NonNull Identity sender) {
setSender(sender);
}

public NIP01(@NonNull Identity sender) {
setSender(sender);
}

/**
* Create a NIP01 text note event without tags
*
* @param content the content of the note
* @return the text note without tags
*/
public NIP01<T> createTextNoteEvent(@NonNull String content) {
var event = new TextNoteEventFactory(getSender(), content).create();
this.setEvent((T) event);
public NIP01<T> createTextNoteEvent(@NonNull String content) {
var event = new TextNoteEventFactory(getSender(), content).create();
this.setEvent((T) event);

return this;
return this;
}

public NIP01<T> createTextNoteEvent(@NonNull Identity sender, @NonNull String content) {
var event = new TextNoteEventFactory(sender, content).create();
this.setEvent((T) event);
public NIP01<T> createTextNoteEvent(@NonNull Identity sender, @NonNull String content) {
var event = new TextNoteEventFactory(sender, content).create();
this.setEvent((T) event);

return this;
return this;
}

/**
Expand All @@ -78,14 +81,14 @@ public NIP01<T> createTextNoteEvent(@NonNull Identity sender, @NonNull String co
* @return a text note event
*/
public NIP01<T> createTextNoteEvent(@NonNull List<BaseTag> tags, @NonNull String content) {
setEvent((T) new TextNoteEventFactory(getSender(), tags, content).create());
return this;
setEvent((T) new TextNoteEventFactory(getSender(), tags, content).create());
return this;
}

public NIP01<T> createMetadataEvent(@NonNull UserProfile profile) {
var sender = getSender();
var event = (sender!=null) ? new MetadataEventFactory(sender, profile).create() : new MetadataEventFactory(profile).create();
var sender = getSender();
var event = (sender!=null) ? new MetadataEventFactory(sender, profile).create() : new MetadataEventFactory(profile).create();

this.setEvent((T) event);
return this;
}
Expand All @@ -96,21 +99,21 @@ public NIP01<T> createMetadataEvent(@NonNull UserProfile profile) {
* @param content the content
*/
public NIP01<T> createReplaceableEvent(@NonNull Integer kind, String content) {
var event = new ReplaceableEventFactory(getSender(), kind, content).create();
var event = new ReplaceableEventFactory(getSender(), kind, content).create();

this.setEvent((T) event);
return this;
}

/**
* Create a replaceable event
* @param tags the note's tags
* @param kind the kind (10000 <= kind < 20000 || kind == 0 || kind == 3)
* @param content the note's content
*/
public NIP01<T> createReplaceableEvent(@NonNull List<BaseTag> tags, @NonNull Integer kind, String content) {
var event = new ReplaceableEventFactory(getSender(), tags, kind, content).create();
var event = new ReplaceableEventFactory(getSender(), tags, kind, content).create();

this.setEvent((T) event);
return this;
}
Expand All @@ -121,11 +124,11 @@ public NIP01<T> createReplaceableEvent(@NonNull List<BaseTag> tags, @NonNull Int
* @param content the note's content
*/
public NIP01<T> createEphemeralEvent(@NonNull Integer kind, String content) {
var event = new EphemeralEventFactory(getSender(), kind, content).create();
var event = new EphemeralEventFactory(getSender(), kind, content).create();

this.setEvent((T) event);
return this;
}
return this;
}

/**
* Create a NIP01 event tag
Expand Down Expand Up @@ -181,6 +184,40 @@ public static PubKeyTag createPubKeyTag(@NonNull PublicKey publicKey, String mai
return result;
}

/**
* Create a NIP01 filters object (all parameters are optional)
*
* @param events a list of event
* @param authors a list of pubkeys or prefixes, the pubkey of an event must
* be one of these
* @param kinds a list of a kind numbers
* @param referencedEvents a list of event ids that are referenced in an "e"
* tag
* @param referencePubKeys a list of pubkeys that are referenced in a "p"
* tag
* @param since an integer unix timestamp in seconds, events must be newer
* than this to pass
* @param until an integer unix timestamp in seconds, events must be older
* than this to pass
* @param limit maximum number of events to be returned in the initial query
* @param genericTagQuery a generic tag query
* @return a filters object
*/
@Deprecated(forRemoval = true)
public static Filters createFilters(List<GenericEvent> events, List<PublicKey> authors, List<Kind> kinds, List<GenericEvent> referencedEvents, List<PublicKey> referencePubKeys, Long since, Long until, Integer limit, GenericTagQuery genericTagQuery) {
return Filters.builder()
.authors(authors)
.events(events)
.genericTagQuery(genericTagQuery)
.kinds(kinds).limit(limit)
.referencePubKeys(referencePubKeys)
.referencedEvents(referencedEvents)
.since(since)
.until(until)
.build();
}


/**
* Create an event message to send events requested by clients
*
Expand All @@ -201,7 +238,7 @@ public static EventMessage createEventMessage(@NonNull IEvent event, @NonNull St
* @param filtersList the filters list
* @return a REQ message
*/
public static ReqMessage createReqMessage(@NonNull String subscriptionId, @NonNull FiltersList filtersList) {
public static ReqMessage createReqMessage(@NonNull String subscriptionId, @NonNull List<Filters> filtersList) {
return new ReqMessageFactory(subscriptionId, filtersList).create();
}

Expand Down Expand Up @@ -238,52 +275,52 @@ public static NoticeMessage createNoticeMessage(@NonNull String message) {
}

/**
*
*
* @param comment the event's comment
*/
public NIP01<T> createParameterizedReplaceableEvent(@NonNull Integer kind, String comment) {
var event = new ParameterizedReplaceableEventFactory(getSender(), kind, comment).create();
var event = new ParameterizedReplaceableEventFactory(getSender(), kind, comment).create();

this.setEvent((T) event);
return this;
}

/**
*
*
* @param tags
* @param kind
* @param comment
* @return
* @return
*/
public NIP01<T> createParameterizedReplaceableEvent(@NonNull List<BaseTag> tags, @NonNull Integer kind, String comment) {
var event = new ParameterizedReplaceableEventFactory(getSender(), tags, kind, comment).create();
var event = new ParameterizedReplaceableEventFactory(getSender(), tags, kind, comment).create();

this.setEvent((T) event);
return this;
}

/**
*
*
* @param id
* @return
* @return
*/
public static IdentifierTag createIdentifierTag(@NonNull String id) {
return new IdentifierTagFactory(id).create();
}

/**
*
*
* @param kind
* @param publicKey
* @param idTag
* @param relay
* @return
* @return
*/
public static AddressTag createAddressTag(@NonNull Integer kind, @NonNull PublicKey publicKey, @NonNull IdentifierTag idTag, Relay relay) {
var result = new AddressTagFactory(publicKey).create();
result.setIdentifierTag(idTag);
result.setKind(kind);
result.setRelay(relay);
return result;
}
}
}

0 comments on commit 8578de0

Please sign in to comment.