Fix all warnings

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-11-12 23:30:47 +01:00
parent a04dfc5293
commit 2939485321
27 changed files with 93 additions and 142 deletions

View File

@@ -153,7 +153,7 @@ defmodule Mobilizon.Service.ActivityPub do
end
end
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, follow} <- Actor.follow(follower, followed, true),
data <- make_follow_data(follower, followed, follow.id),
{:ok, activity} <- insert(data, local),
@@ -197,9 +197,6 @@ defmodule Mobilizon.Service.ActivityPub do
end
end
def create_public_activities(%Actor{} = actor) do
end
@doc """
Create an actor locally by it's URL (AP ID)
"""
@@ -283,18 +280,15 @@ defmodule Mobilizon.Service.ActivityPub do
"content-length": byte_size(json)
})
{:ok, response} =
HTTPoison.post(
inbox,
json,
[{"Content-Type", "application/activity+json"}, {"signature", signature}],
hackney: [pool: :default]
)
HTTPoison.post(
inbox,
json,
[{"Content-Type", "application/activity+json"}, {"signature", signature}],
hackney: [pool: :default]
)
end
@doc """
Fetching a remote actor's informations through it's AP ID
"""
# Fetching a remote actor's informations 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")
@@ -352,8 +346,8 @@ defmodule Mobilizon.Service.ActivityPub do
def fetch_public_activities_for_actor(%Actor{} = actor, page \\ 1, limit \\ 10) do
case actor.type do
:Person ->
{:ok, events, total} = Events.get_events_for_actor(actor, page, limit)
{:ok, comments, total} = Events.get_comments_for_actor(actor, page, limit)
{:ok, events, total_events} = Events.get_events_for_actor(actor, page, limit)
{:ok, comments, total_comments} = Events.get_comments_for_actor(actor, page, limit)
event_activities = Enum.map(events, &event_to_activity/1)
@@ -361,7 +355,7 @@ defmodule Mobilizon.Service.ActivityPub do
activities = event_activities ++ comment_activities
{activities, total}
{activities, total_events + total_comments}
:Service ->
bot = Actors.get_bot_by_actor(actor)
@@ -389,9 +383,7 @@ defmodule Mobilizon.Service.ActivityPub do
end
end
@doc """
Create an activity from an event
"""
# Create an activity from an event
@spec event_to_activity(%Event{}, boolean()) :: Activity.t()
defp event_to_activity(%Event{} = event, local \\ true) do
%Activity{
@@ -402,9 +394,7 @@ defmodule Mobilizon.Service.ActivityPub do
}
end
@doc """
Create an activity from a comment
"""
# Create an activity from a comment
@spec comment_to_activity(%Comment{}, boolean()) :: Activity.t()
defp comment_to_activity(%Comment{} = comment, local \\ true) do
%Activity{
@@ -415,7 +405,7 @@ defmodule Mobilizon.Service.ActivityPub do
}
end
defp ical_event_to_activity(%ExIcal.Event{} = ical_event, %Actor{} = actor, source) do
defp ical_event_to_activity(%ExIcal.Event{} = ical_event, %Actor{} = actor, _source) do
# Logger.debug(inspect ical_event)
# TODO : refactor me !
# TODO : also, there should be a form of cache that allows this to be more efficient

View File

