Skip to content

Commit

Permalink
Merge branch 'kb_development' into kbtopic-36-hide-followed-by
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode authored Mar 6, 2024
2 parents b0375f9 + eee13b3 commit 4d80b5b
Show file tree
Hide file tree
Showing 18 changed files with 554 additions and 400 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ GEM
rack (2.2.8.1)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-cors (2.0.1)
rack-cors (2.0.2)
rack (>= 2.0.0)
rack-oauth2 (1.21.3)
activesupport
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/filters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def set_filter
end

def resource_params
params.require(:custom_filter).permit(:title, :expires_in, :filter_action, :exclude_follows, :exclude_localusers, :with_quote, context: [], keywords_attributes: [:id, :keyword, :whole_word, :_destroy])
params.require(:custom_filter).permit(:title, :expires_in, :filter_action, :exclude_follows, :exclude_localusers, :exclude_quote, context: [], keywords_attributes: [:id, :keyword, :whole_word, :_destroy])
end

def set_body_classes
Expand Down
34 changes: 9 additions & 25 deletions app/models/account_suggestions/friends_of_friends_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,15 @@

class AccountSuggestions::FriendsOfFriendsSource < AccountSuggestions::Source
def get(account, limit: DEFAULT_LIMIT)
Account.find_by_sql([<<~SQL.squish, { id: account.id, limit: limit }]).map { |row| [row.id, key] }
WITH first_degree AS (
SELECT target_account_id
FROM follows
JOIN accounts AS target_accounts ON follows.target_account_id = target_accounts.id
WHERE account_id = :id
AND NOT target_accounts.hide_collections
)
SELECT accounts.id, COUNT(*) AS frequency
FROM accounts
JOIN follows ON follows.target_account_id = accounts.id
JOIN account_stats ON account_stats.account_id = accounts.id
LEFT OUTER JOIN follow_recommendation_mutes ON follow_recommendation_mutes.target_account_id = accounts.id AND follow_recommendation_mutes.account_id = :id
WHERE follows.account_id IN (SELECT * FROM first_degree)
AND NOT EXISTS (SELECT 1 FROM follows f WHERE f.target_account_id = follows.target_account_id AND f.account_id = :id)
AND follows.target_account_id <> :id
AND accounts.discoverable
AND accounts.suspended_at IS NULL
AND accounts.silenced_at IS NULL
AND accounts.moved_to_account_id IS NULL
AND follow_recommendation_mutes.target_account_id IS NULL
GROUP BY accounts.id, account_stats.id
ORDER BY frequency DESC, account_stats.followers_count ASC
LIMIT :limit
SQL
first_degree = account.following.where.not(hide_collections: true).select(:id).reorder(nil)
base_account_scope(account)
.joins(:account_stat)
.where(id: Follow.where(account_id: first_degree).select(:target_account_id))
.group('accounts.id, account_stats.id')
.reorder('frequency DESC, followers_count DESC')
.limit(limit)
.pluck(Arel.sql('accounts.id, COUNT(*) AS frequency'))
.map { |id, _frequency| [id, key] }
end

private
Expand Down
3 changes: 2 additions & 1 deletion app/models/account_suggestions/similar_profiles_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def get(account, limit: DEFAULT_LIMIT)
recently_followed_account_ids = account.active_relationships.recent.limit(5).pluck(:target_account_id)

if Chewy.enabled? && !recently_followed_account_ids.empty?
QueryBuilder.new(recently_followed_account_ids, account).build.limit(limit).hits.pluck('_id').map(&:to_i).zip([key].cycle)
ids_from_es = QueryBuilder.new(recently_followed_account_ids, account).build.limit(limit).hits.pluck('_id').map(&:to_i)
base_account_scope(account).where(id: ids_from_es).pluck(:id).zip([key].cycle)
else
[]
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/account_suggestions/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def get(_account, **kwargs)
def base_account_scope(account)
Account
.searchable
.where(discoverable: true)
.without_silenced
.where.not(follows_sql, id: account.id)
.where.not(follow_requests_sql, id: account.id)
.not_excluded_by_account(account)
Expand Down
8 changes: 8 additions & 0 deletions app/models/custom_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def irreversible?
hide_action?
end

def exclude_quote=(value)
self.with_quote = !ActiveModel::Type::Boolean.new.cast(value)
end

