Expose content type of status sources
This commit is contained in:
parent
72ac940618
commit
fe2d4778ee
6 changed files with 73 additions and 5 deletions
|
@ -40,6 +40,10 @@ Has these additional fields under the `pleroma` object:
|
||||||
- `parent_visible`: If the parent of this post is visible to the user or not.
|
- `parent_visible`: If the parent of this post is visible to the user or not.
|
||||||
- `pinned_at`: a datetime (iso8601) when status was pinned, `null` otherwise.
|
- `pinned_at`: a datetime (iso8601) when status was pinned, `null` otherwise.
|
||||||
|
|
||||||
|
The `GET /api/v1/statuses/:id/source` endpoint additionally has the following attributes:
|
||||||
|
|
||||||
|
- `content_type`: The content type of the status source.
|
||||||
|
|
||||||
## Scheduled statuses
|
## Scheduled statuses
|
||||||
|
|
||||||
Has these additional fields in `params`:
|
Has these additional fields in `params`:
|
||||||
|
|
|
@ -761,6 +761,10 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
|
||||||
type: :string,
|
type: :string,
|
||||||
description:
|
description:
|
||||||
"Subject or summary line, below which status content is collapsed until expanded"
|
"Subject or summary line, below which status content is collapsed until expanded"
|
||||||
|
},
|
||||||
|
content_type: %Schema{
|
||||||
|
type: :string,
|
||||||
|
description: "The content type of the source"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,10 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
object =
|
object =
|
||||||
note_data
|
note_data
|
||||||
|> Map.put("emoji", emoji)
|
|> Map.put("emoji", emoji)
|
||||||
|> Map.put("source", draft.status)
|
|> Map.put("source", %{
|
||||||
|
"content" => draft.status,
|
||||||
|
"mediaType" => Utils.get_content_type(draft.params[:content_type])
|
||||||
|
})
|
||||||
|> Map.put("generator", draft.params[:generator])
|
|> Map.put("generator", draft.params[:generator])
|
||||||
|
|
||||||
%__MODULE__{draft | object: object}
|
%__MODULE__{draft | object: object}
|
||||||
|
|
|
@ -219,7 +219,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
|> maybe_add_attachments(draft.attachments, attachment_links)
|
|> maybe_add_attachments(draft.attachments, attachment_links)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_content_type(content_type) do
|
def get_content_type(content_type) do
|
||||||
if Enum.member?(Config.get([:instance, :allowed_post_formats]), content_type) do
|
if Enum.member?(Config.get([:instance, :allowed_post_formats]), content_type) do
|
||||||
content_type
|
content_type
|
||||||
else
|
else
|
||||||
|
|
|
@ -354,7 +354,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
reblog: nil,
|
reblog: nil,
|
||||||
card: card,
|
card: card,
|
||||||
content: content_html,
|
content: content_html,
|
||||||
text: opts[:with_source] && object.data["source"],
|
text: opts[:with_source] && get_source_text(object.data["source"]),
|
||||||
created_at: created_at,
|
created_at: created_at,
|
||||||
edited_at: edited_at,
|
edited_at: edited_at,
|
||||||
reblogs_count: announcement_count,
|
reblogs_count: announcement_count,
|
||||||
|
@ -465,8 +465,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
|
|
||||||
%{
|
%{
|
||||||
id: activity.id,
|
id: activity.id,
|
||||||
text: Map.get(object.data, "source", ""),
|
text: get_source_text(Map.get(object.data, "source", "")),
|
||||||
spoiler_text: Map.get(object.data, "summary", "")
|
spoiler_text: Map.get(object.data, "summary", ""),
|
||||||
|
content_type: get_source_content_type(object.data["source"])
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -687,4 +688,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp build_image_url(_, _), do: nil
|
defp build_image_url(_, _), do: nil
|
||||||
|
|
||||||
|
defp get_source_text(%{"content" => content} = _source) do
|
||||||
|
content
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_source_text(source) when is_binary(source) do
|
||||||
|
source
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_source_text(_) do
|
||||||
|
""
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_source_content_type(%{"mediaType" => type} = _source) do
|
||||||
|
type
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_source_content_type(_source) do
|
||||||
|
Utils.get_content_type(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -724,4 +724,40 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||||
status = StatusView.render("show.json", activity: edited)
|
status = StatusView.render("show.json", activity: edited)
|
||||||
assert status.edited_at
|
assert status.edited_at
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "with a source object" do
|
||||||
|
note =
|
||||||
|
insert(:note,
|
||||||
|
data: %{"source" => %{"content" => "object source", "mediaType" => "text/markdown"}}
|
||||||
|
)
|
||||||
|
|
||||||
|
activity = insert(:note_activity, note: note)
|
||||||
|
|
||||||
|
status = StatusView.render("show.json", activity: activity, with_source: true)
|
||||||
|
assert status.text == "object source"
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "source.json" do
|
||||||
|
test "with a source object, renders both source and content type" do
|
||||||
|
note =
|
||||||
|
insert(:note,
|
||||||
|
data: %{"source" => %{"content" => "object source", "mediaType" => "text/markdown"}}
|
||||||
|
)
|
||||||
|
|
||||||
|
activity = insert(:note_activity, note: note)
|
||||||
|
|
||||||
|
status = StatusView.render("source.json", activity: activity)
|
||||||
|
assert status.text == "object source"
|
||||||
|
assert status.content_type == "text/markdown"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with a source string, renders source and put text/plain as the content type" do
|
||||||
|
note = insert(:note, data: %{"source" => "string source"})
|
||||||
|
activity = insert(:note_activity, note: note)
|
||||||
|
|
||||||
|
status = StatusView.render("source.json", activity: activity)
|
||||||
|
assert status.text == "string source"
|
||||||
|
assert status.content_type == "text/plain"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue