Add option for default toot content-type

This commit is contained in:
Thibaut Girka
2019-05-13 14:42:39 +02:00
committed by ThibG
parent 0be93820f3
commit a6b7c23f6f
7 changed files with 18 additions and 2 deletions

View 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)
)

View 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

View 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

View 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

View 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/