From b5ae6d4b27ac58c580d538ed92d1024d5f804405 Mon Sep 17 00:00:00 2001 From: noellabo Date: Mon, 21 Feb 2022 06:32:59 +0900 Subject: [PATCH] Add the theme option #InstanceTicker --- .../settings/preferences_controller.rb | 1 + app/helpers/application_helper.rb | 12 ++++++++++++ app/lib/user_settings_decorator.rb | 5 +++++ app/models/user.rb | 1 + app/serializers/initial_state_serializer.rb | 1 + app/views/layouts/application.html.haml | 3 +++ .../preferences/appearance/show.html.haml | 16 +++++++++++----- config/initializers/content_security_policy.rb | 2 +- config/locales/en.yml | 1 + config/locales/ja.yml | 1 + config/locales/simple_form.en.yml | 8 ++++++++ config/locales/simple_form.ja.yml | 8 ++++++++ config/settings.yml | 1 + ...0221014129_migrate_instance_ticker_theme.rb | 18 ++++++++++++++++++ db/schema.rb | 2 +- 15 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 db/post_migrate/20220221014129_migrate_instance_ticker_theme.rb diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index 97eaf6172..1b7d28911 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -78,6 +78,7 @@ class Settings::PreferencesController < Settings::BaseController :setting_hide_followers_count, :setting_disable_joke_appearance, :setting_new_features_policy, + :setting_theme_instance_ticker, notification_emails: %i(follow follow_request reblog favourite emoji_reaction mention digest report pending_account trending_tag), interactions: %i(must_be_follower must_be_following must_be_following_dm) ) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8e30d12a8..b64fc6cb2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -169,6 +169,18 @@ module ApplicationHelper text.split("\n").map { |line| '> ' + line }.join("\n") end + INSTANCE_TICKER_URL = { + 'none' => '', + 'type-0' => 'https://34.si/330/0.css', + 'type-1' => 'https://34.si/330/1.css', + 'type-2' => 'https://34.si/330/2.css', + 'type-3' => 'https://34.si/330/3.css', + }.freeze + + def instance_ticker_css + INSTANCE_TICKER_URL[current_user&.setting_theme_instance_ticker] + end + def render_initial_state state_params = { settings: { diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 5ee626a9c..f72cc0000 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -72,6 +72,7 @@ class UserSettingsDecorator user.settings['hide_followers_count'] = hide_followers_count_preference if change?('setting_hide_followers_count') 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') end def merged_notification_emails @@ -246,6 +247,10 @@ class UserSettingsDecorator settings['setting_new_features_policy'] end + def theme_instance_ticker + settings['setting_theme_instance_ticker'] + end + def boolean_cast_setting(key) ActiveModel::Type::Boolean.new.cast(settings[key]) end diff --git a/app/models/user.rb b/app/models/user.rb index fc582f888..524c2ef36 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -133,6 +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, to: :settings, prefix: :setting, allow_nil: false diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index e89aa452f..3e5b041b5 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -57,6 +57,7 @@ class InitialStateSerializer < ActiveModel::Serializer store[:show_reply_tree_button] = object.current_account.user.setting_show_reply_tree_button 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 else store[:auto_play_gif] = Setting.auto_play_gif store[:display_media] = Setting.display_media diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index d3dc0093b..c40ff86f1 100755 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -30,6 +30,9 @@ = stylesheet_link_tag '/inert.css', skip_pipeline: true, media: 'all', id: 'inert-style' + - if instance_ticker_css.present? + = stylesheet_link_tag instance_ticker_css, skip_pipeline: true, media: 'all' + - if Setting.custom_css.present? = stylesheet_link_tag custom_css_path, host: request.host, media: 'all' diff --git a/app/views/settings/preferences/appearance/show.html.haml b/app/views/settings/preferences/appearance/show.html.haml index d93abb521..5a81adcc2 100644 --- a/app/views/settings/preferences/appearance/show.html.haml +++ b/app/views/settings/preferences/appearance/show.html.haml @@ -5,16 +5,22 @@ = button_tag t('generic.save_changes'), class: 'button', form: 'edit_user' = simple_form_for current_user, url: settings_preferences_appearance_path, html: { method: :put, id: 'edit_user' } do |f| - .fields-row - .fields-group.fields-row__column.fields-row__column-6 - = f.input :locale, collection: I18n.available_locales, wrapper: :with_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, selected: I18n.locale, hint: false - .fields-group.fields-row__column.fields-row__column-6 - = f.input :setting_theme, collection: Themes.instance.names, label_method: lambda { |theme| I18n.t("themes.#{theme}", default: theme) }, wrapper: :with_label, include_blank: false, hint: false + .fields-group.fields-row__column-6 + = f.input :locale, collection: I18n.available_locales, wrapper: :with_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, selected: I18n.locale, hint: false - unless I18n.locale == :en .flash-message.translation-prompt #{t 'appearance.localization.body'} #{content_tag(:a, t('appearance.localization.guide_link_text'), href: t('appearance.localization.guide_link'), target: "_blank", rel: "noopener")} + %h4= t 'appearance.themes' + + .fields-row + .fields-row__column.fields-row__column-6 + = f.input :setting_theme, collection: Themes.instance.names, label_method: lambda { |theme| I18n.t("themes.#{theme}", default: theme) }, wrapper: :with_label, include_blank: false, hint: true + + .fields-row__column.fields-row__column-6 + = f.input :setting_theme_instance_ticker, collection: ['none', 'type-0', 'type-1', 'type-2', 'type-3'], label_method: lambda { |item| t("simple_form.hints.defaults.setting_theme_instance_ticker_#{item}") }, wrapper: :with_label, include_blank: false, hint: t('simple_form.hints.defaults.setting_theme_instance_ticker_html'), fedibird_features: true + %h4= t 'appearance.advanced_web_interface' %p.hint= t 'appearance.advanced_web_interface_hint' diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 0d5157b01..c64f78a80 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -16,7 +16,7 @@ media_host ||= host_to_url(ENV['S3_CLOUDFRONT_HOST']) media_host ||= host_to_url(ENV['S3_HOSTNAME']) if ENV['S3_ENABLED'] == 'true' media_host ||= assets_host -instance_ticker_host = 'https://inst.ance.tk' +instance_ticker_host = 'https://34.si' github_host = "https://raw.githubusercontent.com" # GitHub google_fonts_host = "https://fonts.gstatic.com" # Google Fonts diff --git a/config/locales/en.yml b/config/locales/en.yml index f0c74cff7..c27629778 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -768,6 +768,7 @@ en: guide_link: https://crowdin.com/project/mastodon guide_link_text: Everyone can contribute. sensitive_content: Sensitive content + themes: Themes toot_layout: Post layout application_mailer: notification_preferences: Change e-mail preferences diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 615accdbb..caeea7be4 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -746,6 +746,7 @@ ja: guide_link: https://ja.crowdin.com/project/mastodon guide_link_text: 誰でも参加することができます。 sensitive_content: 閲覧注意コンテンツ + themes: テーマ toot_layout: 投稿のレイアウト application_mailer: notification_preferences: メール設定の変更 diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 1f35b2610..14f6deeb2 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -78,6 +78,13 @@ en: setting_show_tab_bar_label: When adding a list etc. to the tab bar, it is recommended to display the label because it is not possible to distinguish by the icon alone setting_show_followed_by: "The color of the follow button changes according to the follow status (gray: no follow relationship, yellow: followed, blue: following, green: mutual follow)" setting_show_target: Enable the function to switch between posting target and follow / subscribe target + setting_theme: Change the site's coloring, buttons, and other design elements + setting_theme_instance_ticker_html: Display the poster's server information in the post (#InstanceTicker) + setting_theme_instance_ticker_none: None + setting_theme_instance_ticker_type-0: Type-0 (SNS LOGO) + 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_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} @@ -230,6 +237,7 @@ en: setting_show_target: Enable targeting features setting_system_font_ui: Use system's default font setting_theme: Site theme + setting_theme_instance_ticker: '#InstanceTicker' setting_trends: Show today's trends setting_unfollow_modal: Show confirmation dialog before unfollowing someone setting_unsubscribe_modal: Show confirmation dialog before unsubscribing someone diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index 833592168..4145267a7 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -78,6 +78,13 @@ ja: setting_show_tab_bar_label: リスト等をタブバーに追加する場合、アイコンだけでは区別がつかないので、ラベルを表示することをおすすめします setting_show_followed_by: フォロー状態に応じてフォローボタンの色が変わります(灰色:フォロー関係なし、黄色:フォローされている、青色:フォローしている、緑色:相互フォロー) setting_show_target: 投稿対象と、フォロー・購読の対象を切り替える機能を有効にします + setting_theme: サイトのカラーリングやボタンなどのデザインを変更します + setting_theme_instance_ticker_html: 投稿に投稿者のサーバ情報を表示します(#InstanceTicker) + setting_theme_instance_ticker_none: なし + setting_theme_instance_ticker_type-0: Type-0 (SNSロゴ) + 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_use_blurhash: ぼかしはメディアの色を元に生成されますが、細部は見えにくくなっています setting_use_pending_items: 新着があってもタイムラインを自動的にスクロールしないようにします username: あなたのユーザー名は %{domain} の中で重複していない必要があります @@ -230,6 +237,7 @@ ja: setting_show_target: ターゲット機能を有効にする setting_system_font_ui: システムのデフォルトフォントを使う setting_theme: サイトテーマ + setting_theme_instance_ticker: インスタンス・ティッカー setting_trends: 本日のトレンドタグを表示する setting_unfollow_modal: フォローを解除する前に確認ダイアログを表示する setting_unsubscribe_modal: 購読を解除する前に確認ダイアログを表示する diff --git a/config/settings.yml b/config/settings.yml index 1e0aa73cb..4634225c2 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -32,6 +32,7 @@ defaults: &defaults system_font_ui: false noindex: false theme: 'default' + theme_instance_ticker: 'none' aggregate_reblogs: true advanced_layout: false use_blurhash: true diff --git a/db/post_migrate/20220221014129_migrate_instance_ticker_theme.rb b/db/post_migrate/20220221014129_migrate_instance_ticker_theme.rb new file mode 100644 index 000000000..b6a45e27a --- /dev/null +++ b/db/post_migrate/20220221014129_migrate_instance_ticker_theme.rb @@ -0,0 +1,18 @@ +class MigrateInstanceTickerTheme < ActiveRecord::Migration[6.1] + THEME_CONVERSION = { + nil => 'default', + 'contrast' => 'contrast', + 'light' => 'mastodon-light', + }.freeze + + def up + result = ActiveRecord::Base.connection.select_all("select u.id, (regexp_matches(s.value, '--- instance-ticker-(type-[0123])'))[1] as type, (regexp_matches(s.value, '--- instance-ticker-type-[0123]-?(contrast|light)'))[1] as theme from users u join settings s on s.thing_id = u.id where s.thing_type = 'User' and var = 'theme' and value ~ '--- instance-ticker-type-[0123]-?(contrast|light)?'").each do |row| + User.find(row['id']).settings['theme_instance_ticker'] = row['type'] + User.find(row['id']).settings['theme'] = THEME_CONVERSION[row['theme']] + end + end + + def down + # nothing to do + end +end diff --git a/db/schema.rb b/db/schema.rb index 0dd8b09fb..40a56dde6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_02_02_115057) do +ActiveRecord::Schema.define(version: 2022_02_21_014129) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql"