Expose content type of status sources

This commit is contained in:
Tusooa Zhu 2022-06-04 12:56:56 -04:00
commit fe2d4778ee
No known key found for this signature in database
GPG key ID: 7B467EDE43A08224
6 changed files with 73 additions and 5 deletions

View file

@ -761,6 +761,10 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
type: :string,
description:
"Subject or summary line, below which status content is collapsed until expanded"
},
content_type: %Schema{
type: :string,
description: "The content type of the source"
}
}
}

View file

@ -224,7 +224,10 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
object =
note_data
|> 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])
%__MODULE__{draft | object: object}

View file

@ -219,7 +219,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|> maybe_add_attachments(draft.attachments, attachment_links)
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
content_type
else

View file

@ -354,7 +354,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
reblog: nil,
card: card,
content: content_html,
text: opts[:with_source] && object.data["source"],
text: opts[:with_source] && get_source_text(object.data["source"]),
created_at: created_at,
edited_at: edited_at,
reblogs_count: announcement_count,
@ -465,8 +465,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
%{
id: activity.id,
text: Map.get(object.data, "source", ""),
spoiler_text: Map.get(object.data, "summary", "")
text: get_source_text(Map.get(object.data, "source", "")),
spoiler_text: Map.get(object.data, "summary", ""),
content_type: get_source_content_type(object.data["source"])
}
end
@ -687,4 +688,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
end
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