Refactor Mobilizon.Service.Activity.Member
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
e484728c3d
commit
ae24fa17d5
@ -18,8 +18,9 @@ defmodule Mobilizon.Service.Activity.Member do
|
|||||||
) do
|
) do
|
||||||
subject = Keyword.get(options, :subject)
|
subject = Keyword.get(options, :subject)
|
||||||
|
|
||||||
with author_id <- get_author(new_member, options),
|
author_id = get_author(new_member, options)
|
||||||
object_id <- if(subject == "member_removed", do: nil, else: to_string(member_id)) do
|
object_id = if(subject == "member_removed", do: nil, else: to_string(member_id))
|
||||||
|
|
||||||
ActivityBuilder.enqueue(:build_activity, %{
|
ActivityBuilder.enqueue(:build_activity, %{
|
||||||
"type" => "member",
|
"type" => "member",
|
||||||
"subject" => subject,
|
"subject" => subject,
|
||||||
@ -31,7 +32,6 @@ defmodule Mobilizon.Service.Activity.Member do
|
|||||||
"inserted_at" => DateTime.utc_now()
|
"inserted_at" => DateTime.utc_now()
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def insert_activity(_, _), do: {:ok, nil}
|
def insert_activity(_, _), do: {:ok, nil}
|
||||||
|
|
||||||
@ -66,34 +66,37 @@ defmodule Mobilizon.Service.Activity.Member do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
moderator = Keyword.get(options, :moderator)
|
%{
|
||||||
old_member = Keyword.get(options, :old_member)
|
|
||||||
|
|
||||||
subject_params = %{
|
|
||||||
member_role: String.upcase(to_string(role))
|
member_role: String.upcase(to_string(role))
|
||||||
}
|
}
|
||||||
|
|> maybe_add_actor(actor)
|
||||||
|
|> maybe_add_old_member(Keyword.get(options, :old_member))
|
||||||
|
|> maybe_add_moderator(Keyword.get(options, :moderator))
|
||||||
|
end
|
||||||
|
|
||||||
subject_params =
|
@spec maybe_add_actor(map(), Actor.t() | nil) :: map()
|
||||||
if(is_nil(actor),
|
defp maybe_add_actor(subject_params, nil), do: subject_params
|
||||||
do: subject_params,
|
|
||||||
else:
|
defp maybe_add_actor(subject_params, %Actor{} = actor) do
|
||||||
subject_params
|
subject_params
|
||||||
|> Map.put(
|
|> Map.put(
|
||||||
:member_actor_federated_username,
|
:member_actor_federated_username,
|
||||||
Actor.preferred_username_and_domain(actor)
|
Actor.preferred_username_and_domain(actor)
|
||||||
)
|
)
|
||||||
|> Map.put(:member_actor_name, actor.name)
|
|> Map.put(:member_actor_name, actor.name)
|
||||||
)
|
end
|
||||||
|
|
||||||
subject_params =
|
@spec maybe_add_old_member(map(), Member.t() | nil) :: map()
|
||||||
if(is_nil(old_member),
|
defp maybe_add_old_member(subject_params, nil), do: subject_params
|
||||||
do: subject_params,
|
|
||||||
else: Map.put(subject_params, :old_role, String.upcase(to_string(old_member.role)))
|
|
||||||
)
|
|
||||||
|
|
||||||
if is_nil(moderator),
|
defp maybe_add_old_member(subject_params, old_member) do
|
||||||
do: subject_params,
|
Map.put(subject_params, :old_role, String.upcase(to_string(old_member.role)))
|
||||||
else:
|
end
|
||||||
|
|
||||||
|
@spec maybe_add_moderator(map(), Actor.t() | nil) :: map()
|
||||||
|
defp maybe_add_moderator(subject_params, nil), do: subject_params
|
||||||
|
|
||||||
|
defp maybe_add_moderator(subject_params, moderator) do
|
||||||
Map.put(
|
Map.put(
|
||||||
subject_params,
|
subject_params,
|
||||||
:moderator_preferred_username,
|
:moderator_preferred_username,
|
||||||
|
Loading…
Reference in New Issue
Block a user