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:
Thomas Citharel 2019-02-22 16:11:57 +01:00
parent d73f738b1b
commit d37c873b04
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
8 changed files with 47 additions and 15 deletions

View File

@ -213,7 +213,7 @@ defmodule Mobilizon.Actors.Actor do
@doc """
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
with {:ok, %Actor{keys: keys}} <- Actors.get_or_fetch_by_url(url),
{:ok, public_key} <- prepare_public_key(keys) do

View File

@ -579,6 +579,7 @@ defmodule Mobilizon.Events do
@doc """
Create a relation between two tags
"""
@spec create_tag_relation(map()) :: {:ok, TagRelation.t()} | {:error, Ecto.Changeset.t()}
def create_tag_relation(attrs \\ {}) do
%TagRelation{}
|> TagRelation.changeset(attrs)

View File

@ -51,7 +51,7 @@ defmodule MobilizonWeb.API.Groups do
{:existing_group, _} ->
{:error, :existing_group_name}
{:bad_actor} ->
{:bad_actor, _} ->
{:error, :bad_admin_actor}
end
end

View File

@ -32,8 +32,7 @@ defmodule MobilizonWeb.HTTPSignaturePlug do
[signature | _] = get_req_header(conn, "signature")
cond do
# Dialyzer doesn't like this line
signature && String.contains?(signature, actor) ->
String.contains?(signature, actor) ->
conn =
conn
|> put_req_header(

View File

@ -36,9 +36,8 @@ defmodule Mobilizon.Service.ActivityPub do
@doc """
Wraps an object into an activity
TODO: Rename me
"""
# TODO: Rename me
@spec insert(map(), boolean()) :: {:ok, %Activity{}} | {:error, any()}
def insert(map, local \\ true) when is_map(map) do
with map <- lazy_put_activity_defaults(map),
@ -113,6 +112,9 @@ defmodule Mobilizon.Service.ActivityPub do
end
end
@doc """
Create an activity of type "Create"
"""
def create(%{to: to, actor: actor, object: object} = params) do
Logger.debug("creating an activity")
Logger.debug(inspect(params))
@ -240,6 +242,9 @@ defmodule Mobilizon.Service.ActivityPub do
# end
# end
@doc """
Make an actor follow another
"""
def follow(%Actor{} = follower, %Actor{} = followed, activity_id \\ nil, local \\ true) do
with {:ok, %Follower{} = follow} <- Actor.follow(followed, follower, true),
activity_follow_id <- activity_id || Follower.url(follow),
@ -253,6 +258,9 @@ defmodule Mobilizon.Service.ActivityPub do
end
end
@doc """
Make an actor unfollow another
"""
@spec unfollow(Actor.t(), Actor.t(), String.t(), boolean()) :: {:ok, map()} | any()
def unfollow(%Actor{} = followed, %Actor{} = follower, activity_id \\ nil, local \\ true) do
with {:ok, %Follower{id: follow_id}} <- Actor.unfollow(followed, follower),
@ -337,7 +345,7 @@ defmodule Mobilizon.Service.ActivityPub do
end
@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()
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)
@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()}
def make_actor_from_nickname(nickname) do
@ -366,6 +374,9 @@ defmodule Mobilizon.Service.ActivityPub do
end
end
@doc """
Publish an activity to all appropriated audiences inboxes
"""
def publish(actor, activity) do
Logger.debug("Publishing an activity")
@ -395,6 +406,9 @@ defmodule Mobilizon.Service.ActivityPub do
end)
end
@doc """
Publish an activity to a specific inbox
"""
def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do
Logger.info("Federating #{id} to #{inbox}")
%URI{host: host, path: path} = URI.parse(inbox)
@ -425,7 +439,7 @@ defmodule Mobilizon.Service.ActivityPub do
)
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()
defp fetch_and_prepare_actor_from_url(url) do
Logger.debug("Fetching and preparing actor from url")
@ -447,6 +461,9 @@ defmodule Mobilizon.Service.ActivityPub do
@doc """
Creating proper actor data struct from AP data
Convert ActivityPub data to our internal format
"""
@spec actor_data_from_actor_object(map()) :: {:ok, map()}
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
@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{
recipients: ["https://www.w3.org/ns/activitystreams#Public"],
actor: comment.actor.url,
@ -590,8 +607,9 @@ defmodule Mobilizon.Service.ActivityPub do
nil
end
def is_public?(activity) do
"https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++
(activity.data["cc"] || []))
end
# # Whether the Public audience is in the activity's audience
# defp is_public?(activity) do
# "https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++
# (activity.data["cc"] || []))
# end
end

View File

@ -498,8 +498,10 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
@spec normalize(map()) :: struct() | nil
def normalize(obj) when is_map(obj), do: get_anything_by_url(obj["id"])
@spec normalize(String.t()) :: struct() | nil
def normalize(url) when is_binary(url), do: get_anything_by_url(url)
@spec normalize(any()) :: nil
def normalize(_), do: nil

View File

@ -188,7 +188,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|> Map.put("in_reply_to_comment_id", 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} ->
Logger.debug("Parent object is something we don't handle")
Logger.debug(inspect(object))
@ -239,6 +239,16 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
@doc """
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(
actor,
to,
@ -271,6 +281,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
}
end
@spec make_event_data(Event.t(), list(String.t())) :: map()
def make_event_data(
%Event{title: title, organizer_actor: actor, uuid: uuid},
to \\ ["https://www.w3.org/ns/activitystreams#Public"]

View File

@ -55,6 +55,7 @@ defmodule Mobilizon.Service.WebFinger do
@spec represent_actor(Actor.t()) :: struct()
def represent_actor(actor), do: represent_actor(actor, "JSON")
@spec represent_actor(Actor.t(), String.t()) :: struct()
def represent_actor(actor, "JSON") do
%{
"subject" => "acct:#{actor.preferred_username}@#{MobilizonWeb.Endpoint.host()}",