;; lib/mod/activity.sx — export decisions as ActivityPub-shaped events.
;;
;; The rose-ash platform propagates cross-domain effects as ActivityPub-shaped
;; activities. A moderation decision maps to a moderation verb so the rest of the
;; platform (and federated peers) can act on it: remove→Delete, ban→Block,
;; hide/escalate→Flag, keep→no activity. The precise mod action is preserved in
;; :action so a consumer can disambiguate (e.g. hide vs escalate, both Flag).

(define
  mod/action->verb
  (fn
    (action)
    (cond
      ((= action "remove") "Delete")
      ((= action "ban") "Block")
      ((= action "hide") "Flag")
      ((= action "escalate") "Flag")
      (true nil))))

(define
  mod/decision->activity
  (fn
    (d actor)
    (let
      ((verb (mod/action->verb (get d :action))))
      (if (nil? verb) nil {:type verb :action (get d :action) :actor actor :summary (str "moderation/" (get d :action) " via " (get d :rule)) :object (get d :report-id) :rule (get d :rule)}))))

;; map a batch of decisions to activities, dropping the no-op keeps
(define
  mod/decisions->activities
  (fn
    (decisions actor)
    (reduce
      (fn
        (acc d)
        (let
          ((a (mod/decision->activity d actor)))
          (if (nil? a) acc (append acc (list a)))))
      (list)
      decisions)))
