Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: #70 DTL投稿で、公開範囲・検索許可を別々に設定 #177

Merged
merged 8 commits into from
Oct 26, 2023
8 changes: 6 additions & 2 deletions app/models/concerns/has_user_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,12 @@ def setting_link_preview
settings['link_preview']
end

def setting_dtl_force_with_tag
settings['dtl_force_with_tag']&.to_sym || :none
def setting_dtl_force_visibility
settings['dtl_force_visibility']&.to_sym || :unchange
end

def setting_dtl_force_searchability
settings['dtl_force_searchability']&.to_sym || :unchange
end

def setting_dtl_force_subscribable
Expand Down
3 changes: 2 additions & 1 deletion app/models/user_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class KeyError < Error; end
setting :emoji_reaction_streaming_notify_impl2, default: false
setting :emoji_reaction_policy, default: :allow, in: %w(allow outside_only followers_only following_only mutuals_only block)
setting :unsafe_limited_distribution, default: false
setting :dtl_force_with_tag, default: :none, in: %w(full searchability none)
setting :dtl_force_visibility, default: :unchange, in: %w(unchange public public_unlisted unlisted)
setting :dtl_force_searchability, default: :unchange, in: %w(unchange public public_unlisted)
setting :dtl_force_subscribable, default: false
setting :lock_follow_from_bot, default: false
setting :allow_quote, default: true
Expand Down
4 changes: 2 additions & 2 deletions app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def overwrite_dtl_post
return if raw_tags.exclude?(DTL_TAG)
return unless %i(public public_unlisted unlisted).include?(@visibility)

@visibility = :unlisted if @account.user&.setting_dtl_force_with_tag == :full
@searchability = :public if %i(full searchability).include?(@account.user&.setting_dtl_force_with_tag)
@visibility = @account.user&.setting_dtl_force_visibility if %i(public public_unlisted unlisted).include?(@account.user&.setting_dtl_force_visibility)
@searchability = @account.user&.setting_dtl_force_searchability if %i(public public_unlisted).include?(@account.user&.setting_dtl_force_searchability)
@dtl = true
end

Expand Down
5 changes: 4 additions & 1 deletion app/views/settings/preferences/other/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
= ff.input :'web.enable_dtl_menu', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_dtl_menu')

.fields-group
= ff.input :dtl_force_with_tag, kmyblue: true, collection: %w(full searchability none), label_method: ->(item) { safe_join([t("simple_form.labels.dtl_force_with_tag.#{item}")]) }, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', wrapper: :with_floating_label, label: I18n.t('simple_form.labels.defaults.setting_dtl_force_with_tag'), hint: I18n.t('simple_form.hints.defaults.setting_dtl_force_with_tag', tag: @dtl_tag)
= ff.input :dtl_force_visibility, kmyblue: true, collection: %w(unchange public public_unlisted unlisted), label_method: ->(item) { safe_join([t("simple_form.labels.dtl_force_visibility.#{item}")]) }, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', wrapper: :with_floating_label, label: I18n.t('simple_form.labels.defaults.setting_dtl_force_visibility'), hint: I18n.t('simple_form.hints.defaults.setting_dtl_force_visibility', tag: @dtl_tag)

.fields-group
= ff.input :dtl_force_searchability, kmyblue: true, collection: %w(unchange public public_unlisted), label_method: ->(item) { safe_join([t("simple_form.labels.dtl_force_searchability.#{item}")]) }, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', wrapper: :with_floating_label, label: I18n.t('simple_form.labels.defaults.setting_dtl_force_searchability'), hint: I18n.t('simple_form.hints.defaults.setting_dtl_force_searchability', tag: @dtl_tag)

