2021-02-24 18:06:48 +00:00
|
|
|
defmodule Mobilizon.Service.Activity.Event do
|
|
|
|
@moduledoc """
|
|
|
|
Insert an event activity
|
|
|
|
"""
|
2021-03-23 14:18:03 +00:00
|
|
|
alias Mobilizon.{Actors, Events}
|
2021-02-24 18:06:48 +00:00
|
|
|
alias Mobilizon.Events.Event
|
|
|
|
alias Mobilizon.Service.Activity
|
|
|
|
alias Mobilizon.Service.Workers.ActivityBuilder
|
|
|
|
|
|
|
|
@behaviour Activity
|
|
|
|
|
|
|
|
@impl Activity
|
|
|
|
def insert_activity(event, options \\ [])
|
|
|
|
|
|
|
|
def insert_activity(
|
|
|
|
%Event{attributed_to_id: attributed_to_id, organizer_actor_id: organizer_actor_id} =
|
|
|
|
event,
|
|
|
|
options
|
|
|
|
)
|
|
|
|
when not is_nil(attributed_to_id) do
|
|
|
|
actor = Actors.get_actor(organizer_actor_id)
|
|
|
|
group = Actors.get_actor(attributed_to_id)
|
|
|
|
subject = Keyword.fetch!(options, :subject)
|
|
|
|
|
|
|
|
ActivityBuilder.enqueue(:build_activity, %{
|
|
|
|
"type" => "event",
|
|
|
|
"subject" => subject,
|
|
|
|
"subject_params" => %{event_uuid: event.uuid, event_title: event.title},
|
|
|
|
"group_id" => group.id,
|
|
|
|
"author_id" => actor.id,
|
|
|
|
"object_type" => "event",
|
|
|
|
"object_id" => if(subject != "event_deleted", do: to_string(event.id), else: nil),
|
|
|
|
"inserted_at" => DateTime.utc_now()
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl Activity
|
|
|
|
def insert_activity(_, _), do: {:ok, nil}
|
2021-03-23 14:18:03 +00:00
|
|
|
|
|
|
|
@impl Activity
|
|
|
|
def get_object(event_id) do
|
|
|
|
case Events.get_event(event_id) do
|
|
|
|
{:ok, %Event{} = event} -> event
|
|
|
|
_ -> nil
|
|
|
|
end
|
|
|
|
end
|
2021-02-24 18:06:48 +00:00
|
|
|
end
|