Implement viewing source
This commit is contained in:
parent
c004eb0fa2
commit
393b508846
|
@ -456,6 +456,20 @@ def show_history_operation do
|
|||
end
|
||||
|
||||
def show_source_operation do
|
||||
%Operation{
|
||||
tags: ["Retrieve status source"],
|
||||
summary: "Status source",
|
||||
description: "View source of a status",
|
||||
operationId: "StatusController.show_source",
|
||||
security: [%{"oAuth" => ["read:statuses"]}],
|
||||
parameters: [
|
||||
id_param()
|
||||
],
|
||||
responses: %{
|
||||
200 => status_source_response(),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def update_operation do
|
||||
|
@ -661,6 +675,28 @@ defp status_history_response do
|
|||
)
|
||||
end
|
||||
|
||||
defp status_source_response do
|
||||
Operation.response(
|
||||
"Status Source",
|
||||
"application/json",
|
||||
%Schema{
|
||||
type: :object,
|
||||
properties: %{
|
||||
id: FlakeID,
|
||||
text: %Schema{
|
||||
type: :string,
|
||||
description: "Raw source of status content"
|
||||
},
|
||||
spoiler_text: %Schema{
|
||||
type: :string,
|
||||
description:
|
||||
"Subject or summary line, below which status content is collapsed until expanded"
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
defp context do
|
||||
%Schema{
|
||||
title: "StatusContext",
|
||||
|
|
|
@ -210,7 +210,16 @@ def show_history(%{assigns: %{user: user}} = conn, %{id: id} = params) do
|
|||
end
|
||||
|
||||
@doc "GET /api/v1/statuses/:id/source"
|
||||
def show_source(%{assigns: %{user: _user}} = _conn, %{id: _id} = _params) do
|
||||
def show_source(%{assigns: %{user: user}} = conn, %{id: id} = _params) do
|
||||
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
|
||||
true <- Visibility.visible_for_user?(activity, user) do
|
||||
try_render(conn, "source.json",
|
||||
activity: activity,
|
||||
for: user
|
||||
)
|
||||
else
|
||||
_ -> {:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
@doc "PUT /api/v1/statuses/:id"
|
||||
|
|
|
@ -449,6 +449,16 @@ def render(
|
|||
}
|
||||
end
|
||||
|
||||
def render("source.json", %{activity: %{data: %{"object" => _object}} = activity} = _opts) do
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
%{
|
||||
id: activity.id,
|
||||
text: Map.get(object.data, "source", ""),
|
||||
spoiler_text: Map.get(object.data, "summary", "")
|
||||
}
|
||||
end
|
||||
|
||||
def render("card.json", %{rich_media: rich_media, page_url: page_url}) do
|
||||
page_url_data = URI.parse(page_url)
|
||||
|
||||
|
|
|
@ -2036,4 +2036,22 @@ test "edited post", %{conn: conn} do
|
|||
json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get status source" do
|
||||
setup do
|
||||
oauth_access(["read:statuses"])
|
||||
end
|
||||
|
||||
test "it returns the source", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "mew mew #abc", spoiler_text: "#def"})
|
||||
|
||||
conn = get(conn, "/api/v1/statuses/#{activity.id}/source")
|
||||
|
||||
id = activity.id
|
||||
|
||||
assert %{"id" => ^id, "text" => "mew mew #abc", "spoiler_text" => "#def"} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue