forked from potsda.mn/mobilizon
Fix event online URL AP attachment
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
0587c90212
commit
18c8b7bc14
|
@ -881,7 +881,6 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
|> Map.merge(%{
|
|> Map.merge(%{
|
||||||
"id" => "#{Endpoint.url()}/reject/follow/#{follower.id}"
|
"id" => "#{Endpoint.url()}/reject/follow/#{follower.id}"
|
||||||
}) do
|
}) do
|
||||||
Logger.error(inspect(update_data))
|
|
||||||
{:ok, follower, update_data}
|
{:ok, follower, update_data}
|
||||||
else
|
else
|
||||||
err ->
|
err ->
|
||||||
|
|
|
@ -46,11 +46,16 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||||
{:mentions, mentions} <- {:mentions, ConverterUtils.fetch_mentions(object["tag"])},
|
{:mentions, mentions} <- {:mentions, ConverterUtils.fetch_mentions(object["tag"])},
|
||||||
{:visibility, visibility} <- {:visibility, get_visibility(object)},
|
{:visibility, visibility} <- {:visibility, get_visibility(object)},
|
||||||
{:options, options} <- {:options, get_options(object)} do
|
{:options, options} <- {:options, get_options(object)} do
|
||||||
|
attachments =
|
||||||
|
object
|
||||||
|
|> Map.get("attachment", [])
|
||||||
|
|> Enum.filter(fn attachment -> Map.get(attachment, "type", "Document") == "Document" end)
|
||||||
|
|
||||||
picture_id =
|
picture_id =
|
||||||
with true <- Map.has_key?(object, "attachment") && length(object["attachment"]) > 0,
|
with true <- length(attachments) > 0,
|
||||||
{:ok, %Picture{id: picture_id}} <-
|
{:ok, %Picture{id: picture_id}} <-
|
||||||
object["attachment"]
|
attachments
|
||||||
|> hd
|
|> hd()
|
||||||
|> PictureConverter.find_or_create_picture(actor_id) do
|
|> PictureConverter.find_or_create_picture(actor_id) do
|
||||||
picture_id
|
picture_id
|
||||||
else
|
else
|
||||||
|
@ -71,7 +76,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||||
local: is_nil(actor_domain),
|
local: is_nil(actor_domain),
|
||||||
options: options,
|
options: options,
|
||||||
status: object |> Map.get("ical:status", "CONFIRMED") |> String.downcase(),
|
status: object |> Map.get("ical:status", "CONFIRMED") |> String.downcase(),
|
||||||
online_address: object["onlineAddress"],
|
online_address: object |> Map.get("attachment", []) |> get_online_address(),
|
||||||
phone_address: object["phoneAddress"],
|
phone_address: object["phoneAddress"],
|
||||||
draft: false,
|
draft: false,
|
||||||
url: object["id"],
|
url: object["id"],
|
||||||
|
@ -122,6 +127,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||||
"repliesModerationOption" => event.options.comment_moderation,
|
"repliesModerationOption" => event.options.comment_moderation,
|
||||||
"commentsEnabled" => event.options.comment_moderation == :allow_all,
|
"commentsEnabled" => event.options.comment_moderation == :allow_all,
|
||||||
"anonymousParticipationEnabled" => event.options.anonymous_participation,
|
"anonymousParticipationEnabled" => event.options.anonymous_participation,
|
||||||
|
"attachment" => [],
|
||||||
# "draft" => event.draft,
|
# "draft" => event.draft,
|
||||||
"ical:status" => event.status |> to_string |> String.upcase(),
|
"ical:status" => event.status |> to_string |> String.upcase(),
|
||||||
"id" => event.url,
|
"id" => event.url,
|
||||||
|
@ -133,9 +139,34 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||||
do: res,
|
do: res,
|
||||||
else: Map.put(res, "location", AddressConverter.model_to_as(event.physical_address))
|
else: Map.put(res, "location", AddressConverter.model_to_as(event.physical_address))
|
||||||
|
|
||||||
|
res =
|
||||||
if is_nil(event.picture),
|
if is_nil(event.picture),
|
||||||
do: res,
|
do: res,
|
||||||
else: Map.put(res, "attachment", [PictureConverter.model_to_as(event.picture)])
|
else:
|
||||||
|
Map.update(
|
||||||
|
res,
|
||||||
|
"attachment",
|
||||||
|
[],
|
||||||
|
&(&1 ++ [PictureConverter.model_to_as(event.picture)])
|
||||||
|
)
|
||||||
|
|
||||||
|
if is_nil(event.online_address),
|
||||||
|
do: res,
|
||||||
|
else:
|
||||||
|
Map.update(
|
||||||
|
res,
|
||||||
|
"attachment",
|
||||||
|
[],
|
||||||
|
&(&1 ++
|
||||||
|
[
|
||||||
|
%{
|
||||||
|
"type" => "Link",
|
||||||
|
"href" => event.online_address,
|
||||||
|
"mediaType" => "text/html",
|
||||||
|
"name" => "Website"
|
||||||
|
}
|
||||||
|
])
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get only elements that we have in EventOptions
|
# Get only elements that we have in EventOptions
|
||||||
|
@ -198,4 +229,21 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||||
@spec date_to_string(DateTime.t() | nil) :: String.t()
|
@spec date_to_string(DateTime.t() | nil) :: String.t()
|
||||||
defp date_to_string(nil), do: nil
|
defp date_to_string(nil), do: nil
|
||||||
defp date_to_string(%DateTime{} = date), do: DateTime.to_iso8601(date)
|
defp date_to_string(%DateTime{} = date), do: DateTime.to_iso8601(date)
|
||||||
|
|
||||||
|
defp get_online_address(attachments) do
|
||||||
|
Enum.find_value(attachments, [], fn attachment ->
|
||||||
|
case attachment do
|
||||||
|
%{
|
||||||
|
"type" => "Link",
|
||||||
|
"href" => url,
|
||||||
|
"mediaType" => "text/html",
|
||||||
|
"name" => "Website"
|
||||||
|
} ->
|
||||||
|
url
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,9 +46,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_event(parent, %{uuid: uuid} = args, %{context: context} = resolution) do
|
def find_event(parent, %{uuid: uuid} = args, %{context: context} = resolution) do
|
||||||
require Logger
|
|
||||||
Logger.error(inspect(context))
|
|
||||||
|
|
||||||
with {:has_event, %Event{} = event} <-
|
with {:has_event, %Event{} = event} <-
|
||||||
{:has_event, Events.get_public_event_by_uuid_with_preload(uuid)},
|
{:has_event, Events.get_public_event_by_uuid_with_preload(uuid)},
|
||||||
{:access_valid, true} <-
|
{:access_valid, true} <-
|
||||||
|
|
|
@ -70,6 +70,8 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||||
assert event.physical_address.url ==
|
assert event.physical_address.url ==
|
||||||
"https://event1.tcit.fr/address/eeecc11d-0030-43e8-a897-6422876372jd"
|
"https://event1.tcit.fr/address/eeecc11d-0030-43e8-a897-6422876372jd"
|
||||||
|
|
||||||
|
assert event.online_address == "https://google.com"
|
||||||
|
|
||||||
{:ok, %Actor{}} = Actors.get_actor_by_url(object["actor"])
|
{:ok, %Actor{}} = Actors.get_actor_by_url(object["actor"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
15
test/fixtures/mobilizon-post-activity.json
vendored
15
test/fixtures/mobilizon-post-activity.json
vendored
|
@ -35,7 +35,20 @@
|
||||||
],
|
],
|
||||||
"id": "https://test.mobilizon.org/events/39026210-0c69-4238-b3cc-986f33f98ed0/activity",
|
"id": "https://test.mobilizon.org/events/39026210-0c69-4238-b3cc-986f33f98ed0/activity",
|
||||||
"object": {
|
"object": {
|
||||||
"attachment": [],
|
"attachment": [
|
||||||
|
{
|
||||||
|
"href": "https://something.org",
|
||||||
|
"mediaType": "text/html",
|
||||||
|
"name": "Another link",
|
||||||
|
"type": "Link"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"href": "https://google.com",
|
||||||
|
"mediaType": "text/html",
|
||||||
|
"name": "Website",
|
||||||
|
"type": "Link"
|
||||||
|
}
|
||||||
|
],
|
||||||
"attributedTo": "https://test.mobilizon.org/@Alicia",
|
"attributedTo": "https://test.mobilizon.org/@Alicia",
|
||||||
"startTime": "2018-02-12T14:08:20Z",
|
"startTime": "2018-02-12T14:08:20Z",
|
||||||
"cc": [
|
"cc": [
|
||||||
|
|
Loading…
Reference in a new issue