mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-27 08:16:16 +00:00
Use context_ids directly if we have them.
This commit is contained in:
parent
bc31bee7c4
commit
360c51f1f5
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue