Refactor Mobilizon.Service.Activity.Member
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
e484728c3d
commit
ae24fa17d5
@ -18,19 +18,19 @@ 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, %{
|
|
||||||
"type" => "member",
|
ActivityBuilder.enqueue(:build_activity, %{
|
||||||
"subject" => subject,
|
"type" => "member",
|
||||||
"subject_params" => get_subject_params(new_member, options),
|
"subject" => subject,
|
||||||
"group_id" => parent_id,
|
"subject_params" => get_subject_params(new_member, options),
|
||||||
"author_id" => author_id,
|
"group_id" => parent_id,
|
||||||
"object_type" => "member",
|
"author_id" => author_id,
|
||||||
"object_id" => object_id,
|
"object_type" => "member",
|
||||||
"inserted_at" => DateTime.utc_now()
|
"object_id" => object_id,
|
||||||
})
|
"inserted_at" => DateTime.utc_now()
|
||||||
end
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def insert_activity(_, _), do: {:ok, nil}
|
def insert_activity(_, _), do: {:ok, nil}
|
||||||
@ -66,38 +66,41 @@ 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:
|
|
||||||
subject_params
|
|
||||||
|> Map.put(
|
|
||||||
:member_actor_federated_username,
|
|
||||||
Actor.preferred_username_and_domain(actor)
|
|
||||||
)
|
|
||||||
|> Map.put(:member_actor_name, actor.name)
|
|
||||||
)
|
|
||||||
|
|
||||||
subject_params =
|
defp maybe_add_actor(subject_params, %Actor{} = actor) do
|
||||||
if(is_nil(old_member),
|
subject_params
|
||||||
do: subject_params,
|
|> Map.put(
|
||||||
else: Map.put(subject_params, :old_role, String.upcase(to_string(old_member.role)))
|
:member_actor_federated_username,
|
||||||
)
|
Actor.preferred_username_and_domain(actor)
|
||||||
|
)
|
||||||
|
|> Map.put(:member_actor_name, actor.name)
|
||||||
|
end
|
||||||
|
|
||||||
if is_nil(moderator),
|
@spec maybe_add_old_member(map(), Member.t() | nil) :: map()
|
||||||
do: subject_params,
|
defp maybe_add_old_member(subject_params, nil), do: subject_params
|
||||||
else:
|
|
||||||
Map.put(
|
defp maybe_add_old_member(subject_params, old_member) do
|
||||||
subject_params,
|
Map.put(subject_params, :old_role, String.upcase(to_string(old_member.role)))
|
||||||
:moderator_preferred_username,
|
end
|
||||||
Actor.preferred_username_and_domain(moderator)
|
|
||||||
)
|
@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(
|
||||||
|
subject_params,
|
||||||
|
:moderator_preferred_username,
|
||||||
|
Actor.preferred_username_and_domain(moderator)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user