Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into object-normalize-refactor

This commit is contained in:
lain 2021-01-05 10:48:32 +01:00
commit d44850d7a5
10 changed files with 190 additions and 114 deletions

7
lib/pleroma/logging.ex Normal file
View file

@ -0,0 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Logging do
@callback error(String.t()) :: any()
end

View file

@ -33,6 +33,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
require Pleroma.Constants
@behaviour Pleroma.Web.ActivityPub.ActivityPub.Persisting
@behaviour Pleroma.Web.ActivityPub.ActivityPub.Streaming
defp get_recipients(%{"type" => "Create"} = data) do
to = Map.get(data, "to", [])
@ -224,6 +225,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
Streamer.stream("participation", participations)
end
@impl true
def stream_out_participations(%Object{data: %{"context" => context}}, user) do
with %Conversation{} = conversation <- Conversation.get_for_ap_id(context) do
conversation = Repo.preload(conversation, :participations)
@ -240,8 +242,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
end
@impl true
def stream_out_participations(_, _), do: :noop
@impl true
def stream_out(%Activity{data: %{"type" => data_type}} = activity)
when data_type in ["Create", "Announce", "Delete"] do
activity
@ -249,6 +253,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|> Streamer.stream(activity)
end
@impl true
def stream_out(_activity) do
:noop
end

View file

@ -0,0 +1,12 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ActivityPub.Streaming do
alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.User
@callback stream_out(Activity.t()) :: any()
@callback stream_out_participations(Object.t(), User.t()) :: any()
end

View file

@ -28,6 +28,8 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
require Logger
@cachex Pleroma.Config.get([:cachex, :provider], Cachex)
@ap_streamer Pleroma.Config.get([:side_effects, :ap_streamer], ActivityPub)
@logger Pleroma.Config.get([:side_effects, :logger], Logger)
@behaviour Pleroma.Web.ActivityPub.SideEffects.Handling
@ -287,12 +289,12 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
MessageReference.delete_for_object(deleted_object)
ActivityPub.stream_out(object)
ActivityPub.stream_out_participations(deleted_object, user)
@ap_streamer.stream_out(object)
@ap_streamer.stream_out_participations(deleted_object, user)
:ok
else
{:actor, _} ->
Logger.error("The object doesn't have an actor: #{inspect(deleted_object)}")
@logger.error("The object doesn't have an actor: #{inspect(deleted_object)}")
:no_object_actor
end