2018-12-14 17:41:55 +01:00
|
|
|
defmodule MobilizonWeb.API.Events do
|
|
|
|
@moduledoc """
|
|
|
|
API for Events
|
|
|
|
"""
|
|
|
|
alias Mobilizon.Actors
|
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Service.Formatter
|
|
|
|
alias Mobilizon.Service.ActivityPub
|
|
|
|
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
|
|
|
|
import MobilizonWeb.API.Utils
|
|
|
|
|
2019-03-19 11:16:03 +01:00
|
|
|
@doc """
|
|
|
|
Create an event
|
|
|
|
"""
|
2018-12-14 17:41:55 +01:00
|
|
|
@spec create_event(map()) :: {:ok, Activity.t()} | any()
|
|
|
|
def create_event(
|
|
|
|
%{
|
|
|
|
title: title,
|
|
|
|
description: description,
|
2019-01-21 15:08:22 +01:00
|
|
|
organizer_actor_id: organizer_actor_id,
|
2018-12-14 17:41:55 +01:00
|
|
|
begins_on: begins_on,
|
|
|
|
category: category
|
|
|
|
} = args
|
|
|
|
) do
|
2019-07-04 17:41:06 +02:00
|
|
|
with %Actor{url: url} = actor <-
|
|
|
|
Actors.get_local_actor_with_everything(organizer_actor_id),
|
2018-12-14 17:41:55 +01:00
|
|
|
title <- String.trim(title),
|
|
|
|
mentions <- Formatter.parse_mentions(description),
|
2019-07-23 13:49:22 +02:00
|
|
|
visibility <- Map.get(args, :visibility, :public),
|
2019-05-22 14:12:11 +02:00
|
|
|
{to, cc} <- to_for_actor_and_mentions(actor, mentions, nil, Atom.to_string(visibility)),
|
2018-12-14 17:41:55 +01:00
|
|
|
tags <- Formatter.parse_tags(description),
|
2019-05-22 14:12:11 +02:00
|
|
|
picture <- Map.get(args, :picture, nil),
|
2018-12-14 17:41:55 +01:00
|
|
|
content_html <-
|
|
|
|
make_content_html(
|
|
|
|
description,
|
|
|
|
mentions,
|
|
|
|
tags,
|
|
|
|
"text/plain"
|
|
|
|
),
|
|
|
|
event <-
|
|
|
|
ActivityPubUtils.make_event_data(
|
|
|
|
url,
|
|
|
|
to,
|
|
|
|
title,
|
|
|
|
content_html,
|
2019-05-22 14:12:11 +02:00
|
|
|
picture,
|
2018-12-14 17:41:55 +01:00
|
|
|
tags,
|
|
|
|
cc,
|
|
|
|
%{begins_on: begins_on},
|
|
|
|
category
|
|
|
|
) do
|
|
|
|
ActivityPub.create(%{
|
|
|
|
to: ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
actor: actor,
|
|
|
|
object: event,
|
|
|
|
local: true
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|