Expose and fetch event contacts
Close #829 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
d7ef8f3280
commit
88067bd217
@ -228,6 +228,14 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||
|> Enum.uniq()
|
||||
end
|
||||
|
||||
defp add_event_contacts(%Event{contacts: contacts}) do
|
||||
contacts
|
||||
|> Enum.map(& &1.url)
|
||||
|> Enum.uniq()
|
||||
end
|
||||
|
||||
defp add_event_contacts(%Event{}), do: []
|
||||
|
||||
defp process_mention({_, mentioned_actor}), do: mentioned_actor.url
|
||||
|
||||
defp process_mention(%{actor_id: actor_id}) do
|
||||
@ -255,7 +263,9 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||
{to, cc} =
|
||||
{to,
|
||||
Enum.uniq(
|
||||
cc ++ add_comments_authors(event.comments) ++ add_shares_actors_followers(event.url)
|
||||
cc ++
|
||||
add_comments_authors(event.comments) ++
|
||||
add_shares_actors_followers(event.url) ++ add_event_contacts(event)
|
||||
)}
|
||||
|
||||
%{"to" => to, "cc" => cc}
|
||||
|
@ -18,6 +18,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||
alias Mobilizon.Service.TimezoneDetector
|
||||
alias Mobilizon.Web.Endpoint
|
||||
|
||||
import Mobilizon.Federation.ActivityPub.Utils, only: [get_url: 1]
|
||||
|
||||
import Mobilizon.Federation.ActivityStream.Converter.Utils,
|
||||
only: [
|
||||
fetch_tags: 1,
|
||||
@ -25,7 +27,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||
build_tags: 1,
|
||||
maybe_fetch_actor_and_attributed_to_id: 1,
|
||||
process_pictures: 2,
|
||||
get_address: 1
|
||||
get_address: 1,
|
||||
fetch_actor: 1
|
||||
]
|
||||
|
||||
require Logger
|
||||
@ -56,6 +59,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||
visibility = get_visibility(object)
|
||||
options = get_options(object, address)
|
||||
metadata = get_metdata(object)
|
||||
contacts = get_contacts(object)
|
||||
|
||||
[description: description, picture_id: picture_id, medias: medias] =
|
||||
process_pictures(object, actor_id)
|
||||
@ -86,7 +90,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||
physical_address_id: if(address, do: address.id, else: nil),
|
||||
updated_at: object["updated"],
|
||||
publish_at: object["published"],
|
||||
language: object["inLanguage"]
|
||||
language: object["inLanguage"],
|
||||
contacts: contacts
|
||||
}
|
||||
|
||||
{:error, err} ->
|
||||
@ -133,7 +138,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||
"id" => event.url,
|
||||
"url" => event.url,
|
||||
"inLanguage" => event.language,
|
||||
"timezone" => event.options.timezone
|
||||
"timezone" => event.options.timezone,
|
||||
"contacts" => Enum.map(event.contacts, & &1.url)
|
||||
}
|
||||
|> maybe_add_physical_address(event)
|
||||
|> maybe_add_event_picture(event)
|
||||
@ -286,4 +292,19 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||
%URI{host: local_domain} = URI.parse(Endpoint.url())
|
||||
url_domain == local_domain
|
||||
end
|
||||
|
||||
@spec get_contacts(map()) :: list(Actor.t())
|
||||
defp get_contacts(object) do
|
||||
object
|
||||
|> Map.get("contacts", [])
|
||||
|> Enum.map(&get_contact/1)
|
||||
|> Enum.filter(&match?({:ok, _}, &1))
|
||||
|> Enum.map(fn {:ok, contact} -> contact end)
|
||||
end
|
||||
|
||||
defp get_contact(contact) do
|
||||
contact
|
||||
|> get_url()
|
||||
|> fetch_actor()
|
||||
end
|
||||
end
|
||||
|
@ -179,7 +179,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
|
||||
def maybe_fetch_actor_and_attributed_to_id(_), do: {:error, :no_actor_found}
|
||||
|
||||
@spec fetch_actor(String.t()) :: {:ok, Actor.t()} | {:error, atom()}
|
||||
defp fetch_actor(actor_url) do
|
||||
def fetch_actor(actor_url) do
|
||||
case ActivityPubActor.get_or_fetch_actor_by_url(actor_url) do
|
||||
{:ok, %Actor{suspended: false} = actor} ->
|
||||
{:ok, actor}
|
||||
|
Loading…
Reference in New Issue
Block a user