relay.Count()

This commit is contained in:
fiatjaf
2023-07-18 16:17:00 -03:00
parent 6cee628149
commit 53b9dde6e0
4 changed files with 92 additions and 6 deletions

View File

@@ -15,6 +15,9 @@ type Subscription struct {
Relay *Relay
Filters Filters
// for this to be treated as a COUNT and not a REQ this must be set
countResult chan int64
// the Events channel emits all EVENTs that come in a Subscription
// will be closed when the subscription ends
Events chan *Event
@@ -123,7 +126,12 @@ func (sub *Subscription) Sub(ctx context.Context, filters Filters) {
func (sub *Subscription) Fire() error {
id := sub.GetID()
reqb, _ := ReqEnvelope{id, sub.Filters}.MarshalJSON()
var reqb []byte
if sub.countResult == nil {
reqb, _ = ReqEnvelope{id, sub.Filters}.MarshalJSON()
} else {
reqb, _ = CountEnvelope{id, sub.Filters, nil}.MarshalJSON()
}
debugLogf("{%s} sending %v", sub.Relay.URL, reqb)
sub.live.Store(true)