fixing json filter json + marshaling filter tags.

This commit is contained in:
fiatjaf 2023-04-16 16:19:24 -03:00
parent c42059f4b4
commit 2695854e56
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 70 additions and 34 deletions

View File

@ -9,14 +9,14 @@ import (
type Filters []Filter type Filters []Filter
type Filter struct { type Filter struct {
IDs []string `json:"ids"` IDs []string `json:"ids,omitempty"`
Kinds []int `json:"kinds"` Kinds []int `json:"kinds,omitempty"`
Authors []string `json:"authors"` Authors []string `json:"authors,omitempty"`
Tags TagMap `json:"-"` Tags TagMap `json:"-,omitempty"`
Since *Timestamp `json:"since"` Since *Timestamp `json:"since,omitempty"`
Until *Timestamp `json:"until"` Until *Timestamp `json:"until,omitempty"`
Limit int `json:"limit"` Limit int `json:"limit,omitempty"`
Search string `json:"search"` Search string `json:"search,omitempty"`
} }
type TagMap map[string][]string type TagMap map[string][]string

View File

@ -170,12 +170,11 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
out.RawByte('{') out.RawByte('{')
first := true first := true
_ = first _ = first
{ if len(in.IDs) != 0 {
const prefix string = ",\"ids\":" const prefix string = ",\"ids\":"
first = false
out.RawString(prefix[1:]) out.RawString(prefix[1:])
if in.IDs == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { {
out.RawString("null")
} else {
out.RawByte('[') out.RawByte('[')
for v4, v5 := range in.IDs { for v4, v5 := range in.IDs {
if v4 > 0 { if v4 > 0 {
@ -186,12 +185,15 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
out.RawByte(']') out.RawByte(']')
} }
} }
{ if len(in.Kinds) != 0 {
const prefix string = ",\"kinds\":" const prefix string = ",\"kinds\":"
out.RawString(prefix) if first {
if in.Kinds == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { first = false
out.RawString("null") out.RawString(prefix[1:])
} else { } else {
out.RawString(prefix)
}
{
out.RawByte('[') out.RawByte('[')
for v6, v7 := range in.Kinds { for v6, v7 := range in.Kinds {
if v6 > 0 { if v6 > 0 {
@ -202,12 +204,15 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
out.RawByte(']') out.RawByte(']')
} }
} }
{ if len(in.Authors) != 0 {
const prefix string = ",\"authors\":" const prefix string = ",\"authors\":"
out.RawString(prefix) if first {
if in.Authors == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { first = false
out.RawString("null") out.RawString(prefix[1:])
} else { } else {
out.RawString(prefix)
}
{
out.RawByte('[') out.RawByte('[')
for v8, v9 := range in.Authors { for v8, v9 := range in.Authors {
if v8 > 0 { if v8 > 0 {
@ -218,34 +223,65 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
out.RawByte(']') out.RawByte(']')
} }
} }
{ if in.Since != nil {
const prefix string = ",\"since\":" const prefix string = ",\"since\":"
out.RawString(prefix) if first {
if in.Since == nil { first = false
out.RawString("null") out.RawString(prefix[1:])
} else { } else {
out.RawString(prefix)
}
out.Int64(int64(*in.Since)) out.Int64(int64(*in.Since))
} }
} if in.Until != nil {
{
const prefix string = ",\"until\":" const prefix string = ",\"until\":"
out.RawString(prefix) if first {
if in.Until == nil { first = false
out.RawString("null") out.RawString(prefix[1:])
} else { } else {
out.RawString(prefix)
}
out.Int64(int64(*in.Until)) out.Int64(int64(*in.Until))
} }
} if in.Limit != 0 {
{
const prefix string = ",\"limit\":" const prefix string = ",\"limit\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix) out.RawString(prefix)
}
out.Int(int(in.Limit)) out.Int(int(in.Limit))
} }
{ if in.Search != "" {
const prefix string = ",\"search\":" const prefix string = ",\"search\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix) out.RawString(prefix)
}
out.String(string(in.Search)) out.String(string(in.Search))
} }
for tag, values := range in.Tags {
const prefix string = ",\"authors\":"
if first {
first = false
out.RawString("\"#" + tag + "\":")
} else {
out.RawString(",\"#" + tag + "\":")
}
{
out.RawByte('[')
for i, v := range values {
if i > 0 {
out.RawByte(',')
}
out.String(string(v))
}
out.RawByte(']')
}
}
out.RawByte('}') out.RawByte('}')
} }