def exclude_quote
!with_quote
end

def self.cached_filters_for(account_id)
active_filters = Rails.cache.fetch("filters:v3:#{account_id}") do
filters_hash = {}
Expand Down
8 changes: 8 additions & 0 deletions app/models/user_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class KeyError < Error; end
setting :reject_send_limited_to_suspects, default: false

setting_inverse_alias :indexable, :noindex
setting_inverse_alias :show_statuses_count, :hide_statuses_count
setting_inverse_alias :show_following_count, :hide_following_count
setting_inverse_alias :show_followers_count, :hide_followers_count

namespace :web do
setting :advanced_layout, default: false
Expand Down Expand Up @@ -74,6 +77,11 @@ class KeyError < Error; end
setting :hide_emoji_reaction_unavailable_server, default: false
setting :hide_favourite_menu, default: false
setting :hide_emoji_reaction_count, default: false

setting_inverse_alias :'web.show_blocking_quote', :'web.hide_blocking_quote'
setting_inverse_alias :'web.show_emoji_reaction_count', :'web.hide_emoji_reaction_count'
setting_inverse_alias :'web.show_favourite_menu', :'web.hide_favourite_menu'
setting_inverse_alias :'web.show_recent_emojis', :'web.hide_recent_emojis'
end

namespace :notification_emails do
Expand Down
4 changes: 4 additions & 0 deletions app/models/user_settings/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ def setting(key, options = {})
@definitions[s.key] = s
end
end

def setting_inverse_alias(key, original_key)
@definitions[key] = @definitions[original_key].inverse_of(key)
end
end
2 changes: 1 addition & 1 deletion app/views/filters/_filter_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
= f.input :exclude_localusers, wrapper: :with_label, kmyblue: true, label: t('simple_form.labels.filters.options.exclude_localusers')

.fields-group
= f.input :with_quote, wrapper: :with_label, kmyblue: true, label: t('simple_form.labels.filters.options.with_quote')
= f.input :exclude_quote, wrapper: :with_label, as: :boolean, kmyblue: true, label: t('simple_form.labels.filters.options.exclude_quote')

%hr.spacer/

Expand Down
8 changes: 4 additions & 4 deletions app/views/settings/preferences/appearance/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,25 @@
%h4= t 'appearance.custom_emoji_and_emoji_reactions'

.fields-group
= ff.input :'web.hide_recent_emojis', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_hide_recent_emojis'), hint: false
= ff.input :'web.hide_recent_emojis', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_show_recent_emojis'), hint: false
- if Setting.enable_emoji_reaction
= ff.input :'web.enable_emoji_reaction', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_enable_emoji_reaction'), hint: I18n.t('simple_form.hints.defaults.setting_enable_emoji_reaction')
= ff.input :'web.show_emoji_reaction_on_timeline', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_show_emoji_reaction_on_timeline')
= ff.input :'web.hide_emoji_reaction_unavailable_server', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_hide_emoji_reaction_unavailable_server')
= ff.input :'web.hide_emoji_reaction_count', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_hide_emoji_reaction_count')
= ff.input :'web.show_emoji_reaction_count', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_show_emoji_reaction_count')

%h4= t 'appearance.saved_posts'

.fields-group
= ff.input :'web.bookmark_category_needed', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_bookmark_category_needed'), hint: I18n.t('simple_form.hints.defaults.setting_bookmark_category_needed')
= ff.input :'web.hide_favourite_menu', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_hide_favourite_menu')
= ff.input :'web.show_favourite_menu', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_show_favourite_menu')

%h4= t 'appearance.quotes'

.fields-group
= ff.input :'web.show_quote_in_home', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_show_quote_in_home'), hint: false
= ff.input :'web.show_quote_in_public', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_show_quote_in_public'), hint: false
= ff.input :'web.hide_blocking_quote', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_hide_blocking_quote'), hint: false
= ff.input :'web.show_blocking_quote', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_show_blocking_quote'), hint: false

%h4= t 'appearance.timelines'

Expand Down
6 changes: 3 additions & 3 deletions app/views/settings/privacy/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@

