938f698b7a
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
31 lines
836 B
Elixir
31 lines
836 B
Elixir
defmodule Mobilizon.Service.Activity.Utils do
|
|
@moduledoc """
|
|
Utils for activities
|
|
"""
|
|
|
|
alias Mobilizon.Activities.Activity
|
|
alias Mobilizon.Service.Activity, as: ActivityService
|
|
|
|
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
|
|
Map.put(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
|
|
end
|