2020-10-12 19:00:50 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-06-04 01:48:21 +02:00
|
|
|
defmodule Mix.Tasks.Pleroma.Digest do
|
|
|
|
use Mix.Task
|
2020-05-13 13:08:10 +02:00
|
|
|
import Mix.Pleroma
|
2019-06-04 01:48:21 +02:00
|
|
|
|
|
|
|
@shortdoc "Manages digest emails"
|
2019-10-03 12:59:49 +02:00
|
|
|
@moduledoc File.read!("docs/administration/CLI_tasks/digest.md")
|
2019-06-04 01:48:21 +02:00
|
|
|
|
|
|
|
def run(["test", nickname | opts]) do
|
2019-06-28 23:52:50 +02:00
|
|
|
Mix.Pleroma.start_pleroma()
|
2019-06-04 01:48:21 +02:00
|
|
|
|
|
|
|
user = Pleroma.User.get_by_nickname(nickname)
|
|
|
|
|
|
|
|
last_digest_emailed_at =
|
|
|
|
with [date] <- opts,
|
|
|
|
{:ok, datetime} <- Timex.parse(date, "{YYYY}-{0M}-{0D}") do
|
|
|
|
datetime
|
|
|
|
else
|
|
|
|
_ -> user.inserted_at
|
|
|
|
end
|
|
|
|
|
|
|
|
patched_user = %{user | last_digest_emailed_at: last_digest_emailed_at}
|
|
|
|
|
2019-08-14 15:46:05 +02:00
|
|
|
with %Swoosh.Email{} = email <- Pleroma.Emails.UserEmail.digest_email(patched_user) do
|
|
|
|
{:ok, _} = Pleroma.Emails.Mailer.deliver(email)
|
|
|
|
|
2020-05-13 13:08:10 +02:00
|
|
|
shell_info("Digest email have been sent to #{nickname} (#{user.email})")
|
2019-08-14 15:46:05 +02:00
|
|
|
else
|
|
|
|
_ ->
|
2020-05-13 13:08:10 +02:00
|
|
|
shell_info("Cound't find any mentions for #{nickname} since #{last_digest_emailed_at}")
|
2019-08-14 15:46:05 +02:00
|
|
|
end
|
2019-06-04 01:48:21 +02:00
|
|
|
end
|
|
|
|
end
|