]> cat aescling's git repositories - mastodon.git/commitdiff
Add option for default toot content-type
authorThibaut Girka <thib@sitedethib.com>
Mon, 13 May 2019 12:42:39 +0000 (14:42 +0200)
committerThibG <thib@sitedethib.com>
Fri, 17 May 2019 21:51:14 +0000 (23:51 +0200)
app/controllers/settings/preferences_controller.rb
app/lib/user_settings_decorator.rb
app/models/user.rb
app/services/post_status_service.rb
app/views/settings/preferences/show.html.haml
config/locales/simple_form.en.yml
config/settings.yml

index eb7a0eb4aa1b0ed45ed9556332458c8884b5e6f2..3d98d583c888bee9a6376b91ce59ef1d1c1ddb4e 100644 (file)
@@ -46,6 +46,7 @@ class Settings::PreferencesController < Settings::BaseController
       :setting_hide_followers_count,
       :setting_aggregate_reblogs,
       :setting_show_application,
+      :setting_default_content_type,
       notification_emails: %i(follow follow_request reblog favourite mention digest report pending_account),
       interactions: %i(must_be_follower must_be_following)
     )
index 367ba9a83b67fb7e49b2262b553bdd68ece1a842..802ca71fe1c4b2e773a751920019553eeb89d894 100644 (file)
@@ -36,6 +36,7 @@ class UserSettingsDecorator
     user.settings['hide_network']        = hide_network_preference if change?('setting_hide_network')
     user.settings['aggregate_reblogs']   = aggregate_reblogs_preference if change?('setting_aggregate_reblogs')
     user.settings['show_application']    = show_application_preference if change?('setting_show_application')
+    user.settings['default_content_type']= default_content_type_preference if change?('setting_default_content_type')
   end
 
   def merged_notification_emails
@@ -122,6 +123,10 @@ class UserSettingsDecorator
     boolean_cast_setting 'setting_aggregate_reblogs'
   end
 
+  def default_content_type_preference
+    settings['setting_default_content_type']
+  end
+
   def boolean_cast_setting(key)
     ActiveModel::Type::Boolean.new.cast(settings[key])
   end
index 8985ebf53e41e3ca6d6d33bdf3aa7b0c49f3b9c1..a245d3eb251f0933404ef612f99a279438fef30c 100644 (file)
@@ -104,7 +104,7 @@ class User < ApplicationRecord
 
   delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :favourite_modal, :delete_modal,
            :reduce_motion, :system_font_ui, :noindex, :flavour, :skin, :display_media, :hide_network, :hide_followers_count,
-           :expand_spoilers, :default_language, :aggregate_reblogs, :show_application, to: :settings, prefix: :setting, allow_nil: false
+           :expand_spoilers, :default_language, :aggregate_reblogs, :show_application, :default_content_type, to: :settings, prefix: :setting, allow_nil: false
 
   attr_reader :invite_code
   attr_writer :external
index 25aa6629c7762c85e41ebc97c073954180557a42..c2584e090c3ac0b0a76a8888fbcd34a150729a4e 100644 (file)
@@ -168,7 +168,7 @@ class PostStatusService < BaseService
       visibility: @visibility,
       language: language_from_option(@options[:language]) || @account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(@text, @account),
       application: @options[:application],
-      content_type: @options[:content_type],
+      content_type: @options[:content_type] || @account.user&.setting_default_content_type,
     }.compact
   end
 
index a50f3351706bcdc6d7eb993802dd9e78b61fd18e..cd5bf9be244ccb7868063b048e39756e9421f2eb 100644 (file)
@@ -25,6 +25,8 @@
   .fields-group
     = f.input :setting_default_privacy, collection: Status.selectable_visibilities, wrapper: :with_floating_label, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), content_tag(:span, I18n.t("statuses.visibilities.#{visibility}_long"), class: 'hint')]) }, required: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li'
 
+    = f.input :setting_default_content_type, collection: ['text/plain', 'text/markdown', 'text/html'], wrapper: :with_label, include_blank: false, label_method: lambda { |item| safe_join([t("simple_form.labels.defaults.setting_default_content_type_#{item.split('/')[1]}"), content_tag(:span, t("simple_form.hints.defaults.setting_default_content_type_#{item.split('/')[1]}"), class: 'hint')]) }, required: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li'
+
     = f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label
 
   %hr#settings_other/
index ba0e403e4578b093957d7bcfe1d8685f4f42827e..6fad7f73a281bcb9f41b49cea5b815744f99e308 100644 (file)
@@ -27,6 +27,9 @@ en:
         phrase: Will be matched regardless of casing in text or content warning of a toot
         scopes: Which APIs the application will be allowed to access. If you select a top-level scope, you don't need to select individual ones.
         setting_aggregate_reblogs: Do not show new boosts for toots that have been recently boosted (only affects newly-received boosts)
+        setting_default_content_type_html: When writing toots, assume they are written in raw HTML, unless specified otherwise
+        setting_default_content_type_markdown: When writing toots, assume they are using Markdown for rich text formatting, unless specified otherwise
+        setting_default_content_type_plain: When writing toots, assume they are plain text with no special formatting, unless specified otherwise (default Mastodon behavior)
         setting_default_language: The language of your toots can be detected automatically, but it's not always accurate
         setting_display_media_default: Hide media marked as sensitive
         setting_display_media_hide_all: Always hide all media
@@ -93,6 +96,10 @@ en:
         setting_aggregate_reblogs: Group boosts in timelines
         setting_auto_play_gif: Auto-play animated GIFs
         setting_boost_modal: Show confirmation dialog before boosting
+        setting_default_content_type: Default format for toots
+        setting_default_content_type_html: HTML
+        setting_default_content_type_markdown: Markdown
+        setting_default_content_type_plain: Plain text
         setting_default_language: Posting language
         setting_default_privacy: Post privacy
         setting_default_sensitive: Always mark media as sensitive
index c3aeab5512799ef45d8b49e0244fa9bcd596fccc..69996af25dbf8c2e3e6bfe6bd8f9fea8d6cbe5e5 100644 (file)
@@ -64,6 +64,7 @@ defaults: &defaults
   show_known_fediverse_at_about_page: true
   show_reblogs_in_public_timelines: false
   show_replies_in_public_timelines: false
+  default_content_type: 'text/plain'
 
 development:
   <<: *defaults