.fields-group
= ff.input :dtl_force_subscribable, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_dtl_force_subscribable'), hint: I18n.t('simple_form.hints.defaults.setting_dtl_force_subscribable')
Expand Down
19 changes: 13 additions & 6 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ en:
setting_display_media_hide_all: Always hide media
setting_display_media_show_all: Always show media
setting_dtl_force_subscribable: Your post can be detected local user's antenna to subscribe deep timeline
setting_dtl_force_with_tag: "With using #%{tag} tag, your post settings will be changed forcibly"
setting_dtl_force_searchability: "With using #%{tag} tag, your post settings will be changed forcibly"
setting_dtl_force_visibility: "With using #%{tag} tag, your post settings will be changed forcibly"
setting_dtl_menu: Show DTL menu on web
setting_emoji_reaction_policy: Even with this setting, users on other servers are free to put their stamp on the post and share it within the same server. If you simply want to remove the stamp from your own screen, you can disable it from the appearance settings
setting_enable_emoji_reaction: If turn off, other users still can react your posts
Expand Down Expand Up @@ -248,7 +249,8 @@ en:
setting_display_media_hide_all: Hide all
setting_display_media_show_all: Show all
setting_dtl_force_subscribable: Ignore your dissubscribable setting when using the DTL tag
setting_dtl_force_with_tag: Post with DTL tag
setting_dtl_force_searchability: Post searchability
setting_dtl_force_visibility: Post visibility
setting_emoji_reaction_streaming_notify_impl2: Enable stamp notification compat with Nyastodon, Catstodon, glitch-soc
setting_enable_emoji_reaction: Use stamp function
setting_enable_login_privacy: Enable login visibility
Expand Down Expand Up @@ -299,10 +301,15 @@ en:
username: Username
username_or_email: Username or Email
whole_word: Whole word
dtl_force_with_tag:
full: Visibility is unlisted, searchability is everyone
none: No changes
searchability: Searchability is everyone
dtl_force_searchability:
public: Everyone
public_unlisted: Local and followers
unchange: Unchange
dtl_force_visibility:
public: Public
public_unlisted: Public unlisted
unchange: Unchange
unlisted: Unlisted
email_domain_block:
with_dns_records: Include MX records and IPs of the domain
emoji_reactions:
Expand Down
19 changes: 13 additions & 6 deletions config/locales/simple_form.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ ja:
setting_display_media_hide_all: メディアを常に隠す
setting_display_media_show_all: メディアを常に表示する
setting_dtl_force_subscribable: 購読拒否設定に関係なく、ディープタイムラインに向けた投稿はアンテナに掲載されます。ディープタイムラインをアンテナ経由で閲覧している人にあなたの発言が届きます
setting_dtl_force_with_tag: "ハッシュタグ #%{tag} をつけて投稿するとき、公開範囲と検索許可を強制的に置き換えるかを設定します"
setting_dtl_force_searchability: "ハッシュタグ #%{tag} をつけて投稿するとき、検索許可を強制的に置き換えるかを設定します"
setting_dtl_force_visibility: "ハッシュタグ #%{tag} をつけて投稿するとき、公開範囲を強制的に置き換えるかを設定します"
setting_emoji_reaction_policy: この設定をしても他のサーバーのユーザーはその投稿に自由にスタンプをつけ、同じサーバーの中で共有できます。単にあなた自身の画面からスタンプを除去したいだけなら、外観設定からスタンプを無効にすることができます
setting_emoji_reaction_streaming_notify_impl2: 当該サーバーの独自機能に対応したアプリを利用時に、スタンプ機能を利用できます。動作確認していないため(そもそもそのようなアプリ自体を確認できていないため)正しく動かない場合があります
setting_enable_emoji_reaction: この機能を無効にしても、他の人はあなたの投稿にスタンプをつけられます
Expand Down Expand Up @@ -262,7 +263,8 @@ ja:
setting_display_media_hide_all: 非表示
setting_display_media_show_all: 表示
setting_dtl_force_subscribable: ディープタイムライン用のハッシュタグを購読するアンテナに限り、購読拒否設定を無視する
setting_dtl_force_with_tag: DTL参加時の投稿設定
setting_dtl_force_searchability: DTL投稿の検索許可
setting_dtl_force_visibility: DTL投稿の公開範囲
setting_dtl_menu: Webクライアントのメニューにディープタイムラインを追加する
setting_enable_login_privacy: 公開範囲「ログインユーザーのみ」をWeb UIで選択可能にする
setting_emoji_reaction_policy: スタンプ受け入れと表示設定
Expand Down Expand Up @@ -315,10 +317,15 @@ ja:
username: ユーザー名
username_or_email: ユーザー名またはメールアドレス
whole_word: 単語全体にマッチ
dtl_force_with_tag:
full: 公開範囲「未収載」検索許可「誰でも」にする
none: 公開範囲も検索許可も変更しない
searchability: 検索許可を「誰でも」にする
dtl_force_searchability:
public: 誰でも
public_unlisted: ローカルとフォロワー
unchange: 変更しない
dtl_force_visibility:
public: 公開
public_unlisted: ローカル公開
unchange: 変更しない
unlisted: 非収載
email_domain_block:
with_dns_records: ドメインのMXレコードとIPアドレスを含む
emoji_reactions:
Expand Down
52 changes: 52 additions & 0 deletions db/migrate/20231023083359_convert_dtl_force_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

require Rails.root.join('lib', 'mastodon', 'migration_helpers')

class ConvertDtlForceSettings < ActiveRecord::Migration[7.0]
include Mastodon::MigrationHelpers

disable_ddl_transaction!

class User < ApplicationRecord; end

def up
safety_assured do
User.transaction do
User.find_in_batches do |users|
users.filter { |user| user.settings.present? }.each do |user|
json = Oj.load(user.settings, symbol_keys: true)
dtl_force_with_tag = json.delete(:dtl_force_with_tag)
next if dtl_force_with_tag.blank?

json[:dtl_force_visibility] = dtl_force_with_tag == 'full' ? 'unlisted' : 'unchange'
json[:dtl_force_searchability] = dtl_force_with_tag == 'none' ? 'unchange' : 'public'
user.update(settings: Oj.dump(json))
end
end
end
end
end

def down
safety_assured do
User.transaction do
User.find_in_batches do |users|
users.filter { |user| user.settings.present? }.each do |user|
json = Oj.load(user.settings, symbol_keys: true)
dtl_force_visibility = json.delete(:dtl_force_visibility)
dtl_force_searchability = json.delete(:dtl_force_searchability)
next unless dtl_force_visibility.present? || dtl_force_searchability.present?

json[:dtl_force_with_tag] = case dtl_force_visibility
when 'unlisted'
'full'
else
dtl_force_searchability == 'unchange' ? 'none' : 'searchability'
end
user.update(settings: Oj.dump(json))
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_10_22_074913) do
ActiveRecord::Schema[7.0].define(version: 2023_10_23_083359) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down
Loading