1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-22 16:03:25 +00:00
mobilizon/lib/service/activity/event.ex
Thomas Citharel 86c2512c62
WIP
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-06-04 13:32:05 +02:00

47 lines
1.3 KiB
Elixir

defmodule Mobilizon.Service.Activity.Event do
@moduledoc """
Insert an event activity
"""
alias Mobilizon.{Actors, Events}
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}
@impl Activity
def get_object(event_id) do
case Events.get_event(event_id) do
{:ok, %Event{} = event} -> event
_ -> nil
end
end
end