Return quote_url through the API, don't render quotes more than 1 level deep
This commit is contained in:
parent
db46abce47
commit
80ab2572a4
@ -198,6 +198,12 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
|
|||||||
nullable: true,
|
nullable: true,
|
||||||
description: "Quoted status (if any)"
|
description: "Quoted status (if any)"
|
||||||
},
|
},
|
||||||
|
quote_url: %Schema{
|
||||||
|
type: :string,
|
||||||
|
format: :uri,
|
||||||
|
nullable: true,
|
||||||
|
description: "URL of the quoted status"
|
||||||
|
},
|
||||||
local: %Schema{
|
local: %Schema{
|
||||||
type: :boolean,
|
type: :boolean,
|
||||||
description: "`true` if the post was made on the local instance"
|
description: "`true` if the post was made on the local instance"
|
||||||
|
@ -316,7 +316,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||||||
|
|
||||||
quote_post =
|
quote_post =
|
||||||
if quote_activity do
|
if quote_activity do
|
||||||
quote_rendering_opts = Map.put(opts, :activity, quote_activity)
|
quote_rendering_opts = Map.merge(opts, %{activity: quote_activity, show_quote: false})
|
||||||
render("show.json", quote_rendering_opts)
|
render("show.json", quote_rendering_opts)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
@ -431,6 +431,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||||||
context: object.data["context"],
|
context: object.data["context"],
|
||||||
in_reply_to_account_acct: reply_to_user && reply_to_user.nickname,
|
in_reply_to_account_acct: reply_to_user && reply_to_user.nickname,
|
||||||
quote: quote_post,
|
quote: quote_post,
|
||||||
|
quote_url: object.data["quoteUrl"],
|
||||||
content: %{"text/plain" => content_plaintext},
|
content: %{"text/plain" => content_plaintext},
|
||||||
spoiler_text: %{"text/plain" => summary},
|
spoiler_text: %{"text/plain" => summary},
|
||||||
expires_at: expires_at,
|
expires_at: expires_at,
|
||||||
@ -666,6 +667,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_quote(_activity, %{show_quote: false}) do
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def get_quote(activity, %{quoted_activities: quoted_activities}) do
|
def get_quote(activity, %{quoted_activities: quoted_activities}) do
|
||||||
object = Object.normalize(activity, fetch: false)
|
object = Object.normalize(activity, fetch: false)
|
||||||
quoted_activities[object.data["quoteUrl"]]
|
quoted_activities[object.data["quoteUrl"]]
|
||||||
|
@ -128,7 +128,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||||||
test "posting a quote post", %{conn: conn} do
|
test "posting a quote post", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, %{id: activity_id}} = CommonAPI.post(user, %{status: "yolo"})
|
{:ok, %{id: activity_id} = activity} = CommonAPI.post(user, %{status: "yolo"})
|
||||||
|
%{data: %{"id" => quote_url}} = Object.normalize(activity)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
@ -138,8 +139,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||||||
"quote_id" => activity_id
|
"quote_id" => activity_id
|
||||||
})
|
})
|
||||||
|
|
||||||
assert %{"id" => id, "pleroma" => %{"quote" => %{"id" => ^activity_id}}} =
|
assert %{
|
||||||
json_response_and_validate_schema(conn, 200)
|
"id" => id,
|
||||||
|
"pleroma" => %{"quote" => %{"id" => ^activity_id}, "quote_url" => ^quote_url}
|
||||||
|
} = json_response_and_validate_schema(conn, 200)
|
||||||
|
|
||||||
assert Activity.get_by_id(id)
|
assert Activity.get_by_id(id)
|
||||||
end
|
end
|
||||||
|
@ -327,6 +327,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||||||
context: object_data["context"],
|
context: object_data["context"],
|
||||||
in_reply_to_account_acct: nil,
|
in_reply_to_account_acct: nil,
|
||||||
quote: nil,
|
quote: nil,
|
||||||
|
quote_url: nil,
|
||||||
content: %{"text/plain" => HTML.strip_tags(object_data["content"])},
|
content: %{"text/plain" => HTML.strip_tags(object_data["content"])},
|
||||||
spoiler_text: %{"text/plain" => HTML.strip_tags(object_data["summary"])},
|
spoiler_text: %{"text/plain" => HTML.strip_tags(object_data["summary"])},
|
||||||
expires_at: nil,
|
expires_at: nil,
|
||||||
@ -423,6 +424,28 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||||||
assert status.in_reply_to_id == to_string(note.id)
|
assert status.in_reply_to_id == to_string(note.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "a quote post" do
|
||||||
|
post = insert(:note_activity)
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, quote_post} = CommonAPI.post(user, %{status: "he", quote_id: post.id})
|
||||||
|
{:ok, quoted_quote_post} = CommonAPI.post(user, %{status: "yo", quote_id: quote_post.id})
|
||||||
|
|
||||||
|
status = StatusView.render("show.json", %{activity: quoted_quote_post})
|
||||||
|
|
||||||
|
assert status.pleroma.quote.id == to_string(quote_post.id)
|
||||||
|
assert status.pleroma.quote_url == Object.normalize(quote_post).data["id"]
|
||||||
|
|
||||||
|
# Quotes don't go more than one level deep
|
||||||
|
refute status.pleroma.quote.pleroma.quote
|
||||||
|
assert status.pleroma.quote.pleroma.quote_url == Object.normalize(post).data["id"]
|
||||||
|
|
||||||
|
# In an index
|
||||||
|
[status] = StatusView.render("index.json", %{activities: [quoted_quote_post], as: :activity})
|
||||||
|
|
||||||
|
assert status.pleroma.quote.id == to_string(quote_post.id)
|
||||||
|
end
|
||||||
|
|
||||||
test "contains mentions" do
|
test "contains mentions" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
mentioned = insert(:user)
|
mentioned = insert(:user)
|
||||||
|
Loading…
Reference in New Issue
Block a user