diff --git a/automod/engine/context.go b/automod/engine/context.go index dde90327..2fd17b78 100644 --- a/automod/engine/context.go +++ b/automod/engine/context.go @@ -242,6 +242,10 @@ func (c *AccountContext) AddAccountLabel(val string) { c.effects.AddAccountLabel(val) } +func (c *AccountContext) RemoveAccountLabel(val string) { + c.effects.RemoveAccountLabel(val) +} + func (c *AccountContext) AddAccountTag(val string) { c.effects.AddAccountTag(val) } @@ -270,6 +274,10 @@ func (c *RecordContext) AddRecordLabel(val string) { c.effects.AddRecordLabel(val) } +func (c *RecordContext) RemoveRecordLabel(val string) { + c.effects.RemoveRecordLabel(val) +} + func (c *RecordContext) AddRecordTag(val string) { c.effects.AddRecordTag(val) } diff --git a/automod/engine/effects.go b/automod/engine/effects.go index 9e67109c..0eedb6d1 100644 --- a/automod/engine/effects.go +++ b/automod/engine/effects.go @@ -28,6 +28,8 @@ type Effects struct { CounterDistinctIncrements []CounterDistinctRef // TODO: better variable names // Label values which should be applied to the overall account, as a result of rule execution. AccountLabels []string + // Label values which should be removed from the overall account, as a result of rule execution. + RemovedAccountLabels []string // Moderation tags (similar to labels, but private) which should be applied to the overall account, as a result of rule execution. AccountTags []string // automod flags (metadata) which should be applied to the account as a result of rule execution. @@ -42,6 +44,8 @@ type Effects struct { AccountAcknowledge bool // Same as "AccountLabels", but at record-level RecordLabels []string + // Same as "RemovedRecordLabels", but at record-level + RemovedRecordLabels []string // Same as "AccountTags", but at record-level RecordTags []string // Same as "AccountFlags", but at record-level @@ -98,6 +102,18 @@ func (e *Effects) AddAccountLabel(val string) { e.AccountLabels = append(e.AccountLabels, val) } +// Enqueues the provided label (string value) to be removed from the account at the end of rule processing. +func (e *Effects) RemoveAccountLabel(val string) { + e.mu.Lock() + defer e.mu.Unlock() + for _, v := range e.RemovedRecordLabels { + if v == val { + return + } + } + e.RemovedAccountLabels = append(e.RemovedAccountLabels, val) +} + // Enqueues the provided label (string value) to be added to the account at the end of rule processing. func (e *Effects) AddAccountTag(val string) { e.mu.Lock() @@ -164,6 +180,18 @@ func (e *Effects) AddRecordLabel(val string) { e.RecordLabels = append(e.RecordLabels, val) } +// Enqueues the provided label (string value) to be removed from the record at the end of rule processing. +func (e *Effects) RemoveRecordLabel(val string) { + e.mu.Lock() + defer e.mu.Unlock() + for _, v := range e.RemovedRecordLabels { + if v == val { + return + } + } + e.RemovedRecordLabels = append(e.RemovedRecordLabels, val) +} + // Enqueues the provided tag (string value) to be added to the record at the end of rule processing. func (e *Effects) AddRecordTag(val string) { e.mu.Lock()