mattn / algia

A cli application for nostr
MIT License
179 stars 25 forks source link

Initializing ev.Tags with nostr.Tags{} in case of tag is empty when publishing an event at doPost function #9

Closed jundow closed 1 year ago

jundow commented 1 year ago

In doPost function, ev.Tags may need to be initialized with nostr.Tags{ }.

If no tags were added to the event object, the ev.Tags was nil. I observed many of relays reject event objects when it was nil.

To resolve this, initializing ev.Tags with nostr.Tags{ } (an empty array of array) worked for me.

I would suggest to add this line,

ev.Tags = nostr.Tags{ }

before the line 260 in "timeline.go."

/*Line 260: func doPost in timeline.go*/
    for i, u := range cCtx.StringSlice("u") {
        ev.Content = fmt.Sprintf("#[%d] ", i) + ev.Content
        if pp := sdk.InputToProfile(u); pp == nil {
            return fmt.Errorf("failed to parse pubkey from '%s'", u)
        } else {
            u = pp.PublicKey
        }
        ev.Tags = ev.Tags.AppendUnique(nostr.Tag{"p", u})
    }
/*the function goes on...*/

If ev.Tags is nil, the corresponding part in the parsed JSON will be nil. If initialized with nostr.Tags{}, it will be "[]".

mattn commented 1 year ago

Okay, could you please send me PR ?

jundow commented 1 year ago

The issue is closed because it was resolved. (PR#10)