From 2939485321ff100a27a3a150b93e6f077da023ae Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 12 Nov 2018 23:30:47 +0100 Subject: [PATCH] Fix all warnings Signed-off-by: Thomas Citharel --- lib/mix/tasks/create_bot.ex | 3 +- lib/mix/tasks/toot.ex | 3 -- lib/mobilizon/actors/actor.ex | 5 +- lib/mobilizon/actors/actors.ex | 35 +++++------- lib/mobilizon/actors/bot.ex | 2 +- .../actors/service/reset_password.ex | 2 +- lib/mobilizon/actors/user.ex | 4 +- lib/mobilizon/addresses/address.ex | 6 +-- lib/mobilizon/addresses/addresses.ex | 3 +- lib/mobilizon/events/events.ex | 4 +- .../controllers/node_info_controller.ex | 6 --- lib/mobilizon_web/resolvers/actor.ex | 2 - lib/mobilizon_web/resolvers/category.ex | 5 +- lib/mobilizon_web/resolvers/event.ex | 22 +++++--- lib/mobilizon_web/resolvers/user.ex | 6 +-- lib/mobilizon_web/schema.ex | 3 -- lib/mobilizon_web/uploaders/category.ex | 2 +- .../views/activity_pub/actor_view.ex | 4 -- .../views/activity_pub/object_view.ex | 5 +- lib/service/activity_pub/activity_pub.ex | 38 +++++-------- lib/service/activity_pub/transmogrifier.ex | 53 +++++++++---------- lib/service/activity_pub/utils.ex | 16 +++--- .../http_signatures/http_signatures.ex | 2 +- lib/service/streamer.ex | 1 - lib/service/web_finger/web_finger.ex | 1 - mix.exs | 1 + mix.lock | 1 + 27 files changed, 93 insertions(+), 142 deletions(-) diff --git a/lib/mix/tasks/create_bot.ex b/lib/mix/tasks/create_bot.ex index 1fe7066f8..56975a584 100644 --- a/lib/mix/tasks/create_bot.ex +++ b/lib/mix/tasks/create_bot.ex @@ -6,9 +6,8 @@ defmodule Mix.Tasks.CreateBot do use Mix.Task alias Mobilizon.Actors alias Mobilizon.Actors.Bot - alias Mobilizon.Repo alias Mobilizon.Actors.User - import Logger + require Logger @shortdoc "Register user" def run([email, name, summary, type, url]) do diff --git a/lib/mix/tasks/toot.ex b/lib/mix/tasks/toot.ex index d208a030d..4b9f8dd78 100644 --- a/lib/mix/tasks/toot.ex +++ b/lib/mix/tasks/toot.ex @@ -6,9 +6,6 @@ defmodule Mix.Tasks.Toot do use Mix.Task alias Mobilizon.Actors alias Mobilizon.Actors.Actor - alias Mobilizon.Repo - alias Mobilizon.Events - alias Mobilizon.Events.Comment alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub.Utils require Logger diff --git a/lib/mobilizon/actors/actor.ex b/lib/mobilizon/actors/actor.ex index 80e7445cd..347f4085f 100644 --- a/lib/mobilizon/actors/actor.ex +++ b/lib/mobilizon/actors/actor.ex @@ -17,7 +17,6 @@ defmodule Mobilizon.Actors.Actor do alias Mobilizon.Actors alias Mobilizon.Actors.{Actor, User, Follower, Member} alias Mobilizon.Events.Event - alias Mobilizon.Service.ActivityPub import Ecto.Query alias Mobilizon.Repo @@ -105,7 +104,7 @@ defmodule Mobilizon.Actors.Actor do end # TODO : Use me ! - @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ + # @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ def remote_actor_creation(params) do changes = %Actor{} @@ -279,7 +278,7 @@ defmodule Mobilizon.Actors.Actor do end end - defp do_follow(%Actor{} = follower, %Actor{} = followed, approved \\ true) do + defp do_follow(%Actor{} = follower, %Actor{} = followed, approved) do Actors.create_follower(%{ "actor_id" => follower.id, "target_actor_id" => followed.id, diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index b8781a792..02e4b5ff5 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -7,7 +7,6 @@ defmodule Mobilizon.Actors do alias Mobilizon.Repo alias Mobilizon.Actors.{Actor, Bot, Member, Follower, User} - alias Mobilizon.Actors alias Mobilizon.Service.ActivityPub @@ -63,13 +62,9 @@ defmodule Mobilizon.Actors do end end - @doc """ - Returns the first actor found for an user - - Useful when the user has not defined default actor - - Raises `Ecto.NoResultsError` if no Actor is found for this ID - """ + # Returns the first actor found for an user + # Useful when the user has not defined default actor + # Raises `Ecto.NoResultsError` if no Actor is found for this ID defp get_first_actor_for_user(%Mobilizon.Actors.User{id: id} = _user) do Repo.one!(from(a in Actor, where: a.user_id == ^id)) end @@ -195,9 +190,6 @@ defmodule Mobilizon.Actors do Repo.all(User) end - defp blank?(""), do: nil - defp blank?(n), do: n - def insert_or_update_actor(data, preload \\ false) do cs = Actor.remote_actor_creation(data) @@ -321,14 +313,13 @@ defmodule Mobilizon.Actors do end def get_actor_by_name(name) do - actor = - case String.split(name, "@") do - [name] -> - Repo.one(from(a in Actor, where: a.preferred_username == ^name and is_nil(a.domain))) + case String.split(name, "@") do + [name] -> + Repo.one(from(a in Actor, where: a.preferred_username == ^name and is_nil(a.domain))) - [name, domain] -> - Repo.get_by(Actor, preferred_username: name, domain: domain) - end + [name, domain] -> + Repo.get_by(Actor, preferred_username: name, domain: domain) + end end def get_local_actor_by_name(name) do @@ -404,7 +395,7 @@ defmodule Mobilizon.Actors do Find actors by their name or displayed name """ def find_actors_by_username_or_name(username, page \\ 1, limit \\ 10) - def find_actors_by_username_or_name("", page, limit), do: [] + def find_actors_by_username_or_name("", _page, _limit), do: [] def find_actors_by_username_or_name(username, page, limit) do start = (page - 1) * limit @@ -421,9 +412,7 @@ defmodule Mobilizon.Actors do ) end - @doc """ - Sanitize the LIKE queries - """ + # Sanitize the LIKE queries defp like_sanitize(value) do "%" <> String.replace(value, ~r/([\\%_])/, "\\1") <> "%" end @@ -515,7 +504,7 @@ defmodule Mobilizon.Actors do defp handle_actor_user_changeset(changeset) do changeset = Ecto.Changeset.traverse_errors(changeset, fn - {msg, opts} -> msg + {msg, _opts} -> msg msg -> msg end) diff --git a/lib/mobilizon/actors/bot.ex b/lib/mobilizon/actors/bot.ex index 6a75f5836..b259ffc11 100644 --- a/lib/mobilizon/actors/bot.ex +++ b/lib/mobilizon/actors/bot.ex @@ -4,7 +4,7 @@ defmodule Mobilizon.Actors.Bot do """ use Ecto.Schema import Ecto.Changeset - alias Mobilizon.Actors.{Actor, User, Bot} + alias Mobilizon.Actors.{Actor, User} schema "bots" do field(:source, :string) diff --git a/lib/mobilizon/actors/service/reset_password.ex b/lib/mobilizon/actors/service/reset_password.ex index 6c41e74fd..192b327d3 100644 --- a/lib/mobilizon/actors/service/reset_password.ex +++ b/lib/mobilizon/actors/service/reset_password.ex @@ -23,7 +23,7 @@ defmodule Mobilizon.Actors.Service.ResetPassword do ) do {:ok, user} else - err -> + _err -> {:error, :invalid_token} end end diff --git a/lib/mobilizon/actors/user.ex b/lib/mobilizon/actors/user.ex index a10b673c4..1253108e5 100644 --- a/lib/mobilizon/actors/user.ex +++ b/lib/mobilizon/actors/user.ex @@ -114,9 +114,7 @@ defmodule Mobilizon.Actors.User do |> Base.url_encode64() end - @doc """ - Hash password when it's changed - """ + # Hash password when it's changed defp hash_password(changeset) do case changeset do %Ecto.Changeset{valid?: true, changes: %{password: password}} -> diff --git a/lib/mobilizon/addresses/address.ex b/lib/mobilizon/addresses/address.ex index 4ac927306..44d818b62 100644 --- a/lib/mobilizon/addresses/address.ex +++ b/lib/mobilizon/addresses/address.ex @@ -5,7 +5,7 @@ defmodule Mobilizon.Addresses.Address do import Ecto.Changeset alias Mobilizon.Addresses.Address alias Mobilizon.Events.Event - alias Mobilizon.Groups.Group + # alias Mobilizon.Actors.Actor schema "addresses" do field(:addressCountry, :string) @@ -16,8 +16,8 @@ defmodule Mobilizon.Addresses.Address do field(:geom, Geo.PostGIS.Geometry) field(:postalCode, :string) field(:streetAddress, :string) - has_one(:event, Event) - has_one(:group, Group) + has_one(:event, Event, foreign_key: :physical_address_id) + # has_one(:group, Actor) timestamps() end diff --git a/lib/mobilizon/addresses/addresses.ex b/lib/mobilizon/addresses/addresses.ex index 62f93592b..3a8a7f832 100644 --- a/lib/mobilizon/addresses/addresses.ex +++ b/lib/mobilizon/addresses/addresses.ex @@ -5,11 +5,10 @@ defmodule Mobilizon.Addresses do import Ecto.Query, warn: false alias Mobilizon.Repo + require Logger alias Mobilizon.Addresses.Address - import Logger - @geom_types [:point] @doc """ diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 323b8b283..91ce07bc6 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -215,9 +215,7 @@ defmodule Mobilizon.Events do Repo.all(query) end - @doc """ - Sanitize the LIKE queries - """ + # Sanitize the LIKE queries defp like_sanitize(value) do "%" <> String.replace(value, ~r/([\\%_])/, "\\1") <> "%" end diff --git a/lib/mobilizon_web/controllers/node_info_controller.ex b/lib/mobilizon_web/controllers/node_info_controller.ex index 7427f49f6..7cbb91500 100644 --- a/lib/mobilizon_web/controllers/node_info_controller.ex +++ b/lib/mobilizon_web/controllers/node_info_controller.ex @@ -21,10 +21,6 @@ defmodule MobilizonWeb.NodeInfoController do # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json def nodeinfo(conn, %{"version" => "2.0"}) do - import Logger - Logger.debug(inspect(@instance)) - # stats = Stats.get_stats() - response = %{ version: "2.0", software: %{ @@ -39,12 +35,10 @@ defmodule MobilizonWeb.NodeInfoController do openRegistrations: Keyword.get(@instance, :registrations_open), usage: %{ users: %{ - # total: stats.user_count || 0 total: Actors.count_users() }, localPosts: Events.count_local_events(), localComments: Events.count_local_comments() - # localPosts: stats.status_count || 0 }, metadata: %{ nodeName: Keyword.get(@instance, :name) diff --git a/lib/mobilizon_web/resolvers/actor.ex b/lib/mobilizon_web/resolvers/actor.ex index 7a89cbfa0..8cb1909c5 100644 --- a/lib/mobilizon_web/resolvers/actor.ex +++ b/lib/mobilizon_web/resolvers/actor.ex @@ -1,6 +1,4 @@ defmodule MobilizonWeb.Resolvers.Actor do - alias Mobilizon.Actors.Actor, as: ActorSchema - alias Mobilizon.Actors.User alias Mobilizon.Actors alias Mobilizon.Service.ActivityPub diff --git a/lib/mobilizon_web/resolvers/category.ex b/lib/mobilizon_web/resolvers/category.ex index ad8e6dbce..98a48ed11 100644 --- a/lib/mobilizon_web/resolvers/category.ex +++ b/lib/mobilizon_web/resolvers/category.ex @@ -1,5 +1,6 @@ defmodule MobilizonWeb.Resolvers.Category do require Logger + alias Mobilizon.Actors.User def list_categories(_parent, _args, _resolution) do categories = @@ -13,7 +14,7 @@ defmodule MobilizonWeb.Resolvers.Category do end def create_category(_parent, %{title: title, picture: picture, description: description}, %{ - context: %{current_user: user} + context: %{current_user: %User{} = _user} }) do with {:ok, category} <- Mobilizon.Events.create_category(%{ @@ -35,7 +36,7 @@ defmodule MobilizonWeb.Resolvers.Category do end end - def create_category(_parent, %{title: title, picture: picture, description: description}, %{}) do + def create_category(_parent, _args, %{}) do {:error, "You are not allowed to create a category if not connected"} end end diff --git a/lib/mobilizon_web/resolvers/event.ex b/lib/mobilizon_web/resolvers/event.ex index 69248bdbf..719b3c445 100644 --- a/lib/mobilizon_web/resolvers/event.ex +++ b/lib/mobilizon_web/resolvers/event.ex @@ -1,5 +1,6 @@ defmodule MobilizonWeb.Resolvers.Event do alias Mobilizon.Service.ActivityPub + alias Mobilizon.Actors def list_events(_parent, _args, _resolution) do {:ok, Mobilizon.Events.list_events()} @@ -15,10 +16,20 @@ defmodule MobilizonWeb.Resolvers.Event do end end + @doc """ + List participant for event (separate request) + """ def list_participants_for_event(_parent, %{uuid: uuid}, _resolution) do {:ok, Mobilizon.Events.list_participants_for_event(uuid)} end + @doc """ + List participants for event (through an event request) + """ + def list_participants_for_event(%{uuid: uuid}, _args, _resolution) do + {:ok, Mobilizon.Events.list_participants_for_event(uuid)} + end + @doc """ Search events by title """ @@ -30,7 +41,7 @@ defmodule MobilizonWeb.Resolvers.Event do Search events and actors by title """ def search_events_and_actors(_parent, %{search: search, page: page, limit: limit}, _resolution) do - search = String.strip(search) + search = String.trim(search) found = case String.contains?(search, "@") do @@ -52,14 +63,9 @@ defmodule MobilizonWeb.Resolvers.Event do {:ok, found} end - @doc """ - List participants for event (through an event request) - """ - def list_participants_for_event(%{uuid: uuid}, _args, _resolution) do - {:ok, Mobilizon.Events.list_participants_for_event(uuid)} - end - def create_event(_parent, args, %{context: %{current_user: user}}) do + organizer_actor_id = Map.get(args, "organizer_actor_id") || Actors.get_actor_for_user(user).id + args = args |> Map.put("organizer_actor_id", organizer_actor_id) Mobilizon.Events.create_event(args) end diff --git a/lib/mobilizon_web/resolvers/user.ex b/lib/mobilizon_web/resolvers/user.ex index 3940acd9b..df3f2c5f2 100644 --- a/lib/mobilizon_web/resolvers/user.ex +++ b/lib/mobilizon_web/resolvers/user.ex @@ -20,7 +20,7 @@ defmodule MobilizonWeb.Resolvers.User do {:error, "You need to be logged-in to view current user"} end - @desc """ + @doc """ Login an user. Returns a token and the user """ def login_user(_parent, %{email: email, password: password}, _resolution) do @@ -37,7 +37,7 @@ defmodule MobilizonWeb.Resolvers.User do end end - @desc """ + @doc """ Register an user : - create the user - create the actor @@ -111,7 +111,7 @@ defmodule MobilizonWeb.Resolvers.User do end end - @desc "Change an user default actor" + @doc "Change an user default actor" def change_default_actor(_parent, %{preferred_username: username}, %{ context: %{current_user: user} }) do diff --git a/lib/mobilizon_web/schema.ex b/lib/mobilizon_web/schema.ex index 972a44911..4ac07750a 100644 --- a/lib/mobilizon_web/schema.ex +++ b/lib/mobilizon_web/schema.ex @@ -10,9 +10,6 @@ defmodule MobilizonWeb.Schema do import_types(Absinthe.Type.Custom) import_types(Absinthe.Plug.Types) - # import_types(MobilizonWeb.Schema.EventTypes) - # import_types(MobilizonWeb.Schema.ActorTypes) - alias MobilizonWeb.Resolvers @desc "An ActivityPub actor" diff --git a/lib/mobilizon_web/uploaders/category.ex b/lib/mobilizon_web/uploaders/category.ex index 9e9fd7977..a42c41ac8 100644 --- a/lib/mobilizon_web/uploaders/category.ex +++ b/lib/mobilizon_web/uploaders/category.ex @@ -23,7 +23,7 @@ defmodule MobilizonWeb.Uploaders.Category do end # Override the persisted filenames: - def filename(version, {file, %{title: title}}) do + def filename(version, {_file, %{title: title}}) do "#{title}_#{version}" end diff --git a/lib/mobilizon_web/views/activity_pub/actor_view.ex b/lib/mobilizon_web/views/activity_pub/actor_view.ex index 68b47257f..598034978 100644 --- a/lib/mobilizon_web/views/activity_pub/actor_view.ex +++ b/lib/mobilizon_web/views/activity_pub/actor_view.ex @@ -3,14 +3,10 @@ defmodule MobilizonWeb.ActivityPub.ActorView do alias MobilizonWeb.ActivityPub.ActorView alias MobilizonWeb.ActivityPub.ObjectView - alias MobilizonWeb.WebFinger alias Mobilizon.Actors.Actor - alias Mobilizon.Repo alias Mobilizon.Service.ActivityPub - alias Mobilizon.Service.ActivityPub.Transmogrifier alias Mobilizon.Service.ActivityPub.Utils alias Mobilizon.Activity - import Ecto.Query def render("actor.json", %{actor: actor}) do public_key = Mobilizon.Service.ActivityPub.Utils.pem_to_public_key_pem(actor.keys) diff --git a/lib/mobilizon_web/views/activity_pub/object_view.ex b/lib/mobilizon_web/views/activity_pub/object_view.ex index 01260de81..d7b67055c 100644 --- a/lib/mobilizon_web/views/activity_pub/object_view.ex +++ b/lib/mobilizon_web/views/activity_pub/object_view.ex @@ -1,7 +1,6 @@ defmodule MobilizonWeb.ActivityPub.ObjectView do use MobilizonWeb, :view alias MobilizonWeb.ActivityPub.ObjectView - alias Mobilizon.Service.ActivityPub.Transmogrifier alias Mobilizon.Service.ActivityPub.Utils def render("event.json", %{event: event}) do @@ -37,14 +36,14 @@ defmodule MobilizonWeb.ActivityPub.ObjectView do Map.merge(comment, Utils.make_json_ld_header()) end - def render("category.json", %{category: category}) do + def render("category.json", %{category: category}) when not is_nil(category) do %{ "identifier" => category.id, "name" => category.title } end - def render("category.json", %{category: nil}) do + def render("category.json", %{category: _category}) do nil end end diff --git a/lib/service/activity_pub/activity_pub.ex b/lib/service/activity_pub/activity_pub.ex index 4b6d6c31d..812af5934 100644 --- a/lib/service/activity_pub/activity_pub.ex +++ b/lib/service/activity_pub/activity_pub.ex @@ -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 diff --git a/lib/service/activity_pub/transmogrifier.ex b/lib/service/activity_pub/transmogrifier.ex index a9e615864..e9dbea7ef 100644 --- a/lib/service/activity_pub/transmogrifier.ex +++ b/lib/service/activity_pub/transmogrifier.ex @@ -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 diff --git a/lib/service/activity_pub/utils.ex b/lib/service/activity_pub/utils.ex index cea18d744..86e0be515 100644 --- a/lib/service/activity_pub/utils.ex +++ b/lib/service/activity_pub/utils.ex @@ -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, diff --git a/lib/service/http_signatures/http_signatures.ex b/lib/service/http_signatures/http_signatures.ex index 9673a2810..ef4aae7cf 100644 --- a/lib/service/http_signatures/http_signatures.ex +++ b/lib/service/http_signatures/http_signatures.ex @@ -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"} diff --git a/lib/service/streamer.ex b/lib/service/streamer.ex index b2b9f9cd6..b5665bc8c 100644 --- a/lib/service/streamer.ex +++ b/lib/service/streamer.ex @@ -7,7 +7,6 @@ defmodule Mobilizon.Service.Streamer do use GenServer require Logger - alias Mobilizon.Accounts.Actor def init(args) do {:ok, args} diff --git a/lib/service/web_finger/web_finger.ex b/lib/service/web_finger/web_finger.ex index 65217cb0b..83e0d0662 100644 --- a/lib/service/web_finger/web_finger.ex +++ b/lib/service/web_finger/web_finger.ex @@ -7,7 +7,6 @@ defmodule Mobilizon.Service.WebFinger do alias Mobilizon.Actors alias Mobilizon.Service.XmlBuilder - alias Mobilizon.Repo require Jason require Logger diff --git a/mix.exs b/mix.exs index 396d952dc..611c26cde 100644 --- a/mix.exs +++ b/mix.exs @@ -84,6 +84,7 @@ defmodule Mobilizon.Mixfile do {:arc, "~> 0.11.0"}, {:arc_ecto, "~> 0.11.0"}, {:email_checker, "~> 0.1.2"}, + {:plug_cowboy, "~> 1.0"}, # Dev and test dependencies {:phoenix_live_reload, "~> 1.0", only: :dev}, {:ex_machina, "~> 2.2", only: [:dev, :test]}, diff --git a/mix.lock b/mix.lock index c4544b8eb..7c5bb92e5 100644 --- a/mix.lock +++ b/mix.lock @@ -71,6 +71,7 @@ "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.1.7", "425fff579085f7eacaf009e71940be07338c8d8b78d16e307c50c7d82a381497", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3 or ~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.1", "6668d787e602981f24f17a5fbb69cc98f8ab085114ebfac6cc36e10a90c8e93c", [:mix], [], "hexpm"}, "plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"}, + "plug_cowboy": {:hex, :plug_cowboy, "1.0.0", "2e2a7d3409746d335f451218b8bb0858301c3de6d668c3052716c909936eb57a", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, "plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},