@@ -155,7 +155,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
end
|
||||
|
||||
# Create an activity from an event
|
||||
@spec event_to_activity(%Event{}, boolean()) :: Activity.t()
|
||||
@spec event_to_activity(Event.t(), boolean()) :: Activity.t()
|
||||
defp event_to_activity(%Event{} = event, local \\ true) do
|
||||
%Activity{
|
||||
recipients: [@public_ap_adress],
|
||||
@@ -166,7 +166,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
end
|
||||
|
||||
# Create an activity from a comment
|
||||
@spec comment_to_activity(%Comment{}, boolean()) :: Activity.t()
|
||||
@spec comment_to_activity(Comment.t(), boolean()) :: Activity.t()
|
||||
defp comment_to_activity(%Comment{} = comment, local \\ true) do
|
||||
%Activity{
|
||||
recipients: [@public_ap_adress],
|
||||
|
||||
@@ -77,7 +77,7 @@ defmodule Mobilizon.Federation.ActivityPub.Permission do
|
||||
|
||||
@spec can_manage_group_object?(
|
||||
existing_object_permissions(),
|
||||
%Actor{url: String.t()},
|
||||
Actor.t(),
|
||||
object()
|
||||
) :: boolean()
|
||||
defp can_manage_group_object?(permission, %Actor{url: actor_url} = actor, object) do
|
||||
|
||||
@@ -967,10 +967,8 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
|
||||
defp do_handle_incoming_reject_invite(invite_object, %Actor{} = actor_rejecting) do
|
||||
with {:invite, {:ok, %Member{role: :invited, actor_id: actor_id} = member}} <-
|
||||
{:invite, get_member(invite_object)},
|
||||
{:same_actor, true} <- {:same_actor, actor_rejecting.id == actor_id},
|
||||
{:ok, activity, member} <-
|
||||
Actions.Reject.reject(:invite, member, false) do
|
||||
{:ok, activity, member}
|
||||
{:same_actor, true} <- {:same_actor, actor_rejecting.id == actor_id} do
|
||||
Actions.Reject.reject(:invite, member, false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -149,25 +149,23 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Comments do
|
||||
),
|
||||
tags <- ConverterUtils.fetch_tags(tags),
|
||||
mentions <- Map.get(args, :mentions, []) ++ ConverterUtils.fetch_mentions(mentions),
|
||||
lang <- Map.get(args, :language, "und"),
|
||||
args <-
|
||||
Map.merge(args, %{
|
||||
actor_id: Map.get(args, :actor_id),
|
||||
text: text,
|
||||
mentions: mentions,
|
||||
tags: tags,
|
||||
event: event,
|
||||
in_reply_to_comment: in_reply_to_comment,
|
||||
in_reply_to_comment_id:
|
||||
if(is_nil(in_reply_to_comment), do: nil, else: Map.get(in_reply_to_comment, :id)),
|
||||
origin_comment_id:
|
||||
if(is_nil(in_reply_to_comment),
|
||||
do: nil,
|
||||
else: Comment.get_thread_id(in_reply_to_comment)
|
||||
),
|
||||
language: if(lang == "und", do: LanguageDetection.detect(:comment, args), else: lang)
|
||||
}) do
|
||||
args
|
||||
lang <- Map.get(args, :language, "und") do
|
||||
Map.merge(args, %{
|
||||
actor_id: Map.get(args, :actor_id),
|
||||
text: text,
|
||||
mentions: mentions,
|
||||
tags: tags,
|
||||
event: event,
|
||||
in_reply_to_comment: in_reply_to_comment,
|
||||
in_reply_to_comment_id:
|
||||
if(is_nil(in_reply_to_comment), do: nil, else: Map.get(in_reply_to_comment, :id)),
|
||||
origin_comment_id:
|
||||
if(is_nil(in_reply_to_comment),
|
||||
do: nil,
|
||||
else: Comment.get_thread_id(in_reply_to_comment)
|
||||
),
|
||||
language: if(lang == "und", do: LanguageDetection.detect(:comment, args), else: lang)
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ defmodule Mobilizon.Federation.WebFinger do
|
||||
{:ok, String.t()} | {:error, :link_not_found} | {:error, any()}
|
||||
defp find_webfinger_endpoint(domain) when is_binary(domain) do
|
||||
with {:ok, %Tesla.Env{status: 200, body: body}} <-
|
||||
fetch_document("http://#{domain}/.well-known/host-meta"),
|
||||
HostMetaClient.get("http://#{domain}/.well-known/host-meta"),
|
||||
link_template when is_binary(link_template) <- find_link_from_template(body) do
|
||||
{:ok, link_template}
|
||||
else
|
||||
@@ -258,11 +258,6 @@ defmodule Mobilizon.Federation.WebFinger do
|
||||
{:error, :link_not_found}
|
||||
end
|
||||
|
||||
@spec fetch_document(String.t()) :: Tesla.Env.result()
|
||||
defp fetch_document(endpoint) do
|
||||
with {:error, err} <- HostMetaClient.get(endpoint), do: {:error, err}
|
||||
end
|
||||
|
||||
@spec address_invalid(String.t()) :: false | {:error, :invalid_address}
|
||||
defp address_invalid(address) do
|
||||
with %URI{host: host, scheme: scheme} <- URI.parse(address),
|
||||
|
||||
@@ -39,9 +39,7 @@ defmodule Mobilizon.Federation.WebFinger.XmlBuilder do
|
||||
defp to_xml(content) when is_binary(content), do: to_string(content)
|
||||
|
||||
defp to_xml(content) when is_list(content) do
|
||||
content
|
||||
|> Enum.map(&to_xml/1)
|
||||
|> Enum.join()
|
||||
Enum.map_join(content, &to_xml/1)
|
||||
end
|
||||
|
||||
defp to_xml(%NaiveDateTime{} = time), do: NaiveDateTime.to_iso8601(time)
|
||||
@@ -49,9 +47,7 @@ defmodule Mobilizon.Federation.WebFinger.XmlBuilder do
|
||||
@spec make_open_tag(tag :: atom, attributes :: map()) :: String.t()
|
||||
defp make_open_tag(tag, attributes) do
|
||||
attributes_string =
|
||||
attributes
|
||||
|> Enum.map(fn {attribute, value} -> "#{attribute}=\"#{value}\"" end)
|
||||
|> Enum.join(" ")
|
||||
Enum.map_join(attributes, " ", fn {attribute, value} -> "#{attribute}=\"#{value}\"" end)
|
||||
|
||||
[to_string(tag), attributes_string] |> Enum.join(" ") |> String.trim()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user