Correctly handle event update
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -110,6 +110,24 @@ defmodule Mobilizon.Actors.Actor do
|
||||
|> unique_constraint(:url, name: :actors_url_index)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def update_changeset(%Actor{} = actor, attrs) do
|
||||
actor
|
||||
|> Ecto.Changeset.cast(attrs, [
|
||||
:name,
|
||||
:summary,
|
||||
:keys,
|
||||
:manually_approves_followers,
|
||||
:suspended,
|
||||
:user_id
|
||||
])
|
||||
|> cast_embed(:avatar)
|
||||
|> cast_embed(:banner)
|
||||
|> validate_required([:preferred_username, :keys, :suspended, :url])
|
||||
|> unique_constraint(:preferred_username, name: :actors_preferred_username_domain_type_index)
|
||||
|> unique_constraint(:url, name: :actors_url_index)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Changeset for person registration
|
||||
"""
|
||||
|
||||
@@ -124,7 +124,7 @@ defmodule Mobilizon.Actors do
|
||||
"""
|
||||
def update_actor(%Actor{} = actor, attrs) do
|
||||
actor
|
||||
|> Actor.changeset(attrs)
|
||||
|> Actor.update_changeset(attrs)
|
||||
|> delete_files_if_media_changed()
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@@ -54,10 +54,10 @@ defmodule Mobilizon.Events.Event do
|
||||
field(:online_address, :string)
|
||||
field(:phone_address, :string)
|
||||
field(:category, :string)
|
||||
embeds_one(:options, Mobilizon.Events.EventOptions)
|
||||
embeds_one(:options, Mobilizon.Events.EventOptions, on_replace: :update)
|
||||
belongs_to(:organizer_actor, Actor, foreign_key: :organizer_actor_id)
|
||||
belongs_to(:attributed_to, Actor, foreign_key: :attributed_to_id)
|
||||
many_to_many(:tags, Tag, join_through: "events_tags")
|
||||
many_to_many(:tags, Tag, join_through: "events_tags", on_replace: :delete)
|
||||
many_to_many(:participants, Actor, join_through: Participant)
|
||||
has_many(:tracks, Track)
|
||||
has_many(:sessions, Session)
|
||||
@@ -98,6 +98,38 @@ defmodule Mobilizon.Events.Event do
|
||||
])
|
||||
end
|
||||
|
||||
@doc false
|
||||
def update_changeset(%Event{} = event, attrs) do
|
||||
event
|
||||
|> Ecto.Changeset.cast(attrs, [
|
||||
:title,
|
||||
:slug,
|
||||
:description,
|
||||
:begins_on,
|
||||
:ends_on,
|
||||
:category,
|
||||
:status,
|
||||
:visibility,
|
||||
:publish_at,
|
||||
:online_address,
|
||||
:phone_address,
|
||||
:picture_id,
|
||||
:physical_address_id
|
||||
])
|
||||
|> cast_embed(:options)
|
||||
|> put_tags(attrs)
|
||||
|> validate_required([
|
||||
:title,
|
||||
:begins_on,
|
||||
:organizer_actor_id,
|
||||
:url,
|
||||
:uuid
|
||||
])
|
||||
end
|
||||
|
||||
defp put_tags(changeset, %{"tags" => tags}), do: put_assoc(changeset, :tags, tags)
|
||||
defp put_tags(changeset, _), do: changeset
|
||||
|
||||
def can_event_be_managed_by(%Event{organizer_actor_id: organizer_actor_id}, actor_id)
|
||||
when organizer_actor_id == actor_id do
|
||||
{:event_can_be_managed, true}
|
||||
|
||||
@@ -227,11 +227,12 @@ defmodule Mobilizon.Events do
|
||||
:tracks,
|
||||
:tags,
|
||||
:participants,
|
||||
:physical_address
|
||||
:physical_address,
|
||||
:picture
|
||||
])}
|
||||
|
||||
err ->
|
||||
{:error, err}
|
||||
_err ->
|
||||
{:error, :event_not_found}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -435,7 +436,8 @@ defmodule Mobilizon.Events do
|
||||
"""
|
||||
def update_event(%Event{} = event, attrs) do
|
||||
event
|
||||
|> Event.changeset(attrs)
|
||||
|> Repo.preload(:tags)
|
||||
|> Event.update_changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@ defmodule MobilizonWeb.API.Events do
|
||||
@moduledoc """
|
||||
API for Events
|
||||
"""
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
|
||||
alias MobilizonWeb.API.Utils
|
||||
@@ -16,13 +15,13 @@ defmodule MobilizonWeb.API.Events do
|
||||
with %{
|
||||
title: title,
|
||||
physical_address: physical_address,
|
||||
visibility: visibility,
|
||||
picture: picture,
|
||||
content_html: content_html,
|
||||
tags: tags,
|
||||
to: to,
|
||||
cc: cc,
|
||||
begins_on: begins_on,
|
||||
ends_on: ends_on,
|
||||
category: category,
|
||||
options: options
|
||||
} <- prepare_args(args),
|
||||
@@ -34,7 +33,13 @@ defmodule MobilizonWeb.API.Events do
|
||||
content_html,
|
||||
picture,
|
||||
tags,
|
||||
%{begins_on: begins_on, physical_address: physical_address, category: category, options: options}
|
||||
%{
|
||||
begins_on: begins_on,
|
||||
ends_on: ends_on,
|
||||
physical_address: physical_address,
|
||||
category: category,
|
||||
options: options
|
||||
}
|
||||
) do
|
||||
ActivityPub.create(%{
|
||||
to: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
@@ -48,30 +53,28 @@ defmodule MobilizonWeb.API.Events do
|
||||
@doc """
|
||||
Update an event
|
||||
"""
|
||||
@spec update_event(map()) :: {:ok, Activity.t(), Event.t()} | any()
|
||||
@spec update_event(map(), Event.t()) :: {:ok, Activity.t(), Event.t()} | any()
|
||||
def update_event(
|
||||
%{
|
||||
organizer_actor: organizer_actor,
|
||||
event: event
|
||||
} = args
|
||||
organizer_actor: organizer_actor
|
||||
} = args,
|
||||
%Event{} = event
|
||||
) do
|
||||
with %{
|
||||
with args <- Map.put(args, :tags, Map.get(args, :tags, [])),
|
||||
%{
|
||||
title: title,
|
||||
physical_address: physical_address,
|
||||
visibility: visibility,
|
||||
picture: picture,
|
||||
content_html: content_html,
|
||||
tags: tags,
|
||||
to: to,
|
||||
cc: cc,
|
||||
begins_on: begins_on,
|
||||
ends_on: ends_on,
|
||||
category: category,
|
||||
options: options
|
||||
} <-
|
||||
prepare_args(
|
||||
args
|
||||
|> update_args(event)
|
||||
),
|
||||
prepare_args(Map.merge(event, args)),
|
||||
event <-
|
||||
ActivityPubUtils.make_event_data(
|
||||
organizer_actor.url,
|
||||
@@ -82,34 +85,24 @@ defmodule MobilizonWeb.API.Events do
|
||||
tags,
|
||||
%{
|
||||
begins_on: begins_on,
|
||||
ends_on: ends_on,
|
||||
physical_address: physical_address,
|
||||
category: Map.get(args, :category),
|
||||
category: category,
|
||||
options: options
|
||||
}
|
||||
},
|
||||
event.uuid,
|
||||
event.url
|
||||
) do
|
||||
ActivityPub.update(%{
|
||||
to: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
actor: organizer_actor,
|
||||
actor: organizer_actor.url,
|
||||
cc: [],
|
||||
object: event,
|
||||
local: true
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
defp update_args(args, event) do
|
||||
%{
|
||||
title: Map.get(args, :title, event.title),
|
||||
description: Map.get(args, :description, event.description),
|
||||
tags: Map.get(args, :tags, event.tags),
|
||||
physical_address: Map.get(args, :physical_address, event.physical_address),
|
||||
visibility: Map.get(args, :visibility, event.visibility),
|
||||
physical_address: Map.get(args, :physical_address, event.physical_address),
|
||||
begins_on: Map.get(args, :begins_on, event.begins_on),
|
||||
category: Map.get(args, :category, event.category),
|
||||
options: Map.get(args, :options, event.options)
|
||||
}
|
||||
end
|
||||
|
||||
defp prepare_args(
|
||||
%{
|
||||
organizer_actor: organizer_actor,
|
||||
@@ -118,8 +111,7 @@ defmodule MobilizonWeb.API.Events do
|
||||
options: options,
|
||||
tags: tags,
|
||||
begins_on: begins_on,
|
||||
category: category,
|
||||
options: options
|
||||
category: category
|
||||
} = args
|
||||
) do
|
||||
with physical_address <- Map.get(args, :physical_address, nil),
|
||||
@@ -131,13 +123,13 @@ defmodule MobilizonWeb.API.Events do
|
||||
%{
|
||||
title: title,
|
||||
physical_address: physical_address,
|
||||
visibility: visibility,
|
||||
picture: picture,
|
||||
content_html: content_html,
|
||||
tags: tags,
|
||||
to: to,
|
||||
cc: cc,
|
||||
begins_on: begins_on,
|
||||
ends_on: Map.get(args, :ends_on, nil),
|
||||
category: category,
|
||||
options: options
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ defmodule MobilizonWeb.API.Groups do
|
||||
preferred_username: title,
|
||||
summary: summary,
|
||||
creator_actor_id: creator_actor_id,
|
||||
avatar: avatar,
|
||||
banner: banner
|
||||
avatar: _avatar,
|
||||
banner: _banner
|
||||
} = args
|
||||
) do
|
||||
with {:is_owned, true, actor} <- User.owns_actor(user, creator_actor_id),
|
||||
{:existing_group, nil} <- {:existing_group, Actors.get_group_by_title(title)},
|
||||
title <- String.trim(title),
|
||||
{:existing_group, nil} <- {:existing_group, Actors.get_group_by_title(title)},
|
||||
visibility <- Map.get(args, :visibility, :public),
|
||||
{content_html, tags, to, cc} <-
|
||||
Utils.prepare_content(actor, summary, visibility, [], nil),
|
||||
|
||||
@@ -193,7 +193,9 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
}
|
||||
} = _resolution
|
||||
) do
|
||||
with {:is_owned, true, organizer_actor} <- User.owns_actor(user, organizer_actor_id),
|
||||
# See https://github.com/absinthe-graphql/absinthe/issues/490
|
||||
with args <- Map.put(args, :options, args[:options] || %{}),
|
||||
{:is_owned, true, organizer_actor} <- User.owns_actor(user, organizer_actor_id),
|
||||
{:ok, args} <- save_attached_picture(args),
|
||||
{:ok, args} <- save_physical_address(args),
|
||||
args_with_organizer <- Map.put(args, :organizer_actor, organizer_actor),
|
||||
@@ -230,10 +232,13 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
}
|
||||
} = _resolution
|
||||
) do
|
||||
with {:ok, %Event{} = event} <- Mobilizon.Events.get_event(event_id),
|
||||
# See https://github.com/absinthe-graphql/absinthe/issues/490
|
||||
with args <- Map.put(args, :options, args[:options] || %{}),
|
||||
{:ok, %Event{} = event} <- Mobilizon.Events.get_event_full(event_id),
|
||||
{:is_owned, true, organizer_actor} <- User.owns_actor(user, event.organizer_actor_id),
|
||||
{:ok, args} <- save_attached_picture(args),
|
||||
{:ok, args} <- save_physical_address(args),
|
||||
args <- Map.put(args, :organizer_actor, organizer_actor),
|
||||
{
|
||||
:ok,
|
||||
%Activity{
|
||||
@@ -243,11 +248,14 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
},
|
||||
%Event{} = event
|
||||
} <-
|
||||
MobilizonWeb.API.Events.update_event(args) do
|
||||
MobilizonWeb.API.Events.update_event(args, event) do
|
||||
{:ok, event}
|
||||
else
|
||||
{:error, :event_not_found} ->
|
||||
{:error, "Event not found"}
|
||||
|
||||
{:is_owned, _} ->
|
||||
{:error, "User doesn't own actor"}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -229,14 +229,14 @@ defmodule MobilizonWeb.Schema.EventType do
|
||||
arg(:organizer_actor_id, non_null(:id))
|
||||
arg(:category, :string, default_value: "meeting")
|
||||
arg(:physical_address, :address_input)
|
||||
arg(:options, :event_options_input, default_value: %{})
|
||||
arg(:options, :event_options_input)
|
||||
|
||||
resolve(&Event.create_event/3)
|
||||
end
|
||||
|
||||
@desc "Update an event"
|
||||
field :update_event, type: :event do
|
||||
arg(:event_id, non_null(:integer))
|
||||
arg(:event_id, non_null(:id))
|
||||
|
||||
arg(:title, :string)
|
||||
arg(:description, :string)
|
||||
@@ -246,6 +246,7 @@ defmodule MobilizonWeb.Schema.EventType do
|
||||
arg(:status, :integer)
|
||||
arg(:public, :boolean)
|
||||
arg(:visibility, :event_visibility)
|
||||
arg(:organizer_actor_id, :id)
|
||||
|
||||
arg(:tags, list_of(:string), description: "The list of tags associated to the event")
|
||||
|
||||
@@ -259,6 +260,7 @@ defmodule MobilizonWeb.Schema.EventType do
|
||||
arg(:phone_address, :string)
|
||||
arg(:category, :string)
|
||||
arg(:physical_address, :address_input)
|
||||
arg(:options, :event_options_input)
|
||||
|
||||
resolve(&Event.update_event/3)
|
||||
end
|
||||
|
||||
@@ -39,21 +39,16 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
@doc """
|
||||
Wraps an object into an activity
|
||||
"""
|
||||
@spec create_activity(map(), boolean()) :: {:ok, %Activity{}} | {:error, any()}
|
||||
@spec create_activity(map(), boolean()) :: {:ok, %Activity{}}
|
||||
def create_activity(map, local \\ true) when is_map(map) do
|
||||
with map <- lazy_put_activity_defaults(map) do
|
||||
activity = %Activity{
|
||||
data: map,
|
||||
local: local,
|
||||
actor: map["actor"],
|
||||
recipients: get_recipients(map)
|
||||
}
|
||||
|
||||
# Notification.create_notifications(activity)
|
||||
# stream_out(activity)
|
||||
{:ok, activity}
|
||||
else
|
||||
error -> {:error, error}
|
||||
{:ok,
|
||||
%Activity{
|
||||
data: map,
|
||||
local: local,
|
||||
actor: map["actor"],
|
||||
recipients: get_recipients(map)
|
||||
}}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -196,7 +191,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
"object" => object
|
||||
},
|
||||
{:ok, activity} <- create_activity(data, local),
|
||||
{:ok, object} <- insert_full_object(data),
|
||||
{:ok, object} <- update_object(object["id"], data),
|
||||
:ok <- maybe_federate(activity) do
|
||||
{:ok, activity, object}
|
||||
end
|
||||
|
||||
@@ -15,12 +15,30 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Actor do
|
||||
@impl Converter
|
||||
@spec as_to_model_data(map()) :: map()
|
||||
def as_to_model_data(object) do
|
||||
avatar =
|
||||
object["icon"]["url"] &&
|
||||
%{
|
||||
"name" => object["icon"]["name"] || "avatar",
|
||||
"url" => object["icon"]["url"]
|
||||
}
|
||||
|
||||
banner =
|
||||
object["image"]["url"] &&
|
||||
%{
|
||||
"name" => object["image"]["name"] || "banner",
|
||||
"url" => object["image"]["url"]
|
||||
}
|
||||
|
||||
%{
|
||||
"type" => String.to_existing_atom(object["type"]),
|
||||
"preferred_username" => object["preferred_username"],
|
||||
"preferred_username" => object["preferredUsername"],
|
||||
"summary" => object["summary"],
|
||||
"url" => object["url"],
|
||||
"name" => object["name"]
|
||||
"name" => object["name"],
|
||||
"avatar" => avatar,
|
||||
"banner" => banner,
|
||||
"keys" => object["publicKey"]["publicKeyPem"],
|
||||
"manually_approves_followers" => object["manuallyApprovesFollowers"]
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
"organizer_actor_id" => actor_id,
|
||||
"picture_id" => picture_id,
|
||||
"begins_on" => object["startTime"],
|
||||
"ends_on" => object["endTime"],
|
||||
"category" => object["category"],
|
||||
"url" => object["id"],
|
||||
"uuid" => object["uuid"],
|
||||
@@ -173,7 +174,8 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
"startTime" => event.begins_on |> date_to_string(),
|
||||
"endTime" => event.ends_on |> date_to_string(),
|
||||
"tag" => event.tags |> build_tags(),
|
||||
"id" => event.url
|
||||
"id" => event.url,
|
||||
"url" => event.url
|
||||
}
|
||||
|
||||
res =
|
||||
|
||||
@@ -295,19 +295,15 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||
%{"type" => "Update", "object" => %{"type" => object_type} = object, "actor" => _actor_id} =
|
||||
data
|
||||
)
|
||||
when object_type in ["Person", "Application", "Service", "Organization"] do
|
||||
when object_type in ["Person", "Group", "Application", "Service", "Organization"] do
|
||||
case Actors.get_actor_by_url(object["id"]) do
|
||||
{:ok, %Actor{url: url}} ->
|
||||
{:ok, new_actor_data} = ActivityPub.actor_data_from_actor_object(object)
|
||||
|
||||
Actors.insert_or_update_actor(new_actor_data)
|
||||
|
||||
{:ok, %Actor{url: actor_url}} ->
|
||||
ActivityPub.update(%{
|
||||
local: false,
|
||||
to: data["to"] || [],
|
||||
cc: data["cc"] || [],
|
||||
object: object,
|
||||
actor: url
|
||||
actor: actor_url
|
||||
})
|
||||
|
||||
e ->
|
||||
@@ -316,6 +312,28 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||
end
|
||||
end
|
||||
|
||||
def handle_incoming(
|
||||
%{"type" => "Update", "object" => %{"type" => "Event"} = object, "actor" => actor} =
|
||||
_update
|
||||
) do
|
||||
with {:ok, %{"actor" => existing_organizer_actor_url} = _existing_event_data} <-
|
||||
fetch_obj_helper_as_activity_streams(object),
|
||||
{:ok, %Actor{url: actor_url}} <- actor |> Utils.get_url() |> Actors.get_actor_by_url(),
|
||||
true <- Utils.get_url(existing_organizer_actor_url) == actor_url do
|
||||
ActivityPub.update(%{
|
||||
local: false,
|
||||
to: object["to"] || [],
|
||||
cc: object["cc"] || [],
|
||||
object: object,
|
||||
actor: actor_url
|
||||
})
|
||||
else
|
||||
e ->
|
||||
Logger.debug(inspect(e))
|
||||
:error
|
||||
end
|
||||
end
|
||||
|
||||
def handle_incoming(
|
||||
%{
|
||||
"type" => "Undo",
|
||||
|
||||
@@ -29,6 +29,8 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
alias MobilizonWeb.Endpoint
|
||||
|
||||
@actor_types ["Group", "Person", "Application"]
|
||||
|
||||
# Some implementations send the actor URI as the actor field, others send the entire actor object,
|
||||
# so figure out what the actor's URI is based on what we have.
|
||||
def get_url(%{"id" => id}), do: id
|
||||
@@ -119,7 +121,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
@doc """
|
||||
Inserts a full object if it is contained in an activity.
|
||||
"""
|
||||
def insert_full_object(%{"object" => %{"type" => "Event"} = object_data})
|
||||
def insert_full_object(%{"object" => %{"type" => "Event"} = object_data, "type" => "Create"})
|
||||
when is_map(object_data) do
|
||||
with {:ok, object_data} <-
|
||||
Converters.Event.as_to_model_data(object_data),
|
||||
@@ -128,7 +130,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
end
|
||||
end
|
||||
|
||||
def insert_full_object(%{"object" => %{"type" => "Group"} = object_data})
|
||||
def insert_full_object(%{"object" => %{"type" => "Group"} = object_data, "type" => "Create"})
|
||||
when is_map(object_data) do
|
||||
with object_data <-
|
||||
Map.put(object_data, "preferred_username", object_data["preferredUsername"]),
|
||||
@@ -140,7 +142,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
@doc """
|
||||
Inserts a full object if it is contained in an activity.
|
||||
"""
|
||||
def insert_full_object(%{"object" => %{"type" => "Note"} = object_data})
|
||||
def insert_full_object(%{"object" => %{"type" => "Note"} = object_data, "type" => "Create"})
|
||||
when is_map(object_data) do
|
||||
with data <- Converters.Comment.as_to_model_data(object_data),
|
||||
{:ok, %Comment{} = comment} <- Events.create_comment(data) do
|
||||
@@ -177,6 +179,39 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
|
||||
def insert_full_object(_), do: {:ok, nil}
|
||||
|
||||
@doc """
|
||||
Update an object
|
||||
"""
|
||||
@spec update_object(struct(), map()) :: {:ok, struct()} | any()
|
||||
def update_object(object, object_data)
|
||||
|
||||
def update_object(event_url, %{
|
||||
"object" => %{"type" => "Event"} = object_data,
|
||||
"type" => "Update"
|
||||
})
|
||||
when is_map(object_data) do
|
||||
with {:event_not_found, %Event{} = event} <-
|
||||
{:event_not_found, Events.get_event_by_url(event_url)},
|
||||
{:ok, object_data} <- Converters.Event.as_to_model_data(object_data),
|
||||
{:ok, %Event{} = event} <- Events.update_event(event, object_data) do
|
||||
{:ok, event}
|
||||
end
|
||||
end
|
||||
|
||||
def update_object(actor_url, %{
|
||||
"object" => %{"type" => type_actor} = object_data,
|
||||
"type" => "Update"
|
||||
})
|
||||
when is_map(object_data) and type_actor in @actor_types do
|
||||
with {:ok, %Actor{} = actor} <- Actors.get_actor_by_url(actor_url),
|
||||
object_data <- Converters.Actor.as_to_model_data(object_data),
|
||||
{:ok, %Actor{} = actor} <- Actors.update_actor(actor, object_data) do
|
||||
{:ok, actor}
|
||||
end
|
||||
end
|
||||
|
||||
def update_object(_, _), do: {:ok, nil}
|
||||
|
||||
#### Like-related helpers
|
||||
|
||||
# @doc """
|
||||
@@ -264,7 +299,8 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
String.t(),
|
||||
map(),
|
||||
list(),
|
||||
map()
|
||||
map(),
|
||||
String.t()
|
||||
) :: map()
|
||||
def make_event_data(
|
||||
actor,
|
||||
@@ -273,10 +309,12 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
content_html,
|
||||
picture \\ nil,
|
||||
tags \\ [],
|
||||
metadata \\ %{}
|
||||
metadata \\ %{},
|
||||
uuid \\ nil,
|
||||
url \\ nil
|
||||
) do
|
||||
Logger.debug("Making event data")
|
||||
uuid = Ecto.UUID.generate()
|
||||
uuid = uuid || Ecto.UUID.generate()
|
||||
|
||||
res = %{
|
||||
"type" => "Event",
|
||||
@@ -285,9 +323,10 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
"content" => content_html,
|
||||
"name" => title,
|
||||
"startTime" => metadata.begins_on,
|
||||
"endTime" => metadata.ends_on,
|
||||
"category" => metadata.category,
|
||||
"actor" => actor,
|
||||
"id" => Routes.page_url(Endpoint, :event, uuid),
|
||||
"id" => url || Routes.page_url(Endpoint, :event, uuid),
|
||||
"uuid" => uuid,
|
||||
"tag" =>
|
||||
tags |> Enum.uniq() |> Enum.map(fn tag -> %{"type" => "Hashtag", "name" => "##{tag}"} end)
|
||||
@@ -505,7 +544,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
activity_id,
|
||||
public
|
||||
)
|
||||
when type in ["Group", "Person", "Application"] do
|
||||
when type in @actor_types do
|
||||
do_make_announce_data(actor_url, actor_followers_url, url, url, activity_id, public)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user