Expose quote_id parameter on the api

This commit is contained in:
tusooa 2023-07-12 23:47:31 -04:00
parent 875b46d97d
commit a8b2f9205d
No known key found for this signature in database
GPG key ID: 42AEC43D48433C51
3 changed files with 18 additions and 0 deletions

View file

@ -198,6 +198,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
nullable: true, nullable: true,
description: "Quoted status (if any)" description: "Quoted status (if any)"
}, },
quote_id: %Schema{
nullable: true,
allOf: [FlakeID],
description: "ID of the status being quoted, if any"
},
quote_url: %Schema{ quote_url: %Schema{
type: :string, type: :string,
format: :uri, format: :uri,

View file

@ -312,6 +312,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
# Here the implicit index of the current content is 0 # Here the implicit index of the current content is 0
chrono_order = history_len - 1 chrono_order = history_len - 1
quote_id = get_quote_id(activity)
quote_activity = get_quote(activity, opts) quote_activity = get_quote(activity, opts)
quote_post = quote_post =
@ -431,6 +433,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_id: quote_id,
quote_url: object.data["quoteUrl"], quote_url: object.data["quoteUrl"],
quote_visible: visible_for_user?(quote_activity, opts[:for]), quote_visible: visible_for_user?(quote_activity, opts[:for]),
content: %{"text/plain" => content_plaintext}, content: %{"text/plain" => content_plaintext},
@ -689,6 +692,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
end end
end end
defp get_quote_id(activity) do
case get_quote(activity, %{}) do
%Activity{id: id} -> id
_ -> nil
end
end
def render_content(%{data: %{"name" => name}} = object) when not is_nil(name) and name != "" do def render_content(%{data: %{"name" => name}} = object) when not is_nil(name) and name != "" do
url = object.data["url"] || object.data["id"] url = object.data["url"] || object.data["id"]

View file

@ -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_id: nil,
quote_url: nil, quote_url: nil,
quote_visible: false, quote_visible: false,
content: %{"text/plain" => HTML.strip_tags(object_data["content"])}, content: %{"text/plain" => HTML.strip_tags(object_data["content"])},
@ -435,10 +436,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("show.json", %{activity: quoted_quote_post}) status = StatusView.render("show.json", %{activity: quoted_quote_post})
assert status.pleroma.quote.id == to_string(quote_post.id) assert status.pleroma.quote.id == to_string(quote_post.id)
assert status.pleroma.quote_id == to_string(quote_post.id)
assert status.pleroma.quote_url == Object.normalize(quote_post).data["id"] assert status.pleroma.quote_url == Object.normalize(quote_post).data["id"]
# Quotes don't go more than one level deep # Quotes don't go more than one level deep
refute status.pleroma.quote.pleroma.quote refute status.pleroma.quote.pleroma.quote
assert status.pleroma.quote.pleroma.quote_id == to_string(post.id)
assert status.pleroma.quote.pleroma.quote_url == Object.normalize(post).data["id"] assert status.pleroma.quote.pleroma.quote_url == Object.normalize(post).data["id"]
# In an index # In an index