@@ -6,8 +6,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
alias Mobilizon.Actors
alias Mobilizon.Events.{Event, Comment}
alias Mobilizon.Service.ActivityPub
import Ecto.Query
alias Mobilizon.Service.ActivityPub.Utils
require Logger
@@ -89,11 +88,10 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
with {:ok, %Actor{} = actor} <- Actors.get_or_fetch_by_url(data["actor"]) do
Logger.debug("found actor")
object = fix_object(data["object"])
params = %{
to: data["to"],
object: object,
object: object |> fix_object,
actor: actor,
local: false,
published: data["published"],
@@ -234,11 +232,9 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|> set_reply_to_uri
end
@doc
"""
@doc """
internal -> Mastodon
"""
def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
Logger.debug("Prepare outgoing for a note creation")
@@ -249,43 +245,42 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
data =
data
|> Map.put("object", object)
|> Map.put("@context", "https://www.w3.org/ns/activitystreams")
|> Map.merge(Utils.make_json_ld_header())
Logger.debug("Finished prepare outgoing for a note creation")
{:ok, data}
end
def prepare_outgoing(%{"type" => type} = data) do
def prepare_outgoing(%{"type" => _type} = data) do
data =
data
# |> maybe_fix_object_url
|> Map.put("@context", "https://www.w3.org/ns/activitystreams")
|> Map.merge(Utils.make_json_ld_header())
{:ok, data}
end
def prepare_outgoing(%Event{} = event) do
event =
event
|> Map.from_struct()
|> Map.drop([:__meta__])
|> Map.put(:"@context", "https://www.w3.org/ns/activitystreams")
|> prepare_object
# def prepare_outgoing(%Event{} = event) do
# event =
# event
# |> Map.from_struct()
# |> Map.drop([:__meta__])
# |> Map.put(:"@context", "https://www.w3.org/ns/activitystreams")
# |> prepare_object
{:ok, event}
end
# {:ok, event}
# end
def prepare_outgoing(%Comment{} = comment) do
comment =
comment
|> Map.from_struct()
|> Map.drop([:__meta__])
|> Map.put(:"@context", "https://www.w3.org/ns/activitystreams")
|> prepare_object
# def prepare_outgoing(%Comment{} = comment) do
# comment =
# comment
# |> Map.from_struct()
# |> Map.drop([:__meta__])
# |> Map.put(:"@context", "https://www.w3.org/ns/activitystreams")
# |> prepare_object
{:ok, comment}
end
# {:ok, comment}
# end
#
# def maybe_fix_object_url(data) do

View File

@@ -13,11 +13,8 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
alias Mobilizon.Events
alias Mobilizon.Activity
alias MobilizonWeb
alias MobilizonWeb.Router.Helpers
alias MobilizonWeb.Endpoint
alias Mobilizon.Service.ActivityPub
alias Ecto.{Changeset, UUID}
import Ecto.Query
require Logger
def make_context(%Activity{data: %{"context" => context}}), do: context
@@ -97,7 +94,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
"""
def lazy_put_activity_defaults(map) do
if is_map(map["object"]) do
object = lazy_put_object_defaults(map["object"], map)
object = lazy_put_object_defaults(map["object"])
%{map | "object" => object}
else
map
@@ -107,9 +104,8 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
@doc """
Adds an id and published date if they aren't there.
"""
def lazy_put_object_defaults(map, activity \\ %{}) do
map
|> Map.put_new_lazy("published", &make_date/0)
def lazy_put_object_defaults(map) do
Map.put_new_lazy(map, "published", &make_date/0)
end
@doc """
@@ -174,7 +170,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
data
end
with {:ok, comm} <- Events.create_comment(data) do
with {:ok, _comment} <- Events.create_comment(data) do
:ok
else
err ->
@@ -261,7 +257,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
# attachments,
inReplyTo \\ nil,
# tags,
cw \\ nil,
_cw \\ nil,
cc \\ []
) do
Logger.debug("Making comment data")
@@ -270,7 +266,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
object = %{
"type" => "Note",
"to" => to,
# "cc" => cc,
"cc" => cc,
"content" => content_html,
# "summary" => cw,
# "attachment" => attachments,

View File

@@ -8,7 +8,7 @@ defmodule Mobilizon.Service.HTTPSignatures do
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.ActivityPub
import Logger
require Logger
def split_signature(sig) do
default = %{"headers" => "date"}

View File

@@ -7,7 +7,6 @@ defmodule Mobilizon.Service.Streamer do
use GenServer
require Logger
alias Mobilizon.Accounts.Actor
def init(args) do
{:ok, args}

View File

@@ -7,7 +7,6 @@ defmodule Mobilizon.Service.WebFinger do
alias Mobilizon.Actors
alias Mobilizon.Service.XmlBuilder
alias Mobilizon.Repo
require Jason
require Logger