; feed/mute — viewer-controlled filtering. ACL (acl.sx) is author-controlled
; visibility; mute is the reader's own preference: hide muted actors or tags.
; Like ACL it is per-viewer and applied per request, never cached.
;
; Requires: lib/feed/normalize.sx, lib/feed/stream.sx, lib/feed/fanout.sx
; (feed/-elem?).

; drop activities authored by a muted actor
(define
  feed/mute-actors
  (fn
    (stream actors)
    (feed/filter
      stream
      (fn (a) (not (feed/-elem? (get a :actor) actors))))))

; drop activities carrying any muted tag
(define
  feed/mute-tags
  (fn
    (stream tags)
    (feed/filter
      stream
      (fn (a) (not (some (fn (t) (feed/-elem? t tags)) (get a :tags)))))))

; drop activities about a muted object (thread mute)
(define
  feed/mute-objects
  (fn
    (stream objects)
    (feed/filter
      stream
      (fn (a) (not (feed/-elem? (get a :object) objects))))))

; apply a viewer preference bag: {:mute-actors (...) :mute-tags (...) :mute-objects (...)}
(define
  feed/apply-prefs
  (fn
    (stream prefs)
    (feed/mute-objects
      (feed/mute-tags
        (feed/mute-actors stream (get prefs :mute-actors (list)))
        (get prefs :mute-tags (list)))
      (get prefs :mute-objects (list)))))
