From 360c51f1f52c48e52fd4fe5ccc0be9dd2b47c59f Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 2 Apr 2018 15:28:35 +0200 Subject: [PATCH] Use context_ids directly if we have them. --- lib/pleroma/web/twitter_api/twitter_api.ex | 1 + lib/pleroma/web/twitter_api/views/activity_view.ex | 11 +++-------- test/web/twitter_api/twitter_api_controller_test.exs | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 30362ef70..027b97154 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -212,6 +212,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do DateTime.utc_now() |> DateTime.to_iso8601() end + # 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 diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index dc4ca61c0..760840239 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -13,6 +13,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do import Ecto.Query + defp query_context_ids([]), do: [] defp query_context_ids(contexts) do query = from o in Object, where: fragment("(?)->>'id' = ANY(?)", o.data, ^contexts) @@ -22,6 +23,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do defp collect_context_ids(activities) do contexts = activities + |> Enum.reject(&(&1.data["context_id"])) |> Enum.map(fn(%{data: data}) -> data["context"] end) @@ -32,6 +34,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do end) end + defp get_context_id(%{data: %{"context_id" => context_id}}, _) when not is_nil(context_id), do: context_id defp get_context_id(%{data: %{"context" => nil}}, _), do: nil defp get_context_id(%{data: %{"context" => context}}, options) do cond do @@ -210,12 +213,4 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do "possibly_sensitive" => possibly_sensitive } end - - defp conversation_id(activity) do - with context when not is_nil(context) <- activity.data["context"] do - TwitterAPI.context_to_conversation_id(context) - else - _e -> nil - end - end end diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 2cbcfd086..6084381cb 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -160,15 +160,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do describe "GET /statusnet/conversation/:id.json" do test "returns the statuses in the conversation", %{conn: conn} do {:ok, _user} = UserBuilder.insert() - {:ok, _activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"}) + {:ok, activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"}) {:ok, _activity_two} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"}) {:ok, _activity_three} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"}) - {:ok, object} = Object.context_mapping("2hu") |> Repo.insert() - conn = conn - |> get("/api/statusnet/conversation/#{object.id}.json") + |> get("/api/statusnet/conversation/#{activity.data["context_id"]}.json") response = json_response(conn, 200) -- 2.45.2