Deal only with the payload

This commit is contained in:
niten 2023-05-18 13:27:36 -07:00
parent 3d6f69173b
commit fa9553ec83
1 changed files with 10 additions and 15 deletions

View File

@ -21,19 +21,14 @@
(defn listen! [& {app :app mqtt-client :mqtt-client topic :topic logger :logger}] (defn listen! [& {app :app mqtt-client :mqtt-client topic :topic logger :logger}]
(let [note-chan (mqtt/subscribe! mqtt-client topic)] (let [note-chan (mqtt/subscribe! mqtt-client topic)]
(go-loop [note (<! note-chan)] (go-loop [note-msg (<! note-chan)]
(if note (if note-msg
(do (if (t/validate Notification note) (let [note (-> note-msg :payload (update :urgency keyword))]
(notify/send-notification! mqtt-client (if (t/validate Notification note)
{ (notify/send-notification! mqtt-client (assoc note :app app))
:app app (let [err (humanize (t/explain Notification note))]
:summary (:summary note) (log/error! logger (format "rejecting invalid notification: %s (%s)\n%s"
:body (:body note) (:summary err) (:body err)
:urgency (-> note :urgency (keyword)) (pprint-to-string note)))))
}) (recur (<! note-chan)))
(let [err (humanize (t/explain Notification note))]
(log/error! logger (format "rejecting invalid notification: %s (%s)\n%s"
(:summary err) (:body err)
(pprint-to-string note)))))
(recur (<! note-chan)))
(log/info! logger "stopping"))))) (log/info! logger "stopping")))))