1 defmodule Pleroma.DigestEmailWorker do
5 config = Pleroma.Config.get([:email_notifications, :digest])
6 negative_interval = -Map.fetch!(config, :interval)
7 inactivity_threshold = Map.fetch!(config, :inactivity_threshold)
8 inactive_users_query = Pleroma.User.list_inactive_users_query(inactivity_threshold)
10 now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
12 from(u in inactive_users_query,
13 where: fragment(~s(? #> '{"email_notifications","digest"}' @> 'true'), u.info),
14 where: u.last_digest_emailed_at < datetime_add(^now, ^negative_interval, "day"),
23 def run([user | users]) do
24 with %Swoosh.Email{} = email <- Pleroma.Emails.UserEmail.digest_email(user) do
25 Pleroma.Emails.Mailer.deliver_async(email)
28 Pleroma.User.touch_last_digest_emailed_at(user)