From 58137b227cd282a1fa7ef8387c63165bb18711fe Mon Sep 17 00:00:00 2001 From: KMY Date: Tue, 12 Sep 2023 17:24:38 +0900 Subject: [PATCH] Connect emoji_reaction block settings and show settings --- app/models/account.rb | 28 ++++++++++++++++++++++ app/models/status.rb | 2 +- app/validators/emoji_reaction_validator.rb | 26 +------------------- config/locales/simple_form.en.yml | 6 ++--- config/locales/simple_form.ja.yml | 6 ++--- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index 62b4f9b6e5f522..8bee051b7a5348 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -370,6 +370,34 @@ def emoji_reaction_policy user.settings&.[]('emoji_reaction_policy')&.to_sym end + def show_emoji_reaction?(account) + case emoji_reaction_policy + when :block_and_hide + false + when :followees_only + account.present? && (id == account.id || following?(account)) + when :followers_only + account.present? && (id == account.id || followed_by?(account)) + when :mutuals_only + account.present? && (id == account.id || mutual?(account)) + when :outside_only + account.present? && (id == account.id || following?(account) || followed_by?(account)) + else + true + end + end + + def allow_emoji_reaction?(account) + return false if account.nil? + + case emoji_reaction_policy + when :block + false + else + show_emoji_reaction?(account) + end + end + def public_settings config = { 'noindex' => noindex?, diff --git a/app/models/status.rb b/app/models/status.rb index 3b0e0dbbb370bb..d91574947a2295 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -350,7 +350,7 @@ def add_status_referred_by_count!(diff) end def emoji_reactions_grouped_by_name(account = nil) - return [] if self.account.emoji_reaction_policy == :block_and_hide + return [] if account.present? && !self.account.show_emoji_reaction?(account) (Oj.load(status_stat&.emoji_reactions || '', mode: :strict) || []).tap do |emoji_reactions| if account.present? diff --git a/app/validators/emoji_reaction_validator.rb b/app/validators/emoji_reaction_validator.rb index ec61434489ba4f..ade43320495e35 100644 --- a/app/validators/emoji_reaction_validator.rb +++ b/app/validators/emoji_reaction_validator.rb @@ -22,30 +22,6 @@ def disabled_custom_emoji?(custom_emoji) end def deny_emoji_reactions?(emoji_reaction) - return false if emoji_reaction.status.account.user.nil? - return deny_from_all?(emoji_reaction) if emoji_reaction.status.account_id == emoji_reaction.account_id - return false if emoji_reaction.status.account.emoji_reaction_policy == :allow - - deny_from_all?(emoji_reaction) || non_outside?(emoji_reaction) || non_follower?(emoji_reaction) || non_following?(emoji_reaction) || non_mutual?(emoji_reaction) - end - - def deny_from_all?(emoji_reaction) - %i(block block_and_hide).include?(emoji_reaction.status.account.emoji_reaction_policy) - end - - def non_following?(emoji_reaction) - emoji_reaction.status.account.emoji_reaction_policy == :followees_only && !emoji_reaction.status.account.following?(emoji_reaction.account) - end - - def non_follower?(emoji_reaction) - emoji_reaction.status.account.emoji_reaction_policy == :followers_only && !emoji_reaction.account.following?(emoji_reaction.status.account) - end - - def non_outside?(emoji_reaction) - emoji_reaction.status.account.emoji_reaction_policy == :outside_only && !emoji_reaction.account.following?(emoji_reaction.status.account) && !emoji_reaction.status.account.following?(emoji_reaction.account) - end - - def non_mutual?(emoji_reaction) - emoji_reaction.status.account.emoji_reaction_policy == :mutuals_only && !emoji_reaction.status.account.mutual?(emoji_reaction.account) + !emoji_reaction.status.account.allow_emoji_reaction?(emoji_reaction.account) end end diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 6816ba7bacc5dd..626b25bb03a63d 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -244,11 +244,11 @@ en: setting_emoji_reaction_streaming_notify_impl2: Enable stamp notification compat with Nyastodon, Catstodon, glitch-soc setting_enable_emoji_reaction: Show emoji reaction on your display setting_enable_login_privacy: Enable login visibility - setting_emoji_reaction_policy: Stamp policy + setting_emoji_reaction_policy: Stamp receive/display policy setting_emoji_reaction_policy_items: allow: Allow all - block: Block all - block_and_hide: Block and hide + block: Block all but show existing reactions + block_and_hide: Block followees_only: Followings only followers_only: Followers only mutuals_only: Mutuals only diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index b8fe0d14caccfe..78d89a2a9e7f60 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -252,11 +252,11 @@ ja: setting_dtl_force_with_tag: DTL参加時の投稿設定 setting_dtl_menu: Webクライアントのメニューにディープタイムラインを追加する setting_enable_login_privacy: 公開範囲「ログインユーザーのみ」をWeb UIで選択可能にする - setting_emoji_reaction_policy: スタンプ受け入れ設定 + setting_emoji_reaction_policy: スタンプ受け入れと表示設定 setting_emoji_reaction_policy_items: allow: 全員に許可 - block: 全員禁止 - block_and_hide: 全員禁止し、既存のスタンプも非表示にする + block: 全員禁止するが、既存のスタンプは表示する + block_and_hide: 全員禁止 followees_only: フォロー中の相手のみ許可 followers_only: フォロワーのみ許可 mutuals_only: 相互のみ許可