Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

Commit

Permalink
chore: update to latest version of go-nostr
Browse files Browse the repository at this point in the history
  • Loading branch information
piraces committed Apr 25, 2023
1 parent c3a02eb commit a5649b9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
20 changes: 10 additions & 10 deletions cmd/rsslay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ func (r *Relay) UpdateListeningFilters() {
}

for _, item := range parsedFeed.Items {
defaultCreatedAt := time.Now()
defaultCreatedAt := time.Unix(time.Now().Unix(), 0)
evt := feed.ItemToTextNote(pubkey, item, parsedFeed, defaultCreatedAt, entity.URL, relayInstance.MaxContentLength)
last, ok := r.lastEmitted.Load(entity.URL)
if last == nil {
last = uint32(time.Now().Unix())
}
if !ok || time.Unix(int64(last.(uint32)), 0).Before(evt.CreatedAt) {
if !ok || nostr.Timestamp(int64(last.(uint32))) < evt.CreatedAt {
_ = evt.Sign(entity.PrivateKey)
r.updates <- evt
r.lastEmitted.Store(entity.URL, last.(uint32))
Expand Down Expand Up @@ -226,10 +226,10 @@ func (b store) QueryEvents(filter *nostr.Filter) ([]nostr.Event, error) {
if filter.Kinds == nil || slices.Contains(filter.Kinds, nostr.KindSetMetadata) {
evt := feed.EntryFeedToSetMetadata(pubkey, parsedFeed, entity.URL, relayInstance.EnableAutoNIP05Registration, relayInstance.DefaultProfilePictureUrl)

if filter.Since != nil && evt.CreatedAt.Before(*filter.Since) {
if filter.Since != nil && evt.CreatedAt < *filter.Since {
continue
}
if filter.Until != nil && evt.CreatedAt.After(*filter.Until) {
if filter.Until != nil && evt.CreatedAt > *filter.Until {
continue
}

Expand All @@ -241,25 +241,25 @@ func (b store) QueryEvents(filter *nostr.Filter) ([]nostr.Event, error) {
if filter.Kinds == nil || slices.Contains(filter.Kinds, nostr.KindTextNote) {
var last uint32 = 0
for _, item := range parsedFeed.Items {
defaultCreatedAt := time.Now()
defaultCreatedAt := time.Unix(time.Now().Unix(), 0)
evt := feed.ItemToTextNote(pubkey, item, parsedFeed, defaultCreatedAt, entity.URL, relayInstance.MaxContentLength)

// Feed need to have a date for each entry...
if evt.CreatedAt.Equal(defaultCreatedAt) {
if evt.CreatedAt == nostr.Timestamp(defaultCreatedAt.Unix()) {
continue
}

if filter.Since != nil && evt.CreatedAt.Before(*filter.Since) {
if filter.Since != nil && evt.CreatedAt < *filter.Since {
continue
}
if filter.Until != nil && evt.CreatedAt.After(*filter.Until) {
if filter.Until != nil && evt.CreatedAt > *filter.Until {
continue
}

_ = evt.Sign(entity.PrivateKey)

if evt.CreatedAt.After(time.Unix(int64(last), 0)) {
last = uint32(evt.CreatedAt.Unix())
if evt.CreatedAt > nostr.Timestamp(int64(last)) {
last = uint32(evt.CreatedAt)
}

parsedEvents = append(parsedEvents, evt)
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.16
github.com/microcosm-cc/bluemonday v1.0.23
github.com/mmcdole/gofeed v1.2.1
github.com/nbd-wtf/go-nostr v0.16.12
github.com/nbd-wtf/go-nostr v0.17.0
github.com/rif/cache2go v1.0.0
github.com/stretchr/testify v1.8.2
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2
Expand All @@ -33,14 +33,15 @@ require (
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mmcdole/goxpp v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
golang.org/x/net v0.8.0 // indirect
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ github.com/hellofresh/health-go/v5 v5.1.1/go.mod h1:ZUymhy/viIPx3xmGT9EkWny0CUZq
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
Expand All @@ -90,6 +92,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/microcosm-cc/bluemonday v1.0.23 h1:SMZe2IGa0NuHvnVNAZ+6B38gsTbi5e4sViiWJyDDqFY=
Expand All @@ -103,8 +107,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/nbd-wtf/go-nostr v0.16.12 h1:+MpIxOCJo8wnKzwgVecSjG62bs36+MrY7SXCIOSXMrU=
github.com/nbd-wtf/go-nostr v0.16.12/go.mod h1:yvUvLkncMo1zNNytdL1KXnWWc46N2uUQDsBmjHgHYC0=
github.com/nbd-wtf/go-nostr v0.17.0 h1:zKMoJBIsD1AAQ5nABvL5jLEz9hI0U4//Zm30NszJ4fA=
github.com/nbd-wtf/go-nostr v0.17.0/go.mod h1:YCDHJtaFQE76d1ZkcUsTkz3dYNP+bldo5CIQwXPPcbk=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down Expand Up @@ -141,8 +145,6 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ=
github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU=
github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
6 changes: 3 additions & 3 deletions pkg/feed/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ func EntryFeedToSetMetadata(pubkey string, feed *gofeed.Feed, originalUrl string

content, _ := json.Marshal(metadata)

createdAt := time.Now()
createdAt := time.Unix(time.Now().Unix(), 0)
if feed.PublishedParsed != nil {
createdAt = *feed.PublishedParsed
}

evt := nostr.Event{
PubKey: pubkey,
CreatedAt: createdAt,
CreatedAt: nostr.Timestamp(createdAt.Unix()),
Kind: nostr.KindSetMetadata,
Tags: nostr.Tags{},
Content: string(content),
Expand Down Expand Up @@ -223,7 +223,7 @@ func ItemToTextNote(pubkey string, item *gofeed.Item, feed *gofeed.Feed, default

evt := nostr.Event{
PubKey: pubkey,
CreatedAt: createdAt,
CreatedAt: nostr.Timestamp(createdAt.Unix()),
Kind: nostr.KindTextNote,
Tags: nostr.Tags{},
Content: strings.ToValidUTF8(content, ""),
Expand Down
4 changes: 2 additions & 2 deletions pkg/feed/feed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const sampleValidWithoutFeedUrl = "https://go.dev/"
const sampleValidWithRelativeFeedUrl = "https://golangweekly.com/"
const sampleValidWithRelativeFeedUrlExpected = "https://golangweekly.com/rss"

var actualTime = time.Now()
var actualTime = time.Unix(time.Now().Unix(), 0)
var sampleNitterFeed = gofeed.Feed{
Title: "Coldplay / @coldplay",
Description: "Twitter feed for: @coldplay. Generated by nitter.moomoo.me",
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestItemToTextNote(t *testing.T) {
event := ItemToTextNote(tc.pubKey, tc.item, tc.feed, tc.defaultCreatedAt, tc.originalUrl, tc.maxContentLength)
assert.NotEmpty(t, event)
assert.Equal(t, tc.pubKey, event.PubKey)
assert.Equal(t, tc.defaultCreatedAt, event.CreatedAt)
assert.Equal(t, tc.defaultCreatedAt, event.CreatedAt.Time())
assert.Equal(t, 1, event.Kind)
assert.Equal(t, tc.expectedContent, event.Content)
assert.Empty(t, event.Sig)
Expand Down
2 changes: 1 addition & 1 deletion pkg/replayer/replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ReplayEventsToRelays(parameters *ReplayParameters) {

if eventCount > parameters.MaxEventsToReplay {
sort.Slice(parameters.Events, func(i, j int) bool {
return parameters.Events[i].Event.CreatedAt.After(parameters.Events[j].Event.CreatedAt)
return parameters.Events[i].Event.CreatedAt > parameters.Events[j].Event.CreatedAt
})
parameters.Events = parameters.Events[:parameters.MaxEventsToReplay]
}
Expand Down

0 comments on commit a5649b9

Please sign in to comment.