1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Workers.Cron.NewUsersDigestWorker do
12 use Pleroma.Workers.WorkerHelper, queue: "new_users_digest"
16 if Pleroma.Config.get([Pleroma.Emails.NewUsersDigestEmail, :enabled]) do
17 today = NaiveDateTime.utc_now() |> Timex.beginning_of_day()
21 |> Timex.shift(days: -1)
22 |> Timex.beginning_of_day()
27 order_by: :inserted_at
30 |> where([u], u.inserted_at >= ^a_day_ago and u.inserted_at < ^today)
32 |> Enum.map(fn user ->
35 |> Activity.Queries.by_actor(user.ap_id)
36 |> Activity.Queries.by_type("Create")
37 |> Activity.with_preloaded_object()
38 |> order_by(desc: :inserted_at)
44 |> Activity.Queries.by_actor(user.ap_id)
45 |> Activity.Queries.by_type("Create")
46 |> Repo.aggregate(:count, :id)
48 {user, total_statuses, latest_status}
51 if users_and_statuses != [] do
54 |> where([u], not is_nil(u.email))
56 |> Enum.map(&Pleroma.Emails.NewUsersDigestEmail.new_users(&1, users_and_statuses))
57 |> Enum.each(&Pleroma.Emails.Mailer.deliver/1)