Various refactoring and typespec improvements
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -51,11 +51,11 @@ defmodule Mobilizon.Service.Activity.Comment do
|
||||
"object_type" => :comment
|
||||
}
|
||||
|
||||
@spec handle_notification(Keyword.t(), notification_type, Comment.t(), Event.t(), Keyword.t()) ::
|
||||
Keyword.t()
|
||||
defp handle_notification(global_res, function, comment, event, options) do
|
||||
case notify(function, comment, event, options) do
|
||||
{:ok, res} -> Keyword.put(global_res, function, res)
|
||||
_ -> Keyword.put(global_res, function, :error)
|
||||
end
|
||||
{:ok, res} = notify(function, comment, event, options)
|
||||
Keyword.put(global_res, function, res)
|
||||
end
|
||||
|
||||
@spec legacy_notifier_enqueue(map()) :: :ok
|
||||
@@ -66,11 +66,11 @@ defmodule Mobilizon.Service.Activity.Comment do
|
||||
)
|
||||
end
|
||||
|
||||
@type notification_type :: atom()
|
||||
@type notification_type :: :mentionned | :announcement | :organizer
|
||||
|
||||
# An actor is mentionned
|
||||
@spec notify(notification_type(), Comment.t(), Event.t(), Keyword.t()) ::
|
||||
{:ok, Oban.Job.t()} | {:ok, :skipped}
|
||||
{:ok, :enqueued} | {:ok, :skipped}
|
||||
defp notify(
|
||||
:mentionned,
|
||||
%Comment{actor_id: actor_id, id: comment_id, mentions: mentions},
|
||||
|
||||
@@ -10,31 +10,35 @@ defmodule Mobilizon.Service.Activity.Group do
|
||||
@behaviour Activity
|
||||
|
||||
@impl Activity
|
||||
@spec insert_activity(Actor.t(), Keyword.t()) ::
|
||||
{:ok, Job.t()} | {:ok, nil} | {:error, Ecto.Changeset.t()}
|
||||
def insert_activity(group, options \\ [])
|
||||
|
||||
def insert_activity(
|
||||
%Actor{type: :Group, id: group_id},
|
||||
options
|
||||
) do
|
||||
with %Actor{type: :Group} = group <- Actors.get_actor(group_id),
|
||||
subject when not is_nil(subject) <- Keyword.get(options, :subject),
|
||||
actor_id <- Keyword.get(options, :actor_id),
|
||||
default_updater_actor <- Actors.get_actor(actor_id),
|
||||
%Actor{id: actor_id} <-
|
||||
Keyword.get(options, :updater_actor, default_updater_actor),
|
||||
old_group <- Keyword.get(options, :old_group) do
|
||||
ActivityBuilder.enqueue(:build_activity, %{
|
||||
"type" => "group",
|
||||
"subject" => subject,
|
||||
"subject_params" => subject_params(group, subject, old_group),
|
||||
"group_id" => group.id,
|
||||
"author_id" => actor_id,
|
||||
"object_type" => "group",
|
||||
"object_id" => to_string(group.id),
|
||||
"inserted_at" => DateTime.utc_now()
|
||||
})
|
||||
else
|
||||
_ -> {:ok, nil}
|
||||
subject = Keyword.get(options, :subject)
|
||||
actor_id = Keyword.get(options, :actor_id)
|
||||
default_updater_actor = Actors.get_actor(actor_id)
|
||||
%Actor{id: actor_id} = Keyword.get(options, :updater_actor, default_updater_actor)
|
||||
old_group = Keyword.get(options, :old_group)
|
||||
|
||||
case Actors.get_actor(group_id) do
|
||||
%Actor{type: :Group} = group ->
|
||||
ActivityBuilder.enqueue(:build_activity, %{
|
||||
"type" => "group",
|
||||
"subject" => subject,
|
||||
"subject_params" => subject_params(group, subject, old_group),
|
||||
"group_id" => group.id,
|
||||
"author_id" => actor_id,
|
||||
"object_type" => "group",
|
||||
"object_id" => to_string(group.id),
|
||||
"inserted_at" => DateTime.utc_now()
|
||||
})
|
||||
|
||||
nil ->
|
||||
{:ok, nil}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ defmodule Mobilizon.Service.Activity.Utils do
|
||||
|> add_activity_object()
|
||||
end
|
||||
|
||||
@spec add_activity_object(Activity.t()) :: map()
|
||||
@spec add_activity_object(Activity.t()) :: Activity.t()
|
||||
def add_activity_object(%Activity{} = activity) do
|
||||
Map.put(activity, :object, ActivityService.object(activity))
|
||||
%Activity{activity | object: ActivityService.object(activity)}
|
||||
end
|
||||
|
||||
@spec transform_params(map()) :: list()
|
||||
|
||||
Reference in New Issue
Block a user