-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish selected event kinds to relay.nos.social (#30)
The idea is to make it work like https://purplepag.es/what.
- Loading branch information
Showing
10 changed files
with
437 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package app | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/planetary-social/nos-event-service/service/domain" | ||
) | ||
|
||
type EventFilter struct { | ||
filterNewerThan *time.Duration | ||
filterOlderThan *time.Duration | ||
filterLargerThan *int | ||
filterWithMoreTagsThan *int | ||
} | ||
|
||
func NewEventFilter( | ||
filterNewerThan *time.Duration, | ||
filterOlderThan *time.Duration, | ||
filterLargerThan *int, | ||
filterWithMoreTagsThan *int, | ||
) *EventFilter { | ||
return &EventFilter{ | ||
filterNewerThan: filterNewerThan, | ||
filterOlderThan: filterOlderThan, | ||
filterLargerThan: filterLargerThan, | ||
filterWithMoreTagsThan: filterWithMoreTagsThan, | ||
} | ||
} | ||
|
||
func (f EventFilter) IsOk(event domain.Event) bool { | ||
if f.filterOlderThan != nil { | ||
maxPastAllowed := time.Now().Add(-*f.filterOlderThan) | ||
if event.CreatedAt().Before(maxPastAllowed) { | ||
return false | ||
} | ||
} | ||
|
||
if f.filterNewerThan != nil { | ||
maxFutureAllowed := time.Now().Add(*f.filterNewerThan) | ||
if event.CreatedAt().After(maxFutureAllowed) { | ||
return false | ||
} | ||
} | ||
|
||
if f.filterLargerThan != nil && len(event.Raw()) > *f.filterLargerThan { | ||
return false | ||
} | ||
|
||
if f.filterWithMoreTagsThan != nil && len(event.Tags()) > *f.filterWithMoreTagsThan { | ||
return false | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.