diff options
author | Egor Kislitsyn <egor@kislitsyn.com> | 2019-02-11 13:54:21 +0700 |
---|---|---|
committer | Egor Kislitsyn <egor@kislitsyn.com> | 2019-02-11 13:54:21 +0700 |
commit | 305d2194136d4560e02c110d528164034d3727b2 (patch) | |
tree | 40510e1c4dc0140ff16e2fdc483da64c83b7077c /lib/pleroma/web/activity_pub/utils.ex | |
parent | 5b1d7c3c5672af065af503891d156b6e0cf5a8c1 (diff) | |
parent | 06c4935c11fc58f5ede18706bc46dcc502e64052 (diff) | |
download | pleroma-305d2194136d4560e02c110d528164034d3727b2.tar.gz |
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into feature/jobs
# Conflicts:
# lib/pleroma/web/federator/federator.ex
# lib/pleroma/web/websub/websub.ex
Diffstat (limited to 'lib/pleroma/web/activity_pub/utils.ex')
-rw-r--r-- | lib/pleroma/web/activity_pub/utils.ex | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 83086dcec..e34dd1d41 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -3,11 +3,19 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Utils do - alias Pleroma.{Repo, Web, Object, Activity, User, Notification} + alias Pleroma.Repo + alias Pleroma.Web + alias Pleroma.Object + alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Notification alias Pleroma.Web.Router.Helpers alias Pleroma.Web.Endpoint - alias Ecto.{Changeset, UUID} + alias Ecto.Changeset + alias Ecto.UUID + import Ecto.Query + require Logger @supported_object_types ["Article", "Note", "Video", "Page"] @@ -134,14 +142,8 @@ defmodule Pleroma.Web.ActivityPub.Utils do context = context || generate_id("contexts") changeset = Object.context_mapping(context) - case Repo.insert(changeset) do - {:ok, object} -> - object - - # This should be solved by an upsert, but it seems ecto - # has problems accessing the constraint inside the jsonb. - {:error, _} -> - Object.get_cached_by_ap_id(context) + with {:ok, object} <- Object.insert_or_get(changeset) do + object end end |