diff options
author | kaniini <nenolod@gmail.com> | 2019-03-22 00:25:35 +0000 |
---|---|---|
committer | kaniini <nenolod@gmail.com> | 2019-03-22 00:25:35 +0000 |
commit | b548181b52c4397d5034cfd95b2ef7e05c9c9c22 (patch) | |
tree | a847bb70d52da43b2f0cca45f7ea49cb4e664c5a /lib/pleroma/web/common_api/utils.ex | |
parent | bf8b29e080a6a8a369abb53a26229bb0544de1c0 (diff) | |
parent | a223e65f35da158ef79f05f65316920dcecaa54b (diff) | |
download | pleroma-b548181b52c4397d5034cfd95b2ef7e05c9c9c22.tar.gz |
Merge branch 'feature/mastoapi-ext-conversation-id' into 'develop'
Mastodon API: add conversation_id extension
See merge request pleroma/pleroma!961
Diffstat (limited to 'lib/pleroma/web/common_api/utils.ex')
-rw-r--r-- | lib/pleroma/web/common_api/utils.ex | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index b7513ef28..fcdfea8e1 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -344,4 +344,33 @@ defmodule Pleroma.Web.CommonAPI.Utils do end def get_report_statuses(_, _), do: {:ok, nil} + + # DEPRECATED mostly, context objects are now created at insertion time. + def context_to_conversation_id(context) do + with %Object{id: id} <- Object.get_cached_by_ap_id(context) do + id + else + _e -> + changeset = Object.context_mapping(context) + + case Repo.insert(changeset) do + {:ok, %{id: id}} -> + id + + # 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).id + end + end + end + + def conversation_id_to_context(id) do + with %Object{data: %{"id" => context}} <- Repo.get(Object, id) do + context + else + _e -> + {:error, "No such conversation"} + end + end end |