1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-28 10:52:11 +00:00
mobilizon/lib/service/activity/utils.ex
Thomas Citharel d2372d5700
fixup! Fix depreciated calls of fetch_env!/2 and get_env/2
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2022-09-21 10:15:28 +02:00

41 lines
1 KiB
Elixir

defmodule Mobilizon.Service.Activity.Utils do
@moduledoc """
Utils for activities
"""
alias Mobilizon.Activities.Activity
alias Mobilizon.Service.Activity, as: ActivityService
@env Application.compile_env(:mobilizon, :env)
def transform_activity(%Activity{} = activity) do
activity
|> Map.update(:subject_params, %{}, &transform_params/1)
|> add_activity_object()
end
@spec add_activity_object(Activity.t()) :: Activity.t()
def add_activity_object(%Activity{} = activity) do
%Activity{activity | object: ActivityService.object(activity)}
end
@spec transform_params(map()) :: list()
defp transform_params(params) do
Enum.map(params, fn {key, value} -> %{key: key, value: transform_value(value)} end)
end
defp transform_value(value) when is_list(value) do
Enum.join(value, ",")
end
defp transform_value(value), do: value
@spec maybe_inserted_at :: map()
def maybe_inserted_at do
if @env == :test do
%{}
else
%{"inserted_at" => DateTime.utc_now()}
end
end
end