Move Activity under Events context

This commit is contained in:
miffigriffy 2019-09-13 01:35:03 +02:00
parent e358dcce77
commit d3f3553ae7
17 changed files with 59 additions and 50 deletions

View file

@ -1,7 +0,0 @@
defmodule Mobilizon.Activity do
@moduledoc """
Represents an activity
"""
defstruct [:data, :local, :actor, :recipients, :notifications]
end

View file

@ -0,0 +1,13 @@
defmodule Mobilizon.Events.Activity do
@moduledoc """
Represents an activity.
"""
defstruct [
:data,
:local,
:actor,
:recipients,
:notifications
]
end

View file

@ -587,8 +587,6 @@ defmodule Mobilizon.Events do
def get_tag(id), do: Repo.get(Tag, id) def get_tag(id), do: Repo.get(Tag, id)
def get_tag_by_slug(slug) do def get_tag_by_slug(slug) do
query = query =
from( from(
@ -760,9 +758,6 @@ defmodule Mobilizon.Events do
Repo.all(final_query) Repo.all(final_query)
end end
alias Mobilizon.Events.Participant alias Mobilizon.Events.Participant
@doc """ @doc """

View file

@ -3,17 +3,18 @@ defmodule MobilizonWeb.API.Reports do
API for Reports API for Reports
""" """
import MobilizonWeb.API.Utils
import Mobilizon.Service.Admin.ActionLogService
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Events alias Mobilizon.Events
alias Mobilizon.Activity alias Mobilizon.Events.Activity
alias Mobilizon.Reports, as: ReportsAction alias Mobilizon.Reports, as: ReportsAction
alias Mobilizon.Reports.{Report, Note} alias Mobilizon.Reports.{Report, Note}
alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub
alias Mobilizon.Users alias Mobilizon.Users
alias Mobilizon.Users.User alias Mobilizon.Users.User
import MobilizonWeb.API.Utils
import Mobilizon.Service.Admin.ActionLogService
@doc """ @doc """
Create a report/flag on an actor, and optionally on an event or on comments. Create a report/flag on an actor, and optionally on an event or on comments.

View file

@ -2,12 +2,14 @@ defmodule MobilizonWeb.Resolvers.Comment do
@moduledoc """ @moduledoc """
Handles the comment-related GraphQL calls Handles the comment-related GraphQL calls
""" """
require Logger
alias Mobilizon.Events.Comment alias Mobilizon.Events.{Activity, Comment}
alias Mobilizon.Activity
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias MobilizonWeb.API.Comments alias MobilizonWeb.API.Comments
require Logger
def create_comment(_parent, %{text: comment, actor_username: username}, %{ def create_comment(_parent, %{text: comment, actor_username: username}, %{
context: %{current_user: %User{} = _user} context: %{current_user: %User{} = _user}
}) do }) do

View file

@ -2,12 +2,11 @@ defmodule MobilizonWeb.Resolvers.Event do
@moduledoc """ @moduledoc """
Handles the event-related GraphQL calls Handles the event-related GraphQL calls
""" """
alias Mobilizon.Activity
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses alias Mobilizon.Addresses
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Events alias Mobilizon.Events
alias Mobilizon.Events.{Event, Participant} alias Mobilizon.Events.{Activity, Event, Participant}
alias Mobilizon.Media.Picture alias Mobilizon.Media.Picture
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias MobilizonWeb.Resolvers.Person alias MobilizonWeb.Resolvers.Person

View file

@ -4,10 +4,12 @@ defmodule MobilizonWeb.Resolvers.Group do
""" """
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Actors.{Actor, Member} alias Mobilizon.Actors.{Actor, Member}
alias Mobilizon.Events.Activity
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub
alias Mobilizon.Activity
alias MobilizonWeb.Resolvers.Person alias MobilizonWeb.Resolvers.Person
require Logger require Logger
@doc """ @doc """

View file

@ -3,9 +3,9 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Events.Activity
alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Utils alias Mobilizon.Service.ActivityPub.Utils
alias Mobilizon.Activity
@private_visibility_empty_collection %{elements: [], total: 0} @private_visibility_empty_collection %{elements: [], total: 0}

View file

@ -1,7 +1,8 @@
defmodule MobilizonWeb.ActivityPub.ObjectView do defmodule MobilizonWeb.ActivityPub.ObjectView do
use MobilizonWeb, :view use MobilizonWeb, :view
alias Mobilizon.Events.Activity
alias Mobilizon.Service.ActivityPub.Utils alias Mobilizon.Service.ActivityPub.Utils
alias Mobilizon.Activity
def render("activity.json", %{activity: %Activity{local: local, data: data} = activity}) do def render("activity.json", %{activity: %Activity{local: local, data: data} = activity}) do
%{ %{

View file

@ -12,10 +12,9 @@ defmodule Mobilizon.Service.ActivityPub do
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Events alias Mobilizon.Events
alias Mobilizon.Events.{Event, Comment, Participant} alias Mobilizon.Events.{Activity, Event, Comment, Participant}
alias Mobilizon.Service.ActivityPub.Transmogrifier alias Mobilizon.Service.ActivityPub.Transmogrifier
alias Mobilizon.Service.WebFinger alias Mobilizon.Service.WebFinger
alias Mobilizon.Activity
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Actors.{Actor, Follower} alias Mobilizon.Actors.{Actor, Follower}

View file

@ -8,11 +8,13 @@ defmodule Mobilizon.Service.ActivityPub.Relay do
Handles following and unfollowing relays and instances Handles following and unfollowing relays and instances
""" """
alias Mobilizon.Activity
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Events.Activity
alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub
alias MobilizonWeb.API.Follows alias MobilizonWeb.API.Follows
require Logger require Logger
def get_actor do def get_actor do

View file

@ -10,25 +10,26 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
Various utils Various utils
""" """
alias Mobilizon.Storage.Repo alias Ecto.Changeset
alias Mobilizon.Addresses alias Mobilizon.Addresses
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Events.Event
alias Mobilizon.Events.Comment
alias Mobilizon.Media.Picture
alias Mobilizon.Events alias Mobilizon.Events
alias Mobilizon.Activity alias Mobilizon.Events.{Activity, Comment, Event}
alias Mobilizon.Media.Picture
alias Mobilizon.Reports alias Mobilizon.Reports
alias Mobilizon.Reports.Report alias Mobilizon.Reports.Report
alias Mobilizon.Users
alias Mobilizon.Service.ActivityPub.Converters alias Mobilizon.Service.ActivityPub.Converters
alias Ecto.Changeset alias Mobilizon.Storage.Repo
require Logger alias Mobilizon.Users
alias MobilizonWeb.Router.Helpers, as: Routes alias MobilizonWeb.Router.Helpers, as: Routes
alias MobilizonWeb.Endpoint alias MobilizonWeb.Endpoint
require Logger
@actor_types ["Group", "Person", "Application"] @actor_types ["Group", "Person", "Application"]
# Some implementations send the actor URI as the actor field, others send the entire actor object, # Some implementations send the actor URI as the actor field, others send the entire actor object,

View file

@ -7,7 +7,8 @@ defmodule Mobilizon.Service.ActivityPub.Visibility do
@moduledoc """ @moduledoc """
Utility functions related to content visibility Utility functions related to content visibility
""" """
alias Mobilizon.Activity
alias Mobilizon.Events.Activity
@public "https://www.w3.org/ns/activitystreams#Public" @public "https://www.w3.org/ns/activitystreams#Public"

View file

@ -9,10 +9,12 @@ defmodule Mobilizon.Service.Federator do
""" """
use GenServer use GenServer
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Activity alias Mobilizon.Events.Activity
alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Transmogrifier alias Mobilizon.Service.ActivityPub.Transmogrifier
require Logger require Logger
@max_jobs 20 @max_jobs 20

View file

@ -197,6 +197,7 @@ defmodule Mobilizon.Mixfile do
Mobilizon.Addresses, Mobilizon.Addresses,
Mobilizon.Addresses.Address, Mobilizon.Addresses.Address,
Mobilizon.Events, Mobilizon.Events,
Mobilizon.Events.Activity,
Mobilizon.Events.Event, Mobilizon.Events.Event,
Mobilizon.Events.Comment, Mobilizon.Events.Comment,
Mobilizon.Events.FeedToken, Mobilizon.Events.FeedToken,
@ -218,7 +219,6 @@ defmodule Mobilizon.Mixfile do
Mobilizon.Users.User, Mobilizon.Users.User,
Mobilizon.Users.UserRole, Mobilizon.Users.UserRole,
Mobilizon.Users.Guards, Mobilizon.Users.Guards,
Mobilizon.Activity,
Mobilizon.Storage.Ecto, Mobilizon.Storage.Ecto,
Mobilizon.Storage.Repo Mobilizon.Storage.Repo
], ],

View file

@ -8,11 +8,10 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
import Mobilizon.Factory import Mobilizon.Factory
alias Mobilizon.Activity
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Events alias Mobilizon.Events
alias Mobilizon.Events.{Comment, Event, Participant} alias Mobilizon.Events.{Activity, Comment, Event, Participant}
alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Utils alias Mobilizon.Service.ActivityPub.Utils
alias Mobilizon.Service.ActivityPub.Transmogrifier alias Mobilizon.Service.ActivityPub.Transmogrifier
@ -26,7 +25,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
test "it works for incoming events" do test "it works for incoming events" do
data = File.read!("test/fixtures/mobilizon-post-activity.json") |> Jason.decode!() 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) Transmogrifier.handle_incoming(data)
assert data["id"] == assert data["id"] ==
@ -116,7 +115,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
test "it works for incoming notices" do test "it works for incoming notices" do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!() 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) Transmogrifier.handle_incoming(data)
assert data["id"] == "https://framapiaf.org/users/admin/statuses/99512778738411822/activity" assert data["id"] == "https://framapiaf.org/users/admin/statuses/99512778738411822/activity"

View file

@ -1,17 +1,16 @@
defmodule MobilizonWeb.API.ReportTest do defmodule MobilizonWeb.API.ReportTest do
use Mobilizon.DataCase 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 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 describe "reports" do
test "creates a report on a event" do test "creates a report on a event" do
%Actor{id: reporter_id, url: reporter_url} = insert(:actor) %Actor{id: reporter_id, url: reporter_url} = insert(:actor)