1 defmodule Mix.Tasks.Pleroma.Digest do
4 @shortdoc "Manages digest emails"
8 ## Send digest email since given date (user registration date by default)
9 ignoring user activity status.
11 ``mix pleroma.digest test <nickname> <since_date>``
13 Example: ``mix pleroma.digest test donaldtheduck 2019-05-20``
15 def run(["test", nickname | opts]) do
16 Mix.Pleroma.start_pleroma()
18 user = Pleroma.User.get_by_nickname(nickname)
20 last_digest_emailed_at =
22 {:ok, datetime} <- Timex.parse(date, "{YYYY}-{0M}-{0D}") do
28 patched_user = %{user | last_digest_emailed_at: last_digest_emailed_at}
30 with %Swoosh.Email{} = email <- Pleroma.Emails.UserEmail.digest_email(patched_user) do
31 {:ok, _} = Pleroma.Emails.Mailer.deliver(email)
33 Mix.shell().info("Digest email have been sent to #{nickname} (#{user.email})")
37 "Cound't find any mentions for #{nickname} since #{last_digest_emailed_at}"