= f.simple_fields_for :settings, current_user.settings do |ff|
.fields-group
= ff.input :hide_statuses_count, as: :boolean, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_hide_statuses_count'), hint: false
= ff.input :hide_following_count, as: :boolean, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_hide_following_count'), hint: false
= ff.input :hide_followers_count, as: :boolean, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_hide_followers_count'), hint: false
= ff.input :show_statuses_count, as: :boolean, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_show_statuses_count'), hint: false
= ff.input :show_following_count, as: :boolean, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_show_following_count'), hint: false
= ff.input :show_followers_count, as: :boolean, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_show_followers_count'), hint: false

.fields-group
= ff.input :show_application, wrapper: :with_label
Expand Down
16 changes: 8 additions & 8 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,8 @@ en:
mutuals_only: Mutuals only
outside_only: Followings or followers only
setting_expand_spoilers: Always expand posts marked with content warnings
setting_hide_blocking_quote: Hide posts which have a quote written by the user you are blocking
setting_hide_emoji_reaction_count: Hide emoji reaction count
setting_hide_emoji_reaction_unavailable_server: Hide emoji reaction button from unavailable server
setting_hide_favourite_menu: Hide favourite menu
setting_hide_followers_count: Hide followers count
setting_hide_following_count: Hide following count
setting_hide_network: Hide your social graph
setting_hide_recent_emojis: Hide recent emojis
setting_hide_statuses_count: Hide statuses count
setting_lock_follow_from_bot: Request approval about bot follow
setting_public_post_to_unlisted: Convert public post to public unlisted if not using Web app
setting_reduce_motion: Reduce motion in animations
Expand All @@ -285,10 +278,17 @@ en:
setting_reject_unlisted_subscription: Reject sending unlisted visibility/non-public searchability posts to Misskey, Calckey
setting_reverse_search_quote: Perform word-by-word search when search keywords are not enclosed in double quotes
setting_show_application: Disclose application used to send posts
setting_show_blocking_quote: Show posts which have a quote written by the user you are blocking
setting_show_emoji_reaction_count: Show emoji reaction number
setting_show_emoji_reaction_on_timeline: Show all emoji reactions on timeline
setting_show_favourite_menu: Show favourite menu
setting_show_followers_count: Show followers count
setting_show_following_count: Show following count
setting_show_quote_in_home: Show quotes in home, list or antenna timelines
setting_show_quote_in_public: Show quotes in public timelines
setting_show_recent_emojis: Show recent emojis
setting_show_relationships: Show relationships on account page
setting_show_statuses_count: Show statuses count
setting_simple_timeline_menu: Reduce post menu on timeline
setting_single_ref_to_quote: Deliver single reference to other server as quote
setting_slip_local_emoji_reaction: Allow bypassing emoji reaction from local users
Expand Down Expand Up @@ -335,7 +335,7 @@ en:
options:
exclude_follows: Exclude following users
exclude_localusers: Exclude local users
with_quote: Also check quote or references
exclude_quote: Exclude quote or references
form_admin_settings:
activity_api_enabled: Publish aggregate statistics about user activity in the API
backups_retention_period: User archive retention period
Expand Down
16 changes: 8 additions & 8 deletions config/locales/simple_form.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,19 @@ ja:
setting_emoji_reaction_streaming_notify_impl2: Nyastodon, Catstodon, glitch-soc互換の絵文字リアクション機能を有効にする
setting_enable_emoji_reaction: 絵文字リアクション機能を使用する
setting_expand_spoilers: 閲覧注意としてマークされた投稿を常に展開する
setting_hide_blocking_quote: ブロックしたユーザーの投稿を引用した投稿を隠す
setting_hide_emoji_reaction_count: 投稿につけられた各絵文字の数を隠す
setting_hide_emoji_reaction_unavailable_server: 絵文字リアクションに対応していないと思われるサーバーの投稿から絵文字リアクション機能を隠す
setting_hide_favourite_menu: 右サイドメニューから「お気に入り」を隠す
setting_hide_followers_count: フォロワー数を隠す
setting_hide_following_count: フォロー数を隠す
setting_hide_network: 繋がりを隠す
setting_hide_recent_emojis: 絵文字ピッカーで最近使用した絵文字を隠す(絵文字デッキのみを表示する)
setting_hide_statuses_count: 投稿数を隠す
setting_lock_follow_from_bot: botからのフォローを承認制にする
setting_show_blocking_quote: ブロックしたユーザーの投稿を引用した投稿を表示する
setting_show_emoji_reaction_count: 投稿につけられた各絵文字の数を表示する
setting_show_favourite_menu: 右サイドメニューに「お気に入り」を表示する
setting_show_followers_count: フォロワー数を公開する
setting_show_following_count: フォロー数を公開する
setting_show_quote_in_home: ホーム・リスト・アンテナなどで引用を表示する
setting_show_quote_in_public: 公開タイムライン(ローカル・連合)で引用を表示する
setting_show_recent_emojis: 絵文字ピッカーで絵文字デッキと一緒に、絵文字の使用履歴も表示する
setting_show_relationships: アカウント詳細ベージで、相手からのフォロー状況を表示する
setting_show_statuses_count: 投稿数を公開する
setting_stay_privacy: 投稿時に公開範囲を保存する
setting_public_post_to_unlisted: サードパーティから公開範囲「公開」で投稿した場合、「ローカル公開」に変更する
setting_reduce_motion: アニメーションの動きを減らす
Expand Down Expand Up @@ -346,7 +346,7 @@ ja:
options:
exclude_follows: フォロー中のユーザーをフィルターの対象にしない
exclude_localusers: ローカルユーザーをフィルターの対象にしない
with_quote: 引用・参照の内容をフィルターの対象に含める
exclude_quote: 引用・参照の内容をフィルターの対象にしない
form_admin_settings:
activity_api_enabled: APIでユーザーアクティビティに関する集計統計を公開する
backups_retention_period: ユーザーアーカイブの保持期間
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mastodon/mastodon",
"license": "AGPL-3.0-or-later",
"packageManager": "[email protected].0",
"packageManager": "[email protected].1",
"engines": {
"node": ">=18"
},
Expand Down
82 changes: 82 additions & 0 deletions spec/models/account_suggestions/friends_of_friends_source_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe AccountSuggestions::FriendsOfFriendsSource do
describe '#get' do
subject { described_class.new }

let!(:bob) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:alice) { Fabricate(:account, discoverable: true, hide_collections: true) }
let!(:eve) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:mallory) { Fabricate(:account, discoverable: false, hide_collections: false) }
let!(:eugen) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:john) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:jerk) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:neil) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:larry) { Fabricate(:account, discoverable: true, hide_collections: false) }

context 'with follows and blocks' do
before do
bob.block!(jerk)
FollowRecommendationMute.create!(account: bob, target_account: neil)

# bob follows eugen, alice and larry
[eugen, alice, larry].each { |account| bob.follow!(account) }

# alice follows eve and mallory
[john, mallory].each { |account| alice.follow!(account) }

# eugen follows eve, john, jerk, larry and neil
[eve, mallory, jerk, larry, neil].each { |account| eugen.follow!(account) }
end

it 'returns eligible accounts', :aggregate_failures do
results = subject.get(bob)

# eve is returned through eugen
expect(results).to include([eve.id, :friends_of_friends])

# john is not reachable because alice hides who she follows
expect(results).to_not include([john.id, :friends_of_friends])

# mallory is not discoverable
expect(results).to_not include([mallory.id, :friends_of_friends])

# larry is not included because he's followed already
expect(results).to_not include([larry.id, :friends_of_friends])

# jerk is blocked
expect(results).to_not include([jerk.id, :friends_of_friends])

# the suggestion for neil has already been rejected
expect(results).to_not include([neil.id, :friends_of_friends])
end
end

context 'with deterministic order' do
before do
# bob follows eve and mallory
[eve, mallory].each { |account| bob.follow!(account) }

# eve follows eugen, john, and jerk
[jerk, eugen, john].each { |account| eve.follow!(account) }

# mallory follows eugen, john, and neil
[neil, eugen, john].each { |account| mallory.follow!(account) }

john.follow!(eugen)
john.follow!(neil)
end

it 'returns eligible accounts in the expected order' do
expect(subject.get(bob)).to eq [
[eugen.id, :friends_of_friends], # followed by 2 friends, 3 followers total
[john.id, :friends_of_friends], # followed by 2 friends, 2 followers total
[neil.id, :friends_of_friends], # followed by 1 friend, 2 followers total
[jerk.id, :friends_of_friends], # followed by 1 friend, 1 follower total
]
end
end
end
end
Loading

0 comments on commit 4d80b5b

Please sign in to comment.