From d3f3553ae7ff2b7a637ed3ea91291f88211dcf34 Mon Sep 17 00:00:00 2001 From: miffigriffy Date: Fri, 13 Sep 2019 01:35:03 +0200 Subject: [PATCH] Move Activity under Events context --- lib/mobilizon/activity.ex | 7 ------- lib/mobilizon/events/activity.ex | 13 +++++++++++++ lib/mobilizon/events/events.ex | 5 ----- lib/mobilizon_web/api/reports.ex | 7 ++++--- lib/mobilizon_web/resolvers/comment.ex | 8 +++++--- lib/mobilizon_web/resolvers/event.ex | 3 +-- lib/mobilizon_web/resolvers/group.ex | 4 +++- .../views/activity_pub/actor_view.ex | 2 +- .../views/activity_pub/object_view.ex | 3 ++- lib/service/activity_pub/activity_pub.ex | 3 +-- lib/service/activity_pub/relay.ex | 4 +++- lib/service/activity_pub/utils.ex | 17 +++++++++-------- lib/service/activity_pub/visibility.ex | 3 ++- lib/service/federator.ex | 4 +++- mix.exs | 2 +- .../activity_pub/transmogrifier_test.exs | 7 +++---- test/mobilizon_web/api/report_test.exs | 17 ++++++++--------- 17 files changed, 59 insertions(+), 50 deletions(-) delete mode 100644 lib/mobilizon/activity.ex create mode 100644 lib/mobilizon/events/activity.ex diff --git a/lib/mobilizon/activity.ex b/lib/mobilizon/activity.ex deleted file mode 100644 index 2bcdc4fed..000000000 --- a/lib/mobilizon/activity.ex +++ /dev/null @@ -1,7 +0,0 @@ -defmodule Mobilizon.Activity do - @moduledoc """ - Represents an activity - """ - - defstruct [:data, :local, :actor, :recipients, :notifications] -end diff --git a/lib/mobilizon/events/activity.ex b/lib/mobilizon/events/activity.ex new file mode 100644 index 000000000..7daf805e7 --- /dev/null +++ b/lib/mobilizon/events/activity.ex @@ -0,0 +1,13 @@ +defmodule Mobilizon.Events.Activity do + @moduledoc """ + Represents an activity. + """ + + defstruct [ + :data, + :local, + :actor, + :recipients, + :notifications + ] +end diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 29f483aae..24c93fa5e 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -587,8 +587,6 @@ defmodule Mobilizon.Events do def get_tag(id), do: Repo.get(Tag, id) - - def get_tag_by_slug(slug) do query = from( @@ -760,9 +758,6 @@ defmodule Mobilizon.Events do Repo.all(final_query) end - - - alias Mobilizon.Events.Participant @doc """ diff --git a/lib/mobilizon_web/api/reports.ex b/lib/mobilizon_web/api/reports.ex index 815471acd..171e70b04 100644 --- a/lib/mobilizon_web/api/reports.ex +++ b/lib/mobilizon_web/api/reports.ex @@ -3,17 +3,18 @@ defmodule MobilizonWeb.API.Reports do API for Reports """ + import MobilizonWeb.API.Utils + import Mobilizon.Service.Admin.ActionLogService + alias Mobilizon.Actors alias Mobilizon.Actors.Actor alias Mobilizon.Events - alias Mobilizon.Activity + alias Mobilizon.Events.Activity alias Mobilizon.Reports, as: ReportsAction alias Mobilizon.Reports.{Report, Note} alias Mobilizon.Service.ActivityPub alias Mobilizon.Users alias Mobilizon.Users.User - import MobilizonWeb.API.Utils - import Mobilizon.Service.Admin.ActionLogService @doc """ Create a report/flag on an actor, and optionally on an event or on comments. diff --git a/lib/mobilizon_web/resolvers/comment.ex b/lib/mobilizon_web/resolvers/comment.ex index c167b898f..cbe0b248b 100644 --- a/lib/mobilizon_web/resolvers/comment.ex +++ b/lib/mobilizon_web/resolvers/comment.ex @@ -2,12 +2,14 @@ defmodule MobilizonWeb.Resolvers.Comment do @moduledoc """ Handles the comment-related GraphQL calls """ - require Logger - alias Mobilizon.Events.Comment - alias Mobilizon.Activity + + alias Mobilizon.Events.{Activity, Comment} alias Mobilizon.Users.User + alias MobilizonWeb.API.Comments + require Logger + def create_comment(_parent, %{text: comment, actor_username: username}, %{ context: %{current_user: %User{} = _user} }) do diff --git a/lib/mobilizon_web/resolvers/event.ex b/lib/mobilizon_web/resolvers/event.ex index 339bbdcba..370b507a2 100644 --- a/lib/mobilizon_web/resolvers/event.ex +++ b/lib/mobilizon_web/resolvers/event.ex @@ -2,12 +2,11 @@ defmodule MobilizonWeb.Resolvers.Event do @moduledoc """ Handles the event-related GraphQL calls """ - alias Mobilizon.Activity alias Mobilizon.Actors.Actor alias Mobilizon.Addresses alias Mobilizon.Addresses.Address alias Mobilizon.Events - alias Mobilizon.Events.{Event, Participant} + alias Mobilizon.Events.{Activity, Event, Participant} alias Mobilizon.Media.Picture alias Mobilizon.Users.User alias MobilizonWeb.Resolvers.Person diff --git a/lib/mobilizon_web/resolvers/group.ex b/lib/mobilizon_web/resolvers/group.ex index 5aa35e861..e9422bb50 100644 --- a/lib/mobilizon_web/resolvers/group.ex +++ b/lib/mobilizon_web/resolvers/group.ex @@ -4,10 +4,12 @@ defmodule MobilizonWeb.Resolvers.Group do """ alias Mobilizon.Actors alias Mobilizon.Actors.{Actor, Member} + alias Mobilizon.Events.Activity alias Mobilizon.Users.User alias Mobilizon.Service.ActivityPub - alias Mobilizon.Activity + alias MobilizonWeb.Resolvers.Person + require Logger @doc """ diff --git a/lib/mobilizon_web/views/activity_pub/actor_view.ex b/lib/mobilizon_web/views/activity_pub/actor_view.ex index 5ecf495c7..c1679bb53 100644 --- a/lib/mobilizon_web/views/activity_pub/actor_view.ex +++ b/lib/mobilizon_web/views/activity_pub/actor_view.ex @@ -3,9 +3,9 @@ defmodule MobilizonWeb.ActivityPub.ActorView do alias Mobilizon.Actors alias Mobilizon.Actors.Actor + alias Mobilizon.Events.Activity alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub.Utils - alias Mobilizon.Activity @private_visibility_empty_collection %{elements: [], total: 0} diff --git a/lib/mobilizon_web/views/activity_pub/object_view.ex b/lib/mobilizon_web/views/activity_pub/object_view.ex index 9a1da8fca..576b9e751 100644 --- a/lib/mobilizon_web/views/activity_pub/object_view.ex +++ b/lib/mobilizon_web/views/activity_pub/object_view.ex @@ -1,7 +1,8 @@ defmodule MobilizonWeb.ActivityPub.ObjectView do use MobilizonWeb, :view + + alias Mobilizon.Events.Activity alias Mobilizon.Service.ActivityPub.Utils - alias Mobilizon.Activity def render("activity.json", %{activity: %Activity{local: local, data: data} = activity}) do %{ diff --git a/lib/service/activity_pub/activity_pub.ex b/lib/service/activity_pub/activity_pub.ex index 7818cbfd8..68e23ec59 100644 --- a/lib/service/activity_pub/activity_pub.ex +++ b/lib/service/activity_pub/activity_pub.ex @@ -12,10 +12,9 @@ defmodule Mobilizon.Service.ActivityPub do alias Mobilizon.Config alias Mobilizon.Events - alias Mobilizon.Events.{Event, Comment, Participant} + alias Mobilizon.Events.{Activity, Event, Comment, Participant} alias Mobilizon.Service.ActivityPub.Transmogrifier alias Mobilizon.Service.WebFinger - alias Mobilizon.Activity alias Mobilizon.Actors alias Mobilizon.Actors.{Actor, Follower} diff --git a/lib/service/activity_pub/relay.ex b/lib/service/activity_pub/relay.ex index 3333be71b..ef44fbbea 100644 --- a/lib/service/activity_pub/relay.ex +++ b/lib/service/activity_pub/relay.ex @@ -8,11 +8,13 @@ defmodule Mobilizon.Service.ActivityPub.Relay do Handles following and unfollowing relays and instances """ - alias Mobilizon.Activity alias Mobilizon.Actors alias Mobilizon.Actors.Actor + alias Mobilizon.Events.Activity alias Mobilizon.Service.ActivityPub + alias MobilizonWeb.API.Follows + require Logger def get_actor do diff --git a/lib/service/activity_pub/utils.ex b/lib/service/activity_pub/utils.ex index db8757bb6..ff7655231 100644 --- a/lib/service/activity_pub/utils.ex +++ b/lib/service/activity_pub/utils.ex @@ -10,25 +10,26 @@ defmodule Mobilizon.Service.ActivityPub.Utils do Various utils """ - alias Mobilizon.Storage.Repo + alias Ecto.Changeset + alias Mobilizon.Addresses alias Mobilizon.Addresses.Address alias Mobilizon.Actors alias Mobilizon.Actors.Actor - alias Mobilizon.Events.Event - alias Mobilizon.Events.Comment - alias Mobilizon.Media.Picture alias Mobilizon.Events - alias Mobilizon.Activity + alias Mobilizon.Events.{Activity, Comment, Event} + alias Mobilizon.Media.Picture alias Mobilizon.Reports alias Mobilizon.Reports.Report - alias Mobilizon.Users alias Mobilizon.Service.ActivityPub.Converters - alias Ecto.Changeset - require Logger + alias Mobilizon.Storage.Repo + alias Mobilizon.Users + alias MobilizonWeb.Router.Helpers, as: Routes alias MobilizonWeb.Endpoint + require Logger + @actor_types ["Group", "Person", "Application"] # Some implementations send the actor URI as the actor field, others send the entire actor object, diff --git a/lib/service/activity_pub/visibility.ex b/lib/service/activity_pub/visibility.ex index 93a5c5aba..756965910 100644 --- a/lib/service/activity_pub/visibility.ex +++ b/lib/service/activity_pub/visibility.ex @@ -7,7 +7,8 @@ defmodule Mobilizon.Service.ActivityPub.Visibility do @moduledoc """ Utility functions related to content visibility """ - alias Mobilizon.Activity + + alias Mobilizon.Events.Activity @public "https://www.w3.org/ns/activitystreams#Public" diff --git a/lib/service/federator.ex b/lib/service/federator.ex index 5e19e8a4c..4d8b99cd0 100644 --- a/lib/service/federator.ex +++ b/lib/service/federator.ex @@ -9,10 +9,12 @@ defmodule Mobilizon.Service.Federator do """ use GenServer + alias Mobilizon.Actors - alias Mobilizon.Activity + alias Mobilizon.Events.Activity alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub.Transmogrifier + require Logger @max_jobs 20 diff --git a/mix.exs b/mix.exs index 67ad05c5f..9386944c1 100644 --- a/mix.exs +++ b/mix.exs @@ -197,6 +197,7 @@ defmodule Mobilizon.Mixfile do Mobilizon.Addresses, Mobilizon.Addresses.Address, Mobilizon.Events, + Mobilizon.Events.Activity, Mobilizon.Events.Event, Mobilizon.Events.Comment, Mobilizon.Events.FeedToken, @@ -218,7 +219,6 @@ defmodule Mobilizon.Mixfile do Mobilizon.Users.User, Mobilizon.Users.UserRole, Mobilizon.Users.Guards, - Mobilizon.Activity, Mobilizon.Storage.Ecto, Mobilizon.Storage.Repo ], diff --git a/test/mobilizon/service/activity_pub/transmogrifier_test.exs b/test/mobilizon/service/activity_pub/transmogrifier_test.exs index 7eb340ae4..91ec98007 100644 --- a/test/mobilizon/service/activity_pub/transmogrifier_test.exs +++ b/test/mobilizon/service/activity_pub/transmogrifier_test.exs @@ -8,11 +8,10 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do import Mobilizon.Factory - alias Mobilizon.Activity alias Mobilizon.Actors alias Mobilizon.Actors.Actor alias Mobilizon.Events - alias Mobilizon.Events.{Comment, Event, Participant} + alias Mobilizon.Events.{Activity, Comment, Event, Participant} alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub.Utils alias Mobilizon.Service.ActivityPub.Transmogrifier @@ -26,7 +25,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do test "it works for incoming events" do data = File.read!("test/fixtures/mobilizon-post-activity.json") |> Jason.decode!() - {:ok, %Mobilizon.Activity{data: data, local: false}, %Event{} = event} = + {:ok, %Activity{data: data, local: false}, %Event{} = event} = Transmogrifier.handle_incoming(data) assert data["id"] == @@ -116,7 +115,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do test "it works for incoming notices" do data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!() - {:ok, %Mobilizon.Activity{data: data, local: false}, _} = + {:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data) assert data["id"] == "https://framapiaf.org/users/admin/statuses/99512778738411822/activity" diff --git a/test/mobilizon_web/api/report_test.exs b/test/mobilizon_web/api/report_test.exs index fa547024b..de6df7f7e 100644 --- a/test/mobilizon_web/api/report_test.exs +++ b/test/mobilizon_web/api/report_test.exs @@ -1,17 +1,16 @@ defmodule MobilizonWeb.API.ReportTest do use Mobilizon.DataCase - alias Mobilizon.Events.Event - alias Mobilizon.Events.Comment - alias Mobilizon.Actors.Actor - alias MobilizonWeb.API.Reports - alias Mobilizon.Reports.{Report, Note} - alias Mobilizon.Activity - alias Mobilizon.Users.User - alias Mobilizon.Users - import Mobilizon.Factory + alias Mobilizon.Actors.Actor + alias Mobilizon.Events.{Activity, Comment, Event} + alias Mobilizon.Reports.{Report, Note} + alias Mobilizon.Users + alias Mobilizon.Users.User + + alias MobilizonWeb.API.Reports + describe "reports" do test "creates a report on a event" do %Actor{id: reporter_id, url: reporter_url} = insert(:actor)