Compare commits

...

3 Commits

Author SHA1 Message Date
Andrew Dunham 74268f4ff7
Merge 04447a05cb into 574cdad7a8 2023-12-26 10:09:25 +00:00
Mathilde 574cdad7a8
Fixing wrongly formatted readme
Contributing to Hometown section would show up as title instead of simple body text.
2023-12-26 11:09:13 +01:00
Andrew Dunham 04447a05cb PublicFeed: add a configuration setting to filter out bot accounts
This can be useful when running a smaller instance that also has bot
accounts, where you don't want them to clutter up the Local timeline.
2023-02-09 16:50:07 -05:00
7 changed files with 57 additions and 3 deletions

View File

@ -81,7 +81,7 @@ Hometown uses [semantic versioning](https://semver.org) and follows a versioning
## Contributing to Hometown
Setting up your Hometown development environment is [exactly like setting up your Mastodon development environment](https://docs.joinmastodon.org/dev/overview/). Pull requests should be made to the `hometown-dev` branch, which is our default branch in Github.
=======
You can open issues for bugs you've found or features you think are missing. You can also submit pull requests to this repository or submit translations using Crowdin. To get started, take a look at [CONTRIBUTING.md](CONTRIBUTING.md). If your contributions are accepted into Mastodon, you can request to be paid through [our OpenCollective](https://opencollective.com/mastodon).
**IRC channel**: #mastodon on irc.libera.chat

View File

@ -37,10 +37,15 @@ class Api::V1::Timelines::PublicController < Api::BaseController
current_account,
local: truthy_param?(:local),
remote: truthy_param?(:remote),
only_media: truthy_param?(:only_media)
only_media: truthy_param?(:only_media),
without_bots: without_bots?
)
end
def without_bots?
Rails.configuration.x.local_timeline_exclude_bots && truthy_param?(:local)
end
def insert_pagination_headers
set_pagination_headers(next_path, prev_path)
end

View File

@ -103,6 +103,7 @@ class Account < ApplicationRecord
scope :without_suspended, -> { where(suspended_at: nil) }
scope :without_silenced, -> { where(silenced_at: nil) }
scope :without_instance_actor, -> { where.not(id: -99) }
scope :without_bots, -> { where.not(actor_type: %w(Application Service)).or(where(actor_type: nil)) }
scope :recent, -> { reorder(id: :desc) }
scope :bots, -> { where(actor_type: %w(Application Service)) }
scope :groups, -> { where(actor_type: 'Group') }

View File

@ -8,6 +8,7 @@ class PublicFeed
# @option [Boolean] :local
# @option [Boolean] :remote
# @option [Boolean] :only_media
# @option [Boolean] :without_bots
def initialize(account, options = {})
@account = account
@options = options
@ -68,8 +69,16 @@ class PublicFeed
options[:only_media]
end
def without_bots?
options[:without_bots]
end
def public_scope
Status.with_public_visibility.joins(:account).merge(Account.without_suspended.without_silenced)
account_scope = Account.without_suspended.without_silenced
if without_bots?
account_scope = account_scope.without_bots
end
scope = Status.with_public_visibility.joins(:account).merge(account_scope)
end
def local_only_scope

View File

@ -12,6 +12,7 @@ class TagFeed < PublicFeed
# @option [Boolean] :local
# @option [Boolean] :remote
# @option [Boolean] :only_media
# @option [Boolean] :without_bots
def initialize(tag, account, options = {})
@tag = tag
super(account, options)

View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
Rails.application.configure do
config.x.local_timeline_exclude_bots = ENV['LOCAL_TIMELINE_EXCLUDE_BOTS'] == 'true'
end

View File

@ -39,6 +39,39 @@ RSpec.describe PublicFeed, type: :model do
expect(subject).not_to include(silenced_status.id)
end
describe '#without_bots=' do
let(:person_account) { Fabricate(:account, actor_type: 'Person') }
let(:bot_account) { Fabricate(:account, actor_type: 'Application') }
context 'when the setting is false' do
subject { described_class.new(nil, without_bots: false).get(20).map(&:id) }
it 'includes bots' do
status = Fabricate(:status, account: account)
person_status = Fabricate(:status, account: person_account)
bot_status = Fabricate(:status, account: bot_account)
expect(subject).to include(status.id)
expect(subject).to include(person_status.id)
expect(subject).to include(bot_status.id)
end
end
context 'when the setting is true' do
subject { described_class.new(nil, without_bots: true).get(20).map(&:id) }
it 'filters out bot accounts' do
status = Fabricate(:status, account: account)
person_status = Fabricate(:status, account: person_account)
bot_status = Fabricate(:status, account: bot_account)
expect(subject).to include(status.id)
expect(subject).to include(person_status.id)
expect(subject).not_to include(bot_status.id)
end
end
end
context 'without local_only option' do
let(:viewer) { nil }