end
def hide_results?
- (@account.user_hides_network? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account))
+ (@account.hides_followers? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account))
end
def default_accounts
end
def hide_results?
- (@account.user_hides_network? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account))
+ (@account.hides_following? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account))
end
def default_accounts
render json: collection_presenter,
serializer: ActivityPub::CollectionSerializer,
adapter: ActivityPub::Adapter,
- content_type: 'application/activity+json'
+ content_type: 'application/activity+json',
+ fields: restrict_fields_to
end
end
end
)
end
end
+
+ def restrict_fields_to
+ if page_requested? || !@account.user_hides_network?
+ # Return all fields
+ else
+ %i(id type totalItems)
+ end
+ end
end
render json: collection_presenter,
serializer: ActivityPub::CollectionSerializer,
adapter: ActivityPub::Adapter,
- content_type: 'application/activity+json'
+ content_type: 'application/activity+json',
+ fields: restrict_fields_to
end
end
end
)
end
end
+
+ def restrict_fields_to
+ if page_requested? || !@account.user_hides_network?
+ # Return all fields
+ else
+ %i(id type totalItems)
+ end
+ end
end
# silenced_at :datetime
# suspended_at :datetime
# trust_level :integer
+# hide_collections :boolean
#
class Account < ApplicationRecord
save!
end
+ def hides_followers?
+ hide_collections? || user_hides_network?
+ end
+
+ def hides_following?
+ hide_collections? || user_hides_network?
+ end
+
def object_type
:person
end
@account.statuses_count = outbox_total_items if outbox_total_items.present?
@account.following_count = following_total_items if following_total_items.present?
@account.followers_count = followers_total_items if followers_total_items.present?
+ @account.hide_collections = following_private? || followers_private?
@account.moved_to_account = @json['movedTo'].present? ? moved_account : nil
end
end
def outbox_total_items
- collection_total_items('outbox')
+ collection_info('outbox').first
end
def following_total_items
- collection_total_items('following')
+ collection_info('following').first
end
def followers_total_items
- collection_total_items('followers')
+ collection_info('followers').first
end
- def collection_total_items(type)
- return if @json[type].blank?
+ def following_private?
+ !collection_info('following').last
+ end
+
+ def followers_private?
+ !collection_info('followers').last
+ end
+
+ def collection_info(type)
+ return [nil, nil] if @json[type].blank?
return @collections[type] if @collections.key?(type)
collection = fetch_resource_without_id_validation(@json[type])
- @collections[type] = collection.is_a?(Hash) && collection['totalItems'].present? && collection['totalItems'].is_a?(Numeric) ? collection['totalItems'] : nil
+ total_items = collection.is_a?(Hash) && collection['totalItems'].present? && collection['totalItems'].is_a?(Numeric) ? collection['totalItems'] : nil
+ has_first_page = collection.is_a?(Hash) && collection['first'].present?
+ @collections[type] = [total_items, has_first_page]
rescue HTTP::Error, OpenSSL::SSL::SSLError
- @collections[type] = nil
+ @collections[type] = [nil, nil]
end
def moved_account
--- /dev/null
+class AddHideCollectionsToAccounts < ActiveRecord::Migration[5.2]
+ def change
+ add_column :accounts, :hide_collections, :boolean
+ end
+end
t.datetime "silenced_at"
t.datetime "suspended_at"
t.integer "trust_level"
+ t.boolean "hide_collections"
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
t.index "lower((username)::text), lower((domain)::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id"