@@ -121,6 +121,32 @@ defmodule Mobilizon.Activities do
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@spec list_group_activities_for_recap(
|
||||
integer() | String.t(),
|
||||
integer() | String.t(),
|
||||
DateTime.t() | nil
|
||||
) :: [Activity.t()]
|
||||
def list_group_activities_for_recap(
|
||||
group_id,
|
||||
actor_asking_id,
|
||||
last_sent_at \\ nil
|
||||
) do
|
||||
query =
|
||||
Activity
|
||||
|> where([a], a.group_id == ^group_id)
|
||||
|> join(:inner, [a], m in Member,
|
||||
on: m.parent_id == a.group_id and m.actor_id == ^actor_asking_id
|
||||
)
|
||||
|> where([a, m], a.inserted_at >= m.member_since)
|
||||
|> order_by(desc: :inserted_at)
|
||||
|> preload([:author, :group])
|
||||
|
||||
query =
|
||||
if is_nil(last_sent_at), do: query, else: where(query, [a], a.inserted_at >= ^last_sent_at)
|
||||
|
||||
Repo.all(query)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single activity.
|
||||
|
||||
|
||||
@@ -1474,12 +1474,9 @@ defmodule Mobilizon.Actors do
|
||||
|
||||
@spec groups_member_of_query(integer | String.t()) :: Ecto.Query.t()
|
||||
defp groups_member_of_query(actor_id) do
|
||||
from(
|
||||
a in Actor,
|
||||
join: m in Member,
|
||||
on: a.id == m.parent_id,
|
||||
where: m.actor_id == ^actor_id
|
||||
)
|
||||
Actor
|
||||
|> join(:inner, [a], m in Member, on: a.id == m.parent_id)
|
||||
|> where([a, m], m.actor_id == ^actor_id and m.role in ^@member_roles)
|
||||
end
|
||||
|
||||
@spec groups_query :: Ecto.Query.t()
|
||||
|
||||
@@ -17,7 +17,13 @@ defmodule Mobilizon.Users do
|
||||
|
||||
defenum(UserRole, :user_role, [:administrator, :moderator, :user])
|
||||
|
||||
defenum(NotificationPendingNotificationDelay, none: 0, direct: 1, one_hour: 5, one_day: 10)
|
||||
defenum(NotificationPendingNotificationDelay,
|
||||
none: 0,
|
||||
direct: 1,
|
||||
one_hour: 5,
|
||||
one_day: 10,
|
||||
one_week: 15
|
||||
)
|
||||
|
||||
@confirmation_token_length 30
|
||||
|
||||
@@ -520,6 +526,18 @@ defmodule Mobilizon.Users do
|
||||
|> Repo.insert(on_conflict: :replace_all, conflict_target: [:user_id, :key, :method])
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns a stream of users which want to have a scheduled recap
|
||||
"""
|
||||
@spec stream_users_for_recap :: Enum.t()
|
||||
def stream_users_for_recap do
|
||||
User
|
||||
|> filter_activated(true)
|
||||
|> join(:inner, [u], s in Setting, on: s.user_id == u.id)
|
||||
|> where([_u, s], s.group_notifications in [:one_hour, :one_day, :one_week])
|
||||
|> Repo.stream()
|
||||
end
|
||||
|
||||
@spec user_by_email_query(String.t(), boolean | nil, boolean()) :: Ecto.Query.t()
|
||||
defp user_by_email_query(email, activated, unconfirmed) do
|
||||
User
|
||||
|
||||
Reference in New Issue
Block a user