A few fixes comming from Dialyser
Signed-off-by: Thomas Citharel <tcit@tcit.fr> Fixes Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
d73f738b1b
commit
d37c873b04
@ -213,7 +213,7 @@ defmodule Mobilizon.Actors.Actor do
|
|||||||
@doc """
|
@doc """
|
||||||
Get a public key for a given ActivityPub actor ID (url)
|
Get a public key for a given ActivityPub actor ID (url)
|
||||||
"""
|
"""
|
||||||
@spec get_public_key_for_url(String.t()) :: {:ok, String.t()}
|
@spec get_public_key_for_url(String.t()) :: {:ok, String.t()} | {:error, atom()}
|
||||||
def get_public_key_for_url(url) do
|
def get_public_key_for_url(url) do
|
||||||
with {:ok, %Actor{keys: keys}} <- Actors.get_or_fetch_by_url(url),
|
with {:ok, %Actor{keys: keys}} <- Actors.get_or_fetch_by_url(url),
|
||||||
{:ok, public_key} <- prepare_public_key(keys) do
|
{:ok, public_key} <- prepare_public_key(keys) do
|
||||||
|
@ -579,6 +579,7 @@ defmodule Mobilizon.Events do
|
|||||||
@doc """
|
@doc """
|
||||||
Create a relation between two tags
|
Create a relation between two tags
|
||||||
"""
|
"""
|
||||||
|
@spec create_tag_relation(map()) :: {:ok, TagRelation.t()} | {:error, Ecto.Changeset.t()}
|
||||||
def create_tag_relation(attrs \\ {}) do
|
def create_tag_relation(attrs \\ {}) do
|
||||||
%TagRelation{}
|
%TagRelation{}
|
||||||
|> TagRelation.changeset(attrs)
|
|> TagRelation.changeset(attrs)
|
||||||
|
@ -51,7 +51,7 @@ defmodule MobilizonWeb.API.Groups do
|
|||||||
{:existing_group, _} ->
|
{:existing_group, _} ->
|
||||||
{:error, :existing_group_name}
|
{:error, :existing_group_name}
|
||||||
|
|
||||||
{:bad_actor} ->
|
{:bad_actor, _} ->
|
||||||
{:error, :bad_admin_actor}
|
{:error, :bad_admin_actor}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -32,8 +32,7 @@ defmodule MobilizonWeb.HTTPSignaturePlug do
|
|||||||
[signature | _] = get_req_header(conn, "signature")
|
[signature | _] = get_req_header(conn, "signature")
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
# Dialyzer doesn't like this line
|
String.contains?(signature, actor) ->
|
||||||
signature && String.contains?(signature, actor) ->
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> put_req_header(
|
|> put_req_header(
|
||||||
|
@ -36,9 +36,8 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Wraps an object into an activity
|
Wraps an object into an activity
|
||||||
|
|
||||||
TODO: Rename me
|
|
||||||
"""
|
"""
|
||||||
|
# TODO: Rename me
|
||||||
@spec insert(map(), boolean()) :: {:ok, %Activity{}} | {:error, any()}
|
@spec insert(map(), boolean()) :: {:ok, %Activity{}} | {:error, any()}
|
||||||
def insert(map, local \\ true) when is_map(map) do
|
def insert(map, local \\ true) when is_map(map) do
|
||||||
with map <- lazy_put_activity_defaults(map),
|
with map <- lazy_put_activity_defaults(map),
|
||||||
@ -113,6 +112,9 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Create an activity of type "Create"
|
||||||
|
"""
|
||||||
def create(%{to: to, actor: actor, object: object} = params) do
|
def create(%{to: to, actor: actor, object: object} = params) do
|
||||||
Logger.debug("creating an activity")
|
Logger.debug("creating an activity")
|
||||||
Logger.debug(inspect(params))
|
Logger.debug(inspect(params))
|
||||||
@ -240,6 +242,9 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Make an actor follow another
|
||||||
|
"""
|
||||||
def follow(%Actor{} = follower, %Actor{} = followed, activity_id \\ nil, local \\ true) do
|
def follow(%Actor{} = follower, %Actor{} = followed, activity_id \\ nil, local \\ true) do
|
||||||
with {:ok, %Follower{} = follow} <- Actor.follow(followed, follower, true),
|
with {:ok, %Follower{} = follow} <- Actor.follow(followed, follower, true),
|
||||||
activity_follow_id <- activity_id || Follower.url(follow),
|
activity_follow_id <- activity_id || Follower.url(follow),
|
||||||
@ -253,6 +258,9 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Make an actor unfollow another
|
||||||
|
"""
|
||||||
@spec unfollow(Actor.t(), Actor.t(), String.t(), boolean()) :: {:ok, map()} | any()
|
@spec unfollow(Actor.t(), Actor.t(), String.t(), boolean()) :: {:ok, map()} | any()
|
||||||
def unfollow(%Actor{} = followed, %Actor{} = follower, activity_id \\ nil, local \\ true) do
|
def unfollow(%Actor{} = followed, %Actor{} = follower, activity_id \\ nil, local \\ true) do
|
||||||
with {:ok, %Follower{id: follow_id}} <- Actor.unfollow(followed, follower),
|
with {:ok, %Follower{id: follow_id}} <- Actor.unfollow(followed, follower),
|
||||||
@ -337,7 +345,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Find an actor in our local database or call Webfinger to find what's its AP ID is and then fetch it
|
Find an actor in our local database or call WebFinger to find what's its AP ID is and then fetch it
|
||||||
"""
|
"""
|
||||||
@spec find_or_make_actor_from_nickname(String.t(), atom() | nil) :: tuple()
|
@spec find_or_make_actor_from_nickname(String.t(), atom() | nil) :: tuple()
|
||||||
def find_or_make_actor_from_nickname(nickname, type \\ nil) do
|
def find_or_make_actor_from_nickname(nickname, type \\ nil) do
|
||||||
@ -355,7 +363,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
def find_or_make_group_from_nickname(nick), do: find_or_make_actor_from_nickname(nick, :Group)
|
def find_or_make_group_from_nickname(nick), do: find_or_make_actor_from_nickname(nick, :Group)
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Create an actor inside our database from username, using Webfinger to find out it's AP ID and then fetch it
|
Create an actor inside our database from username, using WebFinger to find out it's AP ID and then fetch it
|
||||||
"""
|
"""
|
||||||
@spec make_actor_from_nickname(String.t()) :: {:ok, %Actor{}} | {:error, any()}
|
@spec make_actor_from_nickname(String.t()) :: {:ok, %Actor{}} | {:error, any()}
|
||||||
def make_actor_from_nickname(nickname) do
|
def make_actor_from_nickname(nickname) do
|
||||||
@ -366,6 +374,9 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Publish an activity to all appropriated audiences inboxes
|
||||||
|
"""
|
||||||
def publish(actor, activity) do
|
def publish(actor, activity) do
|
||||||
Logger.debug("Publishing an activity")
|
Logger.debug("Publishing an activity")
|
||||||
|
|
||||||
@ -395,6 +406,9 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Publish an activity to a specific inbox
|
||||||
|
"""
|
||||||
def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do
|
def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do
|
||||||
Logger.info("Federating #{id} to #{inbox}")
|
Logger.info("Federating #{id} to #{inbox}")
|
||||||
%URI{host: host, path: path} = URI.parse(inbox)
|
%URI{host: host, path: path} = URI.parse(inbox)
|
||||||
@ -425,7 +439,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Fetching a remote actor's informations through it's AP ID
|
# Fetching a remote actor's information through it's AP ID
|
||||||
@spec fetch_and_prepare_actor_from_url(String.t()) :: {:ok, struct()} | {:error, atom()} | any()
|
@spec fetch_and_prepare_actor_from_url(String.t()) :: {:ok, struct()} | {:error, atom()} | any()
|
||||||
defp fetch_and_prepare_actor_from_url(url) do
|
defp fetch_and_prepare_actor_from_url(url) do
|
||||||
Logger.debug("Fetching and preparing actor from url")
|
Logger.debug("Fetching and preparing actor from url")
|
||||||
@ -447,6 +461,9 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Creating proper actor data struct from AP data
|
Creating proper actor data struct from AP data
|
||||||
|
|
||||||
|
|
||||||
|
Convert ActivityPub data to our internal format
|
||||||
"""
|
"""
|
||||||
@spec actor_data_from_actor_object(map()) :: {:ok, map()}
|
@spec actor_data_from_actor_object(map()) :: {:ok, map()}
|
||||||
def actor_data_from_actor_object(data) when is_map(data) do
|
def actor_data_from_actor_object(data) when is_map(data) do
|
||||||
@ -533,7 +550,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
|
|
||||||
# Create an activity from a comment
|
# Create an activity from a comment
|
||||||
@spec comment_to_activity(%Comment{}, boolean()) :: Activity.t()
|
@spec comment_to_activity(%Comment{}, boolean()) :: Activity.t()
|
||||||
def comment_to_activity(%Comment{} = comment, local \\ true) do
|
defp comment_to_activity(%Comment{} = comment, local \\ true) do
|
||||||
%Activity{
|
%Activity{
|
||||||
recipients: ["https://www.w3.org/ns/activitystreams#Public"],
|
recipients: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
actor: comment.actor.url,
|
actor: comment.actor.url,
|
||||||
@ -590,8 +607,9 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_public?(activity) do
|
# # Whether the Public audience is in the activity's audience
|
||||||
"https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++
|
# defp is_public?(activity) do
|
||||||
(activity.data["cc"] || []))
|
# "https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++
|
||||||
end
|
# (activity.data["cc"] || []))
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
@ -498,8 +498,10 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
|||||||
|
|
||||||
@spec normalize(map()) :: struct() | nil
|
@spec normalize(map()) :: struct() | nil
|
||||||
def normalize(obj) when is_map(obj), do: get_anything_by_url(obj["id"])
|
def normalize(obj) when is_map(obj), do: get_anything_by_url(obj["id"])
|
||||||
|
|
||||||
@spec normalize(String.t()) :: struct() | nil
|
@spec normalize(String.t()) :: struct() | nil
|
||||||
def normalize(url) when is_binary(url), do: get_anything_by_url(url)
|
def normalize(url) when is_binary(url), do: get_anything_by_url(url)
|
||||||
|
|
||||||
@spec normalize(any()) :: nil
|
@spec normalize(any()) :: nil
|
||||||
def normalize(_), do: nil
|
def normalize(_), do: nil
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||||||
|> Map.put("in_reply_to_comment_id", id)
|
|> Map.put("in_reply_to_comment_id", id)
|
||||||
|> Map.put("origin_comment_id", comment |> Comment.get_thread_id())
|
|> Map.put("origin_comment_id", comment |> Comment.get_thread_id())
|
||||||
|
|
||||||
# Anthing else is kind of a MP
|
# Anything else is kind of a MP
|
||||||
{:error, object} ->
|
{:error, object} ->
|
||||||
Logger.debug("Parent object is something we don't handle")
|
Logger.debug("Parent object is something we don't handle")
|
||||||
Logger.debug(inspect(object))
|
Logger.debug(inspect(object))
|
||||||
@ -239,6 +239,16 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||||||
@doc """
|
@doc """
|
||||||
Make an AP event object from an set of values
|
Make an AP event object from an set of values
|
||||||
"""
|
"""
|
||||||
|
@spec make_event_data(
|
||||||
|
String.t(),
|
||||||
|
String.t(),
|
||||||
|
String.t(),
|
||||||
|
String.t(),
|
||||||
|
list(),
|
||||||
|
list(),
|
||||||
|
map(),
|
||||||
|
String.t()
|
||||||
|
) :: map()
|
||||||
def make_event_data(
|
def make_event_data(
|
||||||
actor,
|
actor,
|
||||||
to,
|
to,
|
||||||
@ -271,6 +281,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec make_event_data(Event.t(), list(String.t())) :: map()
|
||||||
def make_event_data(
|
def make_event_data(
|
||||||
%Event{title: title, organizer_actor: actor, uuid: uuid},
|
%Event{title: title, organizer_actor: actor, uuid: uuid},
|
||||||
to \\ ["https://www.w3.org/ns/activitystreams#Public"]
|
to \\ ["https://www.w3.org/ns/activitystreams#Public"]
|
||||||
|
@ -55,6 +55,7 @@ defmodule Mobilizon.Service.WebFinger do
|
|||||||
@spec represent_actor(Actor.t()) :: struct()
|
@spec represent_actor(Actor.t()) :: struct()
|
||||||
def represent_actor(actor), do: represent_actor(actor, "JSON")
|
def represent_actor(actor), do: represent_actor(actor, "JSON")
|
||||||
|
|
||||||
|
@spec represent_actor(Actor.t(), String.t()) :: struct()
|
||||||
def represent_actor(actor, "JSON") do
|
def represent_actor(actor, "JSON") do
|
||||||
%{
|
%{
|
||||||
"subject" => "acct:#{actor.preferred_username}@#{MobilizonWeb.Endpoint.host()}",
|
"subject" => "acct:#{actor.preferred_username}@#{MobilizonWeb.Endpoint.host()}",
|
||||||
|
Loading…
Reference in New Issue
Block a user