Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / lib / pleroma / web / activity_pub / object_validators / common_fixes.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
6 alias Pleroma.Web.ActivityPub.Utils
7
8 # based on Pleroma.Web.ActivityPub.Utils.lazy_put_objects_defaults
9 def fix_defaults(data) do
10 %{data: %{"id" => context}, id: context_id} =
11 Utils.create_context(data["context"] || data["conversation"])
12
13 data
14 |> Map.put_new("context", context)
15 |> Map.put_new("context_id", context_id)
16 end
17
18 def fix_attribution(data) do
19 data
20 |> Map.put_new("actor", data["attributedTo"])
21 end
22 end