Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Send account events to ozone #708

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
89 changes: 89 additions & 0 deletions api/ozone/moderationdefs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions api/ozone/moderationemitEvent.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion automod/capture/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os"

comatproto "github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/atproto/identity"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/bluesky-social/indigo/automod"
Expand Down Expand Up @@ -38,12 +39,19 @@ func ProcessCaptureRules(eng *automod.Engine, capture AccountCapture) error {
ctx := context.Background()

did := capture.AccountMeta.Identity.DID
handle := capture.AccountMeta.Identity.Handle.String()
dir := identity.NewMockDirectory()
dir.Insert(*capture.AccountMeta.Identity)
eng.Directory = &dir

// initial identity rules
eng.ProcessIdentityEvent(ctx, "new", did)
identEvent := comatproto.SyncSubscribeRepos_Identity{
Did: did.String(),
Handle: &handle,
Seq: 12345,
Time: syntax.DatetimeNow().String(),
}
eng.ProcessIdentityEvent(ctx, identEvent)

// all the post rules
for _, pr := range capture.PostRecords {
Expand Down
5 changes: 4 additions & 1 deletion automod/engine/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ func (c *BaseContext) GetAccountMeta(did syntax.DID) *AccountMeta {
func (c *BaseContext) Increment(name, val string) {
c.effects.Increment(name, val)
}

func (c *BaseContext) IncrementDistinct(name, bucket, val string) {
c.effects.IncrementDistinct(name, bucket, val)
}
Expand Down Expand Up @@ -292,6 +291,10 @@ func (c *RecordContext) TakedownBlob(cid string) {
c.effects.TakedownBlob(cid)
}

func (c *RecordContext) PersistRecordOzoneEvent() {
c.effects.PersistRecordOzoneEvent()
}

func (c *NotificationContext) Reject() {
c.effects.Reject()
}
7 changes: 7 additions & 0 deletions automod/engine/effects.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Effects struct {
RejectEvent bool
// Services, if any, which should blast out a notification about this even (eg, Slack)
NotifyServices []string
// If "true", and Ozone event history is configured/enable, then sent a mod event to ozone backend for this event
PersistOzoneRecordEvent bool
}

// Enqueues the named counter to be incremented at the end of all rule processing. Will automatically increment for all time periods.
Expand Down Expand Up @@ -199,3 +201,8 @@ func (e *Effects) Notify(srv string) {
func (e *Effects) Reject() {
e.RejectEvent = true
}

// Marks that this subject should be recorded in ozone history
func (e *Effects) PersistRecordOzoneEvent() {
e.PersistOzoneRecordEvent = true
}
Loading
Loading