From 212080c3e820120e2211605d4b14b0f5a03ec54a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sun, 13 Mar 2022 09:34:51 +0100 Subject: [PATCH] Store status content mime type in the object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- lib/pleroma/constants.ex | 3 ++- lib/pleroma/web/api_spec/schemas/status.ex | 5 +++++ lib/pleroma/web/common_api/activity_draft.ex | 1 + lib/pleroma/web/mastodon_api/views/status_view.ex | 3 ++- test/pleroma/web/mastodon_api/views/status_view_test.exs | 3 ++- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/constants.ex b/lib/pleroma/constants.ex index 7fbe9de824..e3a9a107bb 100644 --- a/lib/pleroma/constants.ex +++ b/lib/pleroma/constants.ex @@ -21,7 +21,8 @@ defmodule Pleroma.Constants do "pleroma_internal", "generator", "assigned_account", - "rules" + "rules", + "content_type" ] ) diff --git a/lib/pleroma/web/api_spec/schemas/status.ex b/lib/pleroma/web/api_spec/schemas/status.ex index 61e43f7a1c..fbc688d053 100644 --- a/lib/pleroma/web/api_spec/schemas/status.ex +++ b/lib/pleroma/web/api_spec/schemas/status.ex @@ -216,6 +216,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do nullable: true, description: "A datetime (ISO 8601) that states when the post was pinned or `null` if the post is not pinned" + }, + content_type: %Schema{ + type: :string, + nullable: true, + description: "A MIME type of the status" } } }, diff --git a/lib/pleroma/web/common_api/activity_draft.ex b/lib/pleroma/web/common_api/activity_draft.ex index 5d5ea78be3..074f68f009 100644 --- a/lib/pleroma/web/common_api/activity_draft.ex +++ b/lib/pleroma/web/common_api/activity_draft.ex @@ -260,6 +260,7 @@ defp object(draft) do |> Map.put("emoji", emoji) |> Map.put("source", draft.status) |> Map.put("generator", draft.params[:generator]) + |> Map.put("content_type", draft.params[:content_type]) %__MODULE__{draft | object: object} end diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 973b3f25b1..1fd6f8885e 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -415,7 +415,8 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} thread_muted: thread_muted?, emoji_reactions: emoji_reactions, parent_visible: visible_for_user?(reply_to, opts[:for]), - pinned_at: pinned_at + pinned_at: pinned_at, + content_type: opts[:with_source] && (object.data["content_type"] || "text/plain") } } end diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index a354a63e5e..97e224b46a 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -291,7 +291,8 @@ test "a note activity" do thread_muted: false, emoji_reactions: [], parent_visible: false, - pinned_at: nil + pinned_at: nil, + content_type: nil } }