Skip to content

Commit

Permalink
Connect emoji_reaction block settings and show settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Sep 12, 2023
1 parent 4863ac5 commit 58137b2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
28 changes: 28 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down
2 changes: 1 addition & 1 deletion app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
26 changes: 1 addition & 25 deletions app/validators/emoji_reaction_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions config/locales/simple_form.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 相互のみ許可
Expand Down

0 comments on commit 58137b2

Please sign in to comment.