Implement Credo software design suggestions
This commit is contained in:
@@ -32,6 +32,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
|
||||
alias Mobilizon.GraphQL.API.Utils, as: APIUtils
|
||||
|
||||
alias Mobilizon.Web.Endpoint
|
||||
alias Mobilizon.Web.Email.{Admin, Mailer}
|
||||
|
||||
require Logger
|
||||
@@ -318,7 +319,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
Convertible.model_to_as(%{follow | actor: follower, target_actor: followed}),
|
||||
{:ok, follow_activity} <- create_activity(follow_as_data, local),
|
||||
activity_unfollow_id <-
|
||||
activity_id || "#{Mobilizon.Web.Endpoint.url()}/unfollow/#{follow_id}/activity",
|
||||
activity_id || "#{Endpoint.url()}/unfollow/#{follow_id}/activity",
|
||||
unfollow_data <-
|
||||
make_unfollow_data(follower, followed, follow_activity, activity_unfollow_id),
|
||||
{:ok, activity} <- create_activity(unfollow_data, local),
|
||||
@@ -483,7 +484,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
# If it's an exclusion it should be something else
|
||||
"actor" => actor_url,
|
||||
"object" => event_url,
|
||||
"id" => "#{Mobilizon.Web.Endpoint.url()}/leave/event/#{participant.id}"
|
||||
"id" => "#{Endpoint.url()}/leave/event/#{participant.id}"
|
||||
},
|
||||
audience <-
|
||||
Audience.calculate_to_and_cc_from_mentions(participant),
|
||||
@@ -778,7 +779,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
make_accept_join_data(
|
||||
follower_as_data,
|
||||
Map.merge(additional, %{
|
||||
"id" => "#{Mobilizon.Web.Endpoint.url()}/accept/follow/#{follower.id}",
|
||||
"id" => "#{Endpoint.url()}/accept/follow/#{follower.id}",
|
||||
"to" => [follower.actor.url],
|
||||
"cc" => [],
|
||||
"actor" => follower.target_actor.url
|
||||
@@ -797,7 +798,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
defp accept_join(%Participant{} = participant, additional) do
|
||||
with {:ok, %Participant{} = participant} <-
|
||||
Events.update_participant(participant, %{role: :participant}),
|
||||
Absinthe.Subscription.publish(Mobilizon.Web.Endpoint, participant.actor,
|
||||
Absinthe.Subscription.publish(Endpoint, participant.actor,
|
||||
event_person_participation_changed: participant.actor.id
|
||||
),
|
||||
participant_as_data <- Convertible.model_to_as(participant),
|
||||
@@ -807,7 +808,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
make_accept_join_data(
|
||||
participant_as_data,
|
||||
Map.merge(Map.merge(audience, additional), %{
|
||||
"id" => "#{Mobilizon.Web.Endpoint.url()}/accept/join/#{participant.id}"
|
||||
"id" => "#{Endpoint.url()}/accept/join/#{participant.id}"
|
||||
})
|
||||
) do
|
||||
{:ok, participant, update_data}
|
||||
@@ -823,7 +824,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
defp reject_join(%Participant{} = participant, additional) do
|
||||
with {:ok, %Participant{} = participant} <-
|
||||
Events.update_participant(participant, %{approved: false, role: :rejected}),
|
||||
Absinthe.Subscription.publish(Mobilizon.Web.Endpoint, participant.actor,
|
||||
Absinthe.Subscription.publish(Endpoint, participant.actor,
|
||||
event_person_participation_changed: participant.actor.id
|
||||
),
|
||||
participant_as_data <- Convertible.model_to_as(participant),
|
||||
@@ -839,7 +840,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
reject_data
|
||||
|> Map.merge(audience)
|
||||
|> Map.merge(%{
|
||||
"id" => "#{Mobilizon.Web.Endpoint.url()}/reject/join/#{participant.id}"
|
||||
"id" => "#{Endpoint.url()}/reject/join/#{participant.id}"
|
||||
}) do
|
||||
{:ok, participant, update_data}
|
||||
else
|
||||
@@ -866,7 +867,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
reject_data
|
||||
|> Map.merge(audience)
|
||||
|> Map.merge(%{
|
||||
"id" => "#{Mobilizon.Web.Endpoint.url()}/reject/follow/#{follower.id}"
|
||||
"id" => "#{Endpoint.url()}/reject/follow/#{follower.id}"
|
||||
}) do
|
||||
{:ok, follower, update_data}
|
||||
else
|
||||
|
||||
@@ -7,6 +7,7 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.{Comment, Event, Participant}
|
||||
alias Mobilizon.Share
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
require Logger
|
||||
|
||||
@@ -108,7 +109,7 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||
end
|
||||
|
||||
def calculate_to_and_cc_from_mentions(%Participant{} = participant) do
|
||||
participant = Mobilizon.Storage.Repo.preload(participant, [:actor, :event])
|
||||
participant = Repo.preload(participant, [:actor, :event])
|
||||
|
||||
actor_participants_urls =
|
||||
participant.event.id
|
||||
@@ -132,13 +133,13 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||
defp add_event_author(nil), do: []
|
||||
|
||||
defp add_event_author(%Event{} = event) do
|
||||
[Mobilizon.Storage.Repo.preload(event, [:organizer_actor]).organizer_actor.url]
|
||||
[Repo.preload(event, [:organizer_actor]).organizer_actor.url]
|
||||
end
|
||||
|
||||
defp add_comment_author(nil), do: nil
|
||||
|
||||
defp add_comment_author(%Comment{} = comment) do
|
||||
case Mobilizon.Storage.Repo.preload(comment, [:actor]) do
|
||||
case Repo.preload(comment, [:actor]) do
|
||||
%Comment{actor: %Actor{url: url}} ->
|
||||
url
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
|
||||
|
||||
alias Mobilizon.GraphQL.API.Follows
|
||||
|
||||
alias Mobilizon.Web.Endpoint
|
||||
|
||||
require Logger
|
||||
|
||||
def init() do
|
||||
@@ -28,7 +30,7 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
|
||||
@spec get_actor() :: Actor.t() | {:error, Ecto.Changeset.t()}
|
||||
def get_actor do
|
||||
with {:ok, %Actor{} = actor} <-
|
||||
Actors.get_or_create_instance_actor_by_url("#{Mobilizon.Web.Endpoint.url()}/relay") do
|
||||
Actors.get_or_create_instance_actor_by_url("#{Endpoint.url()}/relay") do
|
||||
actor
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user