Add feature to reflect the theme on public pages

This commit is contained in:
noellabo 2022-08-04 15:52:07 +09:00
parent 04c3a50e3c
commit 3a9977ed5d
12 changed files with 36 additions and 7 deletions

View file

@ -135,6 +135,7 @@ class ApplicationController < ActionController::Base
end
def current_theme
return @account&.user&.setting_theme if @account&.local? && @account&.user&.setting_theme_public && Themes.instance.names.include?(@account&.user&.setting_theme)
return Setting.theme unless Themes.instance.names.include? current_user&.setting_theme
current_user.setting_theme
end

View file

@ -80,6 +80,7 @@ class Settings::PreferencesController < Settings::BaseController
:setting_disable_joke_appearance,
:setting_new_features_policy,
:setting_theme_instance_ticker,
:setting_theme_public,
:setting_hexagon_avatar,
:setting_enable_status_reference,
:setting_match_visibility_of_references,

View file

@ -118,13 +118,15 @@ module AccountsHelper
end.join("\n")
end
def account_theme_valiables
return if current_user.nil?
def account_theme_valiables(account)
user = account&.user&.setting_theme_public && account&.user || current_user
return if user.nil?
":root {
--content-font-size: #{h(current_user.setting_content_font_size)}px;
--info-font-size: #{h(current_user.setting_info_font_size)}px;
--content-emoji-reaction-size: #{h(current_user.setting_content_emoji_reaction_size)}px;
--content-font-size: #{h(user.setting_content_font_size)}px;
--info-font-size: #{h(user.setting_info_font_size)}px;
--content-emoji-reaction-size: #{h(user.setting_content_emoji_reaction_size)}px;
}"
end

View file

@ -77,6 +77,7 @@ class UserSettingsDecorator
user.settings['disable_joke_appearance'] = disable_joke_appearance_preference if change?('setting_disable_joke_appearance')
user.settings['new_features_policy'] = new_features_policy if change?('setting_new_features_policy')
user.settings['theme_instance_ticker'] = theme_instance_ticker if change?('setting_theme_instance_ticker')
user.settings['theme_public'] = theme_public if change?('setting_theme_public')
user.settings['enable_status_reference'] = enable_status_reference_preference if change?('setting_enable_status_reference')
user.settings['match_visibility_of_references'] = match_visibility_of_references_preference if change?('setting_match_visibility_of_references')
user.settings['hexagon_avatar'] = hexagon_avatar_preference if change?('setting_hexagon_avatar')
@ -280,6 +281,10 @@ end
settings['setting_theme_instance_ticker']
end
def theme_public
boolean_cast_setting 'setting_theme_public'
end
def hexagon_avatar_preference
boolean_cast_setting 'setting_hexagon_avatar'
end

View file

@ -133,7 +133,7 @@ class User < ApplicationRecord
:show_reply_tree_button,
:hide_statuses_count, :hide_following_count, :hide_followers_count, :disable_joke_appearance,
:new_features_policy,
:theme_instance_ticker,
:theme_instance_ticker, :theme_public,
:enable_status_reference, :match_visibility_of_references,
:post_reference_modal, :add_reference_modal, :unselect_reference_modal,
:hexagon_avatar, :enable_empty_column,

View file

@ -59,6 +59,7 @@ class InitialStateSerializer < ActiveModel::Serializer
store[:disable_joke_appearance] = object.current_account.user.setting_disable_joke_appearance
store[:new_features_policy] = object.current_account.user.setting_new_features_policy
store[:theme_instance_ticker] = object.current_account.user.setting_theme_instance_ticker
store[:theme_public] = object.current_account.user.setting_theme_public
store[:enable_status_reference] = object.current_account.user.setting_enable_status_reference
store[:match_visibility_of_references] = object.current_account.user.setting_match_visibility_of_references
store[:post_reference_modal] = object.current_account.user.setting_post_reference_modal

View file

@ -38,7 +38,7 @@
%style{ nonce: request.content_security_policy_nonce }
!= account_cat_styles
!= account_theme_valiables
!= account_theme_valiables(@account)
= yield :header_tags

View file

@ -49,6 +49,9 @@
-# = f.input :setting_mobile_content_font_size, as: :range, input_html: { min: 10, max: 24, list: 'content_font_size_label' }, wrapper: :with_label, hint: false, fedibird_features: true
-# = f.input :setting_mobile_content_emoji_reaction_size, as: :range, input_html: { min: 10, max: 48 }, wrapper: :with_label, false: true, fedibird_features: true
.fields-group
= f.input :setting_theme_public, as: :boolean, wrapper: :with_label, hint: true, fedibird_features: true
%h4= t 'appearance.advanced_web_interface'
%p.hint= t 'appearance.advanced_web_interface_hint'

View file

@ -93,6 +93,7 @@ en:
setting_theme_instance_ticker_type-1: Type-1 (Favicon)
setting_theme_instance_ticker_type-2: Type-2 (Favicon + BG White)
setting_theme_instance_ticker_type-3: Type-3 (Favicon + BG Black)
setting_theme_public: Your public pages will reflect the theme currently in use
setting_use_blurhash: Gradients are based on the colors of the hidden visuals but obfuscate any details
setting_use_pending_items: Hide timeline updates behind a click instead of automatically scrolling the feed
username: Your username will be unique on %{domain}
@ -260,6 +261,7 @@ en:
setting_system_font_ui: Use system's default font
setting_theme: Site theme
setting_theme_instance_ticker: '#InstanceTicker'
setting_theme_public: Reflecting the theme on the public page
setting_trends: Show today's trends
setting_unfollow_modal: Show confirmation dialog before unfollowing someone
setting_unsubscribe_modal: Show confirmation dialog before unsubscribing someone

View file

@ -93,6 +93,7 @@ ja:
setting_theme_instance_ticker_type-1: Type-1 (Favicon)
setting_theme_instance_ticker_type-2: Type-2 (Favicon + 白背景)
setting_theme_instance_ticker_type-3: Type-3 (Favicon + 黒背景)
setting_theme_public: あなたの公開ページに現在使用中のテーマを反映します
setting_use_blurhash: ぼかしはメディアの色を元に生成されますが、細部は見えにくくなっています
setting_use_pending_items: 新着があってもタイムラインを自動的にスクロールしないようにします
username: あなたのユーザー名は %{domain} の中で重複していない必要があります
@ -260,6 +261,7 @@ ja:
setting_system_font_ui: システムのデフォルトフォントを使う
setting_theme: サイトテーマ
setting_theme_instance_ticker: インスタンス・ティッカー
setting_theme_public: 公開ページにテーマを反映する
setting_trends: 本日のトレンドタグを表示する
setting_unfollow_modal: フォローを解除する前に確認ダイアログを表示する
setting_unsubscribe_modal: 購読を解除する前に確認ダイアログを表示する

View file

@ -34,6 +34,7 @@ defaults: &defaults
noindex: false
theme: 'default'
theme_instance_ticker: 'none'
theme_public: true
aggregate_reblogs: true
advanced_layout: false
use_blurhash: true

View file

@ -0,0 +1,11 @@
class ConservativeSettingToThemePublic < ActiveRecord::Migration[6.1]
def up
User.joins('join settings on users.id = settings.thing_id').where(settings: {thing_type: :User, var: :new_features_policy, value: "--- conservative\n"}).find_each do |user|
user.settings['theme_public'] = false
end
end
def down
# nothing to do
end
end