]> cat aescling's git repositories - mastodon.git/commitdiff
Add ability to change content-type when editing a toot
authorClaire <claire.github-309c@sitedethib.com>
Thu, 10 Feb 2022 08:13:27 +0000 (09:13 +0100)
committerClaire <claire.github-309c@sitedethib.com>
Thu, 10 Feb 2022 18:10:14 +0000 (19:10 +0100)
Content-type defaults to edited toot's content-type to avoid surprising
behaviors when using clients that do not support this feature.

app/controllers/api/v1/statuses_controller.rb
app/models/status.rb
app/services/update_status_service.rb

index c928a24def8ebac494acfd47c5ef9bfcaa2d7b9e..eaac8e5636b640cad41b89ebc0389a19af95aa80 100644 (file)
@@ -66,7 +66,8 @@ class Api::V1::StatusesController < Api::BaseController
       media_ids: status_params[:media_ids],
       sensitive: status_params[:sensitive],
       spoiler_text: status_params[:spoiler_text],
-      poll: status_params[:poll]
+      poll: status_params[:poll],
+      content_type: status_params[:content_type]
     )
 
     render json: @status, serializer: REST::StatusSerializer
index e5a0beab6e21bad5ba4b259ae26ee11c5a76944e..236f95c1f7385b7ea0ddee686a2e3a0401bfbffa 100644 (file)
@@ -221,6 +221,7 @@ class Status < ApplicationRecord
       spoiler_text: spoiler_text,
       media_attachments_changed: media_attachments_changed,
       account_id: account_id || self.account_id,
+      content_type: content_type,
       created_at: at_time || edited_at
     )
   end
index 238ef0755691b3a082fbdf04084ad2fe6b9b461f..63bd27989120208c15291a48c098ce2c359ed3e5 100644 (file)
@@ -13,6 +13,7 @@ class UpdateStatusService < BaseService
   # @option options [String] :spoiler_text
   # @option options [Boolean] :sensitive
   # @option options [String] :language
+  # @option options [String] :content_type
   def call(status, account_id, options = {})
     @status                    = status
     @options                   = options
@@ -95,6 +96,7 @@ class UpdateStatusService < BaseService
     @status.spoiler_text = @options[:spoiler_text] || ''
     @status.sensitive    = @options[:sensitive] || @options[:spoiler_text].present?
     @status.language     = valid_locale_or_nil(@options[:language] || @status.language || @status.account.user&.preferred_posting_language || I18n.default_locale)
+    @status.content_type = @options[:content_type] || @status.content_type
     @status.edited_at    = Time.now.utc
 
     @status.save!