about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-08-01 21:28:23 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:17 -0500
commit041243a3c94c0bb72e3dfccd98e16ab5de9ec2f1 (patch)
tree1bc00183df2347f24e81e83edb494680fc0955e2 /app
parent3e57d03573d267e54da66effdd502b3372f4bbd9 (diff)
[Feature, Partial] Add backend support for additional publishing and customization options
Diffstat (limited to 'app')
-rw-r--r--app/controllers/settings/preferences_controller.rb8
-rw-r--r--app/controllers/user_profile_css_controller.rb24
-rw-r--r--app/controllers/user_webapp_css_controller.rb24
-rw-r--r--app/lib/user_settings_decorator.rb58
-rw-r--r--app/models/status.rb1
-rw-r--r--app/models/user.rb3
6 files changed, 115 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