fix bug with kind being set to zero and replaced silently.

This commit is contained in:
fiatjaf 2023-11-13 10:34:09 -03:00
parent 795e98bc2e
commit 6a7a5eb26e
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -15,6 +15,7 @@ import (
"github.com/nbd-wtf/go-nostr/nip19" "github.com/nbd-wtf/go-nostr/nip19"
"github.com/nbd-wtf/go-nostr/nson" "github.com/nbd-wtf/go-nostr/nson"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"golang.org/x/exp/slices"
) )
const CATEGORY_EVENT_FIELDS = "EVENT FIELDS" const CATEGORY_EVENT_FIELDS = "EVENT FIELDS"
@ -129,20 +130,20 @@ example:
Tags: make(nostr.Tags, 0, 3), Tags: make(nostr.Tags, 0, 3),
} }
kindWasSupplied := true
mustRehashAndResign := false mustRehashAndResign := false
if stdinEvent != "" { if stdinEvent != "" {
if err := json.Unmarshal([]byte(stdinEvent), &evt); err != nil { if err := json.Unmarshal([]byte(stdinEvent), &evt); err != nil {
lineProcessingError(c, "invalid event received from stdin: %s", err) lineProcessingError(c, "invalid event received from stdin: %s", err)
continue continue
} }
kindWasSupplied = strings.Contains(stdinEvent, `"kind"`)
} }
kindWasSupplied = slices.Contains(c.FlagNames(), "kind")
if kind := c.Int("kind"); kind != 0 { if kind := c.Int("kind"); kindWasSupplied {
evt.Kind = kind evt.Kind = kind
mustRehashAndResign = true mustRehashAndResign = true
} else if evt.Kind == 0 {
evt.Kind = 1
mustRehashAndResign = true
} }
if content := c.String("content"); content != "" { if content := c.String("content"); content != "" {