From 694ff7169f684a2e4a557619e712e058d6b31e6c Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Wed, 22 Jan 2025 17:38:51 -0800 Subject: [PATCH] remove push-notification support from automod engine (never used) The idea was to integrate the automod framework with other services which do push notifications. This never happened, and this code is dead/untested, so removing for now. This kind of functionality might be useful (we have lots of interaction spam!) and could be pulled back in from git history if we ever need it. --- automod/engine/context.go | 33 ----------------- automod/engine/engine.go | 71 ------------------------------------- automod/engine/ruleset.go | 11 ------ automod/engine/ruletypes.go | 1 - automod/pkg.go | 2 -- automod/rules/all.go | 3 -- 6 files changed, 121 deletions(-) diff --git a/automod/engine/context.go b/automod/engine/context.go index 7e24d1b4..dde90327 100644 --- a/automod/engine/context.go +++ b/automod/engine/context.go @@ -91,22 +91,6 @@ type OzoneEvent struct { Event toolsozone.ModerationDefs_ModEventView_Event } -// Originally intended for push notifications, but can also work for any inter-account notification. -type NotificationContext struct { - AccountContext - - Recipient AccountMeta - Notification NotificationMeta -} - -// Additional notification metadata, with fields aligning with the `app.bsky.notification.listNotifications` Lexicon schemas -type NotificationMeta struct { - // Expected values are 'like', 'repost', 'follow', 'mention', 'reply', and 'quote'; arbitrary values may be added in the future. - Reason string - // The content (atproto record) which was the cause of this notification. Could be a post with a mention, or a like, follow, or repost record. - Subject syntax.ATURI -} - // Checks that op has expected fields, based on the action type func (op *RecordOp) Validate() error { switch op.Action { @@ -198,19 +182,6 @@ func NewRecordContext(ctx context.Context, eng *Engine, meta AccountMeta, op Rec } } -func NewNotificationContext(ctx context.Context, eng *Engine, sender, recipient AccountMeta, reason string, subject syntax.ATURI) NotificationContext { - ac := NewAccountContext(ctx, eng, sender) - ac.BaseContext.Logger = ac.BaseContext.Logger.With("recipient", recipient.Identity.DID, "reason", reason, "subject", subject.String()) - return NotificationContext{ - AccountContext: ac, - Recipient: recipient, - Notification: NotificationMeta{ - Reason: reason, - Subject: subject, - }, - } -} - // fetch relationship metadata between this account and another account func (c *AccountContext) GetAccountRelationship(other syntax.DID) AccountRelationship { rel, err := c.engine.GetAccountRelationship(c.Ctx, c.Account.Identity.DID, other) @@ -322,7 +293,3 @@ func (c *RecordContext) AcknowledgeRecord() { func (c *RecordContext) TakedownBlob(cid string) { c.effects.TakedownBlob(cid) } - -func (c *NotificationContext) Reject() { - c.effects.Reject() -} diff --git a/automod/engine/engine.go b/automod/engine/engine.go index 1125f89a..c6d8bab6 100644 --- a/automod/engine/engine.go +++ b/automod/engine/engine.go @@ -296,66 +296,6 @@ func (eng *Engine) ProcessRecordOp(ctx context.Context, op RecordOp) error { return nil } -// returns a boolean indicating "block the event" -// NOTE: this code is unused and should be removed -func (eng *Engine) ProcessNotificationEvent(ctx context.Context, senderDID, recipientDID syntax.DID, reason string, subject syntax.ATURI) (bool, error) { - eventProcessCount.WithLabelValues("notif").Inc() - start := time.Now() - defer func() { - duration := time.Since(start) - eventProcessDuration.WithLabelValues("notif").Observe(duration.Seconds()) - }() - - // similar to an HTTP server, we want to recover any panics from rule execution - defer func() { - if r := recover(); r != nil { - eng.Logger.Error("automod event execution exception", "err", r, "sender", senderDID, "recipient", recipientDID) - } - }() - var cancel context.CancelFunc - ctx, cancel = context.WithTimeout(ctx, time.Second*5) - defer cancel() - - senderIdent, err := eng.Directory.LookupDID(ctx, senderDID) - if err != nil { - eventErrorCount.WithLabelValues("notif").Inc() - return false, fmt.Errorf("resolving identity: %w", err) - } - if senderIdent == nil { - eventErrorCount.WithLabelValues("notif").Inc() - return false, fmt.Errorf("identity not found for sender DID: %s", senderDID.String()) - } - - recipientIdent, err := eng.Directory.LookupDID(ctx, recipientDID) - if err != nil { - eventErrorCount.WithLabelValues("notif").Inc() - return false, fmt.Errorf("resolving identity: %w", err) - } - if recipientIdent == nil { - eventErrorCount.WithLabelValues("notif").Inc() - return false, fmt.Errorf("identity not found for sender DID: %s", recipientDID.String()) - } - - senderMeta, err := eng.GetAccountMeta(ctx, senderIdent) - if err != nil { - eventErrorCount.WithLabelValues("notif").Inc() - return false, fmt.Errorf("failed to fetch account metadata: %w", err) - } - recipientMeta, err := eng.GetAccountMeta(ctx, recipientIdent) - if err != nil { - eventErrorCount.WithLabelValues("notif").Inc() - return false, fmt.Errorf("failed to fetch account metadata: %w", err) - } - - nc := NewNotificationContext(ctx, eng, *senderMeta, *recipientMeta, reason, subject) - if err := eng.Rules.CallNotificationRules(&nc); err != nil { - eventErrorCount.WithLabelValues("notif").Inc() - return false, fmt.Errorf("rule execution failed: %w", err) - } - eng.CanonicalLogLineNotification(&nc) - return nc.effects.RejectEvent, nil -} - // Purge metadata caches for a specific account. func (e *Engine) PurgeAccountCaches(ctx context.Context, did syntax.DID) error { e.Logger.Debug("purging account caches", "did", did.String()) @@ -391,14 +331,3 @@ func (e *Engine) CanonicalLogLineRecord(c *RecordContext) { "recordReports", len(c.effects.RecordReports), ) } - -func (e *Engine) CanonicalLogLineNotification(c *NotificationContext) { - c.Logger.Info("canonical-event-line", - "accountLabels", c.effects.AccountLabels, - "accountFlags", c.effects.AccountFlags, - "accountTags", c.effects.AccountTags, - "accountTakedown", c.effects.AccountTakedown, - "accountReports", len(c.effects.AccountReports), - "reject", c.effects.RejectEvent, - ) -} diff --git a/automod/engine/ruleset.go b/automod/engine/ruleset.go index 4c72ef8f..1d06e23a 100644 --- a/automod/engine/ruleset.go +++ b/automod/engine/ruleset.go @@ -18,7 +18,6 @@ type RuleSet struct { IdentityRules []IdentityRuleFunc AccountRules []AccountRuleFunc BlobRules []BlobRuleFunc - NotificationRules []NotificationRuleFunc OzoneEventRules []OzoneEventRuleFunc } @@ -101,16 +100,6 @@ func (r *RuleSet) CallAccountRules(c *AccountContext) error { return nil } -func (r *RuleSet) CallNotificationRules(c *NotificationContext) error { - for _, f := range r.NotificationRules { - err := f(c) - if err != nil { - c.Logger.Error("notification rule execution failed", "err", err) - } - } - return nil -} - func (r *RuleSet) CallOzoneEventRules(c *OzoneEventContext) error { for _, f := range r.OzoneEventRules { err := f(c) diff --git a/automod/engine/ruletypes.go b/automod/engine/ruletypes.go index 27d4a149..534f7283 100644 --- a/automod/engine/ruletypes.go +++ b/automod/engine/ruletypes.go @@ -11,5 +11,4 @@ type RecordRuleFunc = func(c *RecordContext) error type PostRuleFunc = func(c *RecordContext, post *appbsky.FeedPost) error type ProfileRuleFunc = func(c *RecordContext, profile *appbsky.ActorProfile) error type BlobRuleFunc = func(c *RecordContext, blob lexutil.LexBlob, data []byte) error -type NotificationRuleFunc = func(c *NotificationContext) error type OzoneEventRuleFunc = func(c *OzoneEventContext) error diff --git a/automod/pkg.go b/automod/pkg.go index e0458969..7d5faa06 100644 --- a/automod/pkg.go +++ b/automod/pkg.go @@ -18,7 +18,6 @@ type SlackNotifier = engine.SlackNotifier type AccountContext = engine.AccountContext type RecordContext = engine.RecordContext type OzoneEventContext = engine.OzoneEventContext -type NotificationContext = engine.NotificationContext type RecordOp = engine.RecordOp type IdentityRuleFunc = engine.IdentityRuleFunc @@ -26,7 +25,6 @@ type RecordRuleFunc = engine.RecordRuleFunc type PostRuleFunc = engine.PostRuleFunc type ProfileRuleFunc = engine.ProfileRuleFunc type BlobRuleFunc = engine.BlobRuleFunc -type NotificationRuleFunc = engine.NotificationRuleFunc type OzoneEventRuleFunc = engine.OzoneEventRuleFunc var ( diff --git a/automod/rules/all.go b/automod/rules/all.go index 8d66b509..facb503d 100644 --- a/automod/rules/all.go +++ b/automod/rules/all.go @@ -56,9 +56,6 @@ func DefaultRules() automod.RuleSet { BlobRules: []automod.BlobRuleFunc{ //BlobVerifyRule, }, - NotificationRules: []automod.NotificationRuleFunc{ - // none - }, OzoneEventRules: []automod.OzoneEventRuleFunc{ HarassmentProtectionOzoneEventRule, }, -- 2.51.2