Send notification emails to followers and members when a group publishes

a new event

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-11-10 16:36:32 +01:00
parent 800060a926
commit 5c7067b22b
65 changed files with 5491 additions and 2767 deletions

View File

@@ -1626,4 +1626,21 @@ defmodule Mobilizon.Actors do
@spec preload_followers(Actor.t(), boolean) :: Actor.t()
defp preload_followers(actor, true), do: Repo.preload(actor, [:followers])
defp preload_followers(actor, false), do: actor
@spec list_actors_to_notify_from_group_event(Actor.t()) :: Follower.t()
def list_actors_to_notify_from_group_event(%Actor{id: actor_id}) do
Actor
|> join(:left, [a], f in Follower, on: a.id == f.actor_id)
|> join(:left, [a], m in Member, on: a.id == m.actor_id)
|> where(
[a, f],
is_nil(a.domain) and f.target_actor_id == ^actor_id and f.approved == true and
f.notify == true
)
|> or_where(
[a, _f, m],
is_nil(a.domain) and m.parent_id == ^actor_id and m.role in ^@member_roles
)
|> Repo.all()
end
end