Add /api/v1/accounts/familiar_followers
to REST API (#17700)
* Add `/api/v1/accounts/familiar_followers` to REST API * Change hide network preference to be stored consistently for local and remote accounts * Add dummy classes to migration * Apply suggestions from code review Co-authored-by: Claire <claire.github-309c@sitedethib.com> Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
c439e13e12
commit
edf09ec747
22 changed files with 169 additions and 32 deletions
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Api::V1::Accounts::FamiliarFollowersController < Api::BaseController
|
||||
before_action -> { doorkeeper_authorize! :read, :'read:follows' }
|
||||
before_action :require_user!
|
||||
before_action :set_accounts
|
||||
|
||||
def index
|
||||
render json: familiar_followers.accounts, each_serializer: REST::FamiliarFollowersSerializer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_accounts
|
||||
@accounts = Account.without_suspended.where(id: account_ids).select('id, hide_collections').index_by(&:id).values_at(*account_ids).compact
|
||||
end
|
||||
|
||||
def familiar_followers
|
||||
FamiliarFollowersPresenter.new(@accounts, current_user.account_id)
|
||||
end
|
||||
|
||||
def account_ids
|
||||
Array(params[:id]).map(&:to_i)
|
||||
end
|
||||
end
|
|
@ -15,13 +15,13 @@ class FollowerAccountsController < ApplicationController
|
|||
format.html do
|
||||
expires_in 0, public: true unless user_signed_in?
|
||||
|
||||
next if @account.user_hides_network?
|
||||
next if @account.hide_collections?
|
||||
|
||||
follows
|
||||
end
|
||||
|
||||
format.json do
|
||||
raise Mastodon::NotPermittedError if page_requested? && @account.user_hides_network?
|
||||
raise Mastodon::NotPermittedError if page_requested? && @account.hide_collections?
|
||||
|
||||
expires_in(page_requested? ? 0 : 3.minutes, public: public_fetch_mode?)
|
||||
|
||||
|
@ -82,7 +82,7 @@ class FollowerAccountsController < ApplicationController
|
|||
end
|
||||
|
||||
def restrict_fields_to
|
||||
if page_requested? || !@account.user_hides_network?
|
||||
if page_requested? || !@account.hide_collections?
|
||||
# Return all fields
|
||||
else
|
||||
%i(id type total_items)
|
||||
|
|
|
@ -15,13 +15,13 @@ class FollowingAccountsController < ApplicationController
|
|||
format.html do
|
||||
expires_in 0, public: true unless user_signed_in?
|
||||
|
||||
next if @account.user_hides_network?
|
||||
next if @account.hide_collections?
|
||||
|
||||
follows
|
||||
end
|
||||
|
||||
format.json do
|
||||
raise Mastodon::NotPermittedError if page_requested? && @account.user_hides_network?
|
||||
raise Mastodon::NotPermittedError if page_requested? && @account.hide_collections?
|
||||
|
||||
expires_in(page_requested? ? 0 : 3.minutes, public: public_fetch_mode?)
|
||||
|
||||
|
@ -82,7 +82,7 @@ class FollowingAccountsController < ApplicationController
|
|||
end
|
||||
|
||||
def restrict_fields_to
|
||||
if page_requested? || !@account.user_hides_network?
|
||||
if page_requested? || !@account.hide_collections?
|
||||
# Return all fields
|
||||
else
|
||||
%i(id type total_items)
|
||||
|
|
|
@ -47,7 +47,6 @@ class Settings::PreferencesController < Settings::BaseController
|
|||
:setting_system_font_ui,
|
||||
:setting_noindex,
|
||||
:setting_theme,
|
||||
:setting_hide_network,
|
||||
:setting_aggregate_reblogs,
|
||||
:setting_show_application,
|
||||
:setting_advanced_layout,
|
||||
|
|
|
@ -20,7 +20,7 @@ class Settings::ProfilesController < Settings::BaseController
|
|||
private
|
||||
|
||||
def account_params
|
||||
params.require(:account).permit(:display_name, :note, :avatar, :header, :locked, :bot, :discoverable, fields_attributes: [:name, :value])
|
||||
params.require(:account).permit(:display_name, :note, :avatar, :header, :locked, :bot, :discoverable, :hide_collections, fields_attributes: [:name, :value])
|
||||
end
|
||||
|
||||
def set_account
|
||||
|
|
|
@ -31,7 +31,6 @@ class UserSettingsDecorator
|
|||
user.settings['system_font_ui'] = system_font_ui_preference if change?('setting_system_font_ui')
|
||||
user.settings['noindex'] = noindex_preference if change?('setting_noindex')
|
||||
user.settings['theme'] = theme_preference if change?('setting_theme')
|
||||
user.settings['hide_network'] = hide_network_preference if change?('setting_hide_network')
|
||||
user.settings['aggregate_reblogs'] = aggregate_reblogs_preference if change?('setting_aggregate_reblogs')
|
||||
user.settings['show_application'] = show_application_preference if change?('setting_show_application')
|
||||
user.settings['advanced_layout'] = advanced_layout_preference if change?('setting_advanced_layout')
|
||||
|
@ -97,10 +96,6 @@ class UserSettingsDecorator
|
|||
boolean_cast_setting 'setting_noindex'
|
||||
end
|
||||
|
||||
def hide_network_preference
|
||||
boolean_cast_setting 'setting_hide_network'
|
||||
end
|
||||
|
||||
def show_application_preference
|
||||
boolean_cast_setting 'setting_show_application'
|
||||
end
|
||||
|
|
|
@ -349,11 +349,11 @@ class Account < ApplicationRecord
|
|||
end
|
||||
|
||||
def hides_followers?
|
||||
hide_collections? || user_hides_network?
|
||||
hide_collections?
|
||||
end
|
||||
|
||||
def hides_following?
|
||||
hide_collections? || user_hides_network?
|
||||
hide_collections?
|
||||
end
|
||||
|
||||
def object_type
|
||||
|
|
|
@ -126,7 +126,7 @@ class User < ApplicationRecord
|
|||
has_many :session_activations, dependent: :destroy
|
||||
|
||||
delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal,
|
||||
:reduce_motion, :system_font_ui, :noindex, :theme, :display_media, :hide_network,
|
||||
:reduce_motion, :system_font_ui, :noindex, :theme, :display_media,
|
||||
:expand_spoilers, :default_language, :aggregate_reblogs, :show_application,
|
||||
:advanced_layout, :use_blurhash, :use_pending_items, :trends, :crop_images,
|
||||
:disable_swiping,
|
||||
|
@ -273,10 +273,6 @@ class User < ApplicationRecord
|
|||
settings.notification_emails['trending_tag']
|
||||
end
|
||||
|
||||
def hides_network?
|
||||
@hides_network ||= settings.hide_network
|
||||
end
|
||||
|
||||
def aggregates_reblogs?
|
||||
@aggregates_reblogs ||= settings.aggregate_reblogs
|
||||
end
|
||||
|
|
17
app/presenters/familiar_followers_presenter.rb
Normal file
17
app/presenters/familiar_followers_presenter.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class FamiliarFollowersPresenter
|
||||
class Result < ActiveModelSerializers::Model
|
||||
attributes :id, :accounts
|
||||
end
|
||||
|
||||
def initialize(accounts, current_account_id)
|
||||
@accounts = accounts
|
||||
@current_account_id = current_account_id
|
||||
end
|
||||
|
||||
def accounts
|
||||
map = Follow.includes(account: :account_stat).where(target_account_id: @accounts.map(&:id)).where(account_id: Follow.where(account_id: @current_account_id).joins(:target_account).merge(Account.where(hide_collections: [nil, false])).select(:target_account_id)).group_by(&:target_account_id)
|
||||
@accounts.map { |account| Result.new(id: account.id, accounts: (account.hide_collections? ? [] : (map[account.id] || [])).map(&:account)) }
|
||||
end
|
||||
end
|
11
app/serializers/rest/familiar_followers_serializer.rb
Normal file
11
app/serializers/rest/familiar_followers_serializer.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class REST::FamiliarFollowersSerializer < ActiveModel::Serializer
|
||||
attribute :id
|
||||
|
||||
has_many :accounts, serializer: REST::AccountSerializer
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
end
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
= render 'accounts/header', account: @account
|
||||
|
||||
- if @account.user_hides_network?
|
||||
- if @account.hide_collections?
|
||||
.nothing-here= t('accounts.network_hidden')
|
||||
- elsif user_signed_in? && @account.blocking?(current_account)
|
||||
.nothing-here= t('accounts.unavailable')
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
= render 'accounts/header', account: @account
|
||||
|
||||
- if @account.user_hides_network?
|
||||
- if @account.hide_collections?
|
||||
.nothing-here= t('accounts.network_hidden')
|
||||
- elsif user_signed_in? && @account.blocking?(current_account)
|
||||
.nothing-here= t('accounts.unavailable')
|
||||
|
|
|
@ -10,9 +10,6 @@
|
|||
.fields-group
|
||||
= f.input :setting_noindex, as: :boolean, wrapper: :with_label
|
||||
|
||||
.fields-group
|
||||
= f.input :setting_hide_network, as: :boolean, wrapper: :with_label
|
||||
|
||||
.fields-group
|
||||
= f.input :setting_aggregate_reblogs, as: :boolean, wrapper: :with_label, recommended: true
|
||||
|
||||
|
|
|
@ -30,7 +30,10 @@
|
|||
= f.input :bot, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.bot')
|
||||
|
||||
.fields-group
|
||||
= f.input :discoverable, as: :boolean, wrapper: :with_label, hint: t(Setting.profile_directory ? 'simple_form.hints.defaults.discoverable' : 'simple_form.hints.defaults.discoverable_no_directory'), recommended: true
|
||||
= f.input :discoverable, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.discoverable'), recommended: true
|
||||
|
||||
.fields-group
|
||||
= f.input :hide_collections, as: :boolean, wrapper: :with_label, label: t('simple_form.labels.defaults.setting_hide_network'), hint: t('simple_form.hints.defaults.setting_hide_network')
|
||||
|
||||
%hr.spacer/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue