diff options
-rw-r--r-- | app/controllers/settings/preferences_controller.rb | 8 | ||||
-rw-r--r-- | app/controllers/user_profile_css_controller.rb | 24 | ||||
-rw-r--r-- | app/controllers/user_webapp_css_controller.rb | 24 | ||||
-rw-r--r-- | app/lib/user_settings_decorator.rb | 58 | ||||
-rw-r--r-- | app/models/status.rb | 1 | ||||
-rw-r--r-- | app/models/user.rb | 3 | ||||
-rw-r--r-- | config/locales/en-MP.yml | 16 | ||||
-rw-r--r-- | config/locales/simple_form.en-MP.yml | 8 | ||||
-rw-r--r-- | config/routes.rb | 3 |
9 files changed, 142 insertions, 3 deletions
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index b189b394f..c0f54b197 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -64,6 +64,14 @@ class Settings::PreferencesController < Settings::BaseController :setting_manual_publish, :setting_style_dashed_nest, :setting_style_underline_a, + :setting_style_css_profile, + :setting_style_css_webapp, + :setting_publish_in, + :setting_unpublish_in, + :setting_unpublish_delete, + :setting_boost_every, + :setting_boost_jitter, + :setting_boost_random, notification_emails: %i(follow follow_request reblog favourite mention digest report pending_account trending_tag), interactions: %i(must_be_follower must_be_following must_be_following_dm) ) diff --git a/app/controllers/user_profile_css_controller.rb b/app/controllers/user_profile_css_controller.rb new file mode 100644 index 000000000..0a0588e88 --- /dev/null +++ b/app/controllers/user_profile_css_controller.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class UserProfileCssController < ApplicationController + skip_before_action :store_current_location + skip_before_action :require_functional! + + before_action :set_cache_headers + before_action :set_account + + def show + expires_in 3.minutes, public: true + render plain: css, content_type: 'text/css' + end + + private + + def css + @account.user&.setting_style_css_profile_errors.blank? ? (@account.user&.setting_style_css_profile || '') : '' + end + + def set_account + @account = Account.find(params[:id]) + end +end diff --git a/app/controllers/user_webapp_css_controller.rb b/app/controllers/user_webapp_css_controller.rb new file mode 100644 index 000000000..fcfbf9aed --- /dev/null +++ b/app/controllers/user_webapp_css_controller.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class UserWebappCssController < ApplicationController + skip_before_action :store_current_location + skip_before_action :require_functional! + + before_action :set_cache_headers + before_action :set_account + + def show + expires_in 3.minutes, public: true + render plain: css, content_type: 'text/css' + end + + private + + def css + @account.user&.setting_style_css_webapp_errors.blank? ? (@account.user&.setting_style_css_webapp || '') : '' + end + + def set_account + @account = Account.find(params[:id]) + end +end diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 0d6d150fa..69affa303 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true +require 'w3c_validators' + class UserSettingsDecorator + include W3CValidators + attr_reader :user, :settings def initialize(user) @@ -31,14 +35,14 @@ class UserSettingsDecorator user.settings['system_font_ui'] = system_font_ui_preference if change?('setting_system_font_ui') user.settings['system_emoji_font'] = system_emoji_font_preference if change?('setting_system_emoji_font') user.settings['noindex'] = noindex_preference if change?('setting_noindex') - user.settings['hide_followers_count']= hide_followers_count_preference if change?('setting_hide_followers_count') + user.settings['hide_followers_count'] = hide_followers_count_preference if change?('setting_hide_followers_count') user.settings['flavour'] = flavour_preference if change?('setting_flavour') user.settings['skin'] = skin_preference if change?('setting_skin') 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['advanced_layout'] = advanced_layout_preference if change?('setting_advanced_layout') - user.settings['default_content_type']= default_content_type_preference if change?('setting_default_content_type') + user.settings['default_content_type'] = default_content_type_preference if change?('setting_default_content_type') user.settings['use_blurhash'] = use_blurhash_preference if change?('setting_use_blurhash') user.settings['use_pending_items'] = use_pending_items_preference if change?('setting_use_pending_items') user.settings['trends'] = trends_preference if change?('setting_trends') @@ -47,6 +51,14 @@ class UserSettingsDecorator user.settings['manual_publish'] = manual_publish_preference if change?('setting_manual_publish') user.settings['style_dashed_nest'] = style_dashed_nest_preference if change?('setting_style_dashed_nest') user.settings['style_underline_a'] = style_underline_a_preference if change?('setting_style_underline_a') + user.settings['style_css_profile'] = style_css_profile_preference if change?('setting_style_css_profile') + user.settings['style_css_webapp'] = style_css_webapp_preference if change?('setting_style_css_webapp') + user.settings['publish_in'] = publish_in_preference if change?('setting_publish_in') + user.settings['unpublish_in'] = unpublish_in_preference if change?('setting_unpublish_in') + user.settings['unpublish_delete'] = unpublish_delete_preference if change?('setting_unpublish_delete') + user.settings['boost_every'] = boost_every_preference if change?('setting_boost_every') + user.settings['boost_jitter'] = boost_jitter_preference if change?('setting_boost_jitter') + user.settings['boost_random'] = boost_random_preference if change?('setting_boost_random') end def merged_notification_emails @@ -173,6 +185,42 @@ class UserSettingsDecorator boolean_cast_setting 'setting_style_underline_a' end + def style_css_profile_preference + css = settings['setting_style_css_profile'].to_s.strip.delete("\r").gsub(/\n\n\n+/, "\n\n") + user.settings['style_css_profile_errors'] = validate_css(css) + css + end + + def style_css_webapp_preference + css = settings['setting_style_css_webapp'].to_s.strip.delete("\r").gsub(/\n\n\n+/, "\n\n") + user.settings['style_css_webapp_errors'] = validate_css(css) + css + end + + def publish_in_preference + settings['setting_publish_in'].to_i + end + + def unpublish_in_preference + settings['setting_unpublish_in'].to_i + end + + def unpublish_delete_preference + boolean_cast_setting 'setting_unpublish_delete' + end + + def boost_every_preference + settings['setting_boost_every'].to_i + end + + def boost_jitter_preference + settings['setting_boost_jitter'].to_i + end + + def boost_random_preference + boolean_cast_setting 'setting_boost_random' + end + def boolean_cast_setting(key) ActiveModel::Type::Boolean.new.cast(settings[key]) end @@ -188,4 +236,10 @@ class UserSettingsDecorator def change?(key) !settings[key].nil? end + + def validate_css(css) + @validator ||= CSSValidator.new + results = @validator.validate_text(css) + results.errors.map { |e| e.to_s.strip } + end end diff --git a/app/models/status.rb b/app/models/status.rb index 82be3ec85..fab3644a4 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -171,6 +171,7 @@ class Status < ApplicationRecord unlisted: 3, public: 4, }.with_indifferent_access.freeze + TIMER_VALUES = [0, 5, 10, 15, 30, 60, 120, 180, 360, 720, 1440].freeze def searchable_by(preloaded = nil) ids = [] diff --git a/app/models/user.rb b/app/models/user.rb index 0ed133079..cdb32f214 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -116,7 +116,8 @@ class User < ApplicationRecord :default_content_type, :system_emoji_font, :manual_publish, :style_dashed_nest, :style_underline_a, :style_css_profile, :style_css_profile_errors, :style_css_webapp, :style_css_webapp_errors, - :publish_in, + :publish_in, :unpublish_in, :unpublish_delete, :boost_every, :boost_jitter, + :boost_random, to: :settings, prefix: :setting, allow_nil: false attr_reader :invite_code, :sign_in_token_attempt diff --git a/config/locales/en-MP.yml b/config/locales/en-MP.yml index b7532435f..be4be53e2 100644 --- a/config/locales/en-MP.yml +++ b/config/locales/en-MP.yml @@ -64,6 +64,8 @@ en-MP: desc_html: Display staff badges on profiles appearance: toot_layout: Roar layout + custom_css: Custom CSS + custom_css_error: "There are problems with the above CSS that must be fixed before it can be applied:" auth: description: prefix_invited_by_user: "@%{name} invites you to join Monsterpit!" @@ -91,6 +93,8 @@ en-MP: body: 'Your roar was boosted by %{name}:' subject: "%{name} boosted your roar" title: New roar + preferences: + advanced_publishing: Advanced publishing options remote_interaction: favourite: proceed: Proceed to admire @@ -117,6 +121,18 @@ en-MP: privacy_html: These options allow you to adjust how much information is visible on your public profile on Monsterpit. <strong>Be aware that other servers you send your roars to have their own profile systems and may not honor these options. You will need to use <em>followers-only</em> or <em>direct</em> privacy for roars you do not want displayed in other servers' public profiles.</strong> advanced_privacy: Advanced privacy advanced_privacy_html: These options can increase your privacy at the expense of compatability with other servers. <strong>They can potentially cause roars to not be delivered to some of your followers. Only enable them if you're fully aware of their side effects.</strong> + timer: + '0': Never + 5: 5 minutes + 10: 10 minutes + 15: 15 minutes + 30: 30 minutes + 60: 1 hour + 120: 2 hours + 180: 3 hours + 360: 6 hours + 720: 12 hours + 1440: 1 day user_mailer: warning: explanation: diff --git a/config/locales/simple_form.en-MP.yml b/config/locales/simple_form.en-MP.yml index 71f498c68..dc06e9fb3 100644 --- a/config/locales/simple_form.en-MP.yml +++ b/config/locales/simple_form.en-MP.yml @@ -52,9 +52,17 @@ en-MP: setting_expand_spoilers: Always expand roars marked with content warnings setting_favourite_modal: Show confirmation dialog before admiring (applies to Glitch flavour only) setting_manual_publish: Manually publish roars + setting_publish_in: Auto-publish setting_show_application: Disclose application used to send roars + setting_style_css_profile: Custom CSS for profile page + setting_style_css_webapp: Custom CSS for web interface setting_style_dashed_nest: Use dashed nest level indicators setting_style_underline_a: Underline hyperlinks + setting_boost_every: Automatically queue and space out boosts + setting_boost_jitter: Add a random delay up to + setting_boost_random: In random order + setting_unpublish_delete: Delete after unpublishing + setting_unpublish_in: Then unpublish after setting_use_pending_items: Relax mode show_replies: Show replies on profile show_unlisted: Show unlisted roars to anonymous visitors diff --git a/config/routes.rb b/config/routes.rb index fd43f9c8c..4702e766b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,6 +35,9 @@ Rails.application.routes.draw do get 'intent', to: 'intents#show' get 'custom.css', to: 'custom_css#show', as: :custom_css + get '/custom/:id/profile.css', to: 'user_profile_css#show', as: :user_profile_css + get '/custom/:id/webapp.css', to: 'user_webapp_css#show', as: :user_webapp_css + resource :instance_actor, path: 'actor', only: [:show] do resource :inbox, only: [:create], module: :activitypub end |