federator: remove OStatus incoming document support
[akkoma] / lib / pleroma / web / federator / federator.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Federator do
6 alias Pleroma.Activity
7 alias Pleroma.Object.Containment
8 alias Pleroma.User
9 alias Pleroma.Web.ActivityPub.ActivityPub
10 alias Pleroma.Web.ActivityPub.Transmogrifier
11 alias Pleroma.Web.ActivityPub.Utils
12 alias Pleroma.Web.Federator.Publisher
13 alias Pleroma.Web.OStatus
14 alias Pleroma.Workers.PublisherWorker
15 alias Pleroma.Workers.ReceiverWorker
16
17 require Logger
18
19 @doc "Addresses [memory leaks on recursive replies fetching](https://git.pleroma.social/pleroma/pleroma/issues/161)"
20 # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
21 def allowed_incoming_reply_depth?(depth) do
22 max_replies_depth = Pleroma.Config.get([:instance, :federation_incoming_replies_max_depth])
23
24 if max_replies_depth do
25 (depth || 1) <= max_replies_depth
26 else
27 true
28 end
29 end
30
31 # Client API
32
33 def incoming_ap_doc(params) do
34 ReceiverWorker.enqueue("incoming_ap_doc", %{"params" => params})
35 end
36
37 def publish(%{id: "pleroma:fakeid"} = activity) do
38 perform(:publish, activity)
39 end
40
41 def publish(activity) do
42 PublisherWorker.enqueue("publish", %{"activity_id" => activity.id})
43 end
44
45 # Job Worker Callbacks
46
47 @spec perform(atom(), module(), any()) :: {:ok, any()} | {:error, any()}
48 def perform(:publish_one, module, params) do
49 apply(module, :publish_one, [params])
50 end
51
52 def perform(:publish, activity) do
53 Logger.debug(fn -> "Running publish for #{activity.data["id"]}" end)
54
55 with %User{} = actor <- User.get_cached_by_ap_id(activity.data["actor"]),
56 {:ok, actor} <- User.ensure_keys_present(actor) do
57 Publisher.publish(actor, activity)
58 end
59 end
60
61 def perform(:incoming_ap_doc, params) do
62 Logger.info("Handling incoming AP activity")
63
64 params = Utils.normalize_params(params)
65
66 # NOTE: we use the actor ID to do the containment, this is fine because an
67 # actor shouldn't be acting on objects outside their own AP server.
68 with {:ok, _user} <- ap_enabled_actor(params["actor"]),
69 nil <- Activity.normalize(params["id"]),
70 :ok <- Containment.contain_origin_from_id(params["actor"], params),
71 {:ok, activity} <- Transmogrifier.handle_incoming(params) do
72 {:ok, activity}
73 else
74 %Activity{} ->
75 Logger.info("Already had #{params["id"]}")
76 :error
77
78 _e ->
79 # Just drop those for now
80 Logger.info("Unhandled activity")
81 Logger.info(Jason.encode!(params, pretty: true))
82 :error
83 end
84 end
85
86 def ap_enabled_actor(id) do
87 user = User.get_cached_by_ap_id(id)
88
89 if User.ap_enabled?(user) do
90 {:ok, user}
91 else
92 ActivityPub.make_user_from_ap_id(id)
93 end
94 end
95 end