Merge pull request #253 from glitch-soc/prevent-local-only-federation

prevent federation of local-only statuses
This commit is contained in:
beatrix
2017-12-16 09:26:48 -05:00
committed by GitHub
8 changed files with 120 additions and 8 deletions

View File

@ -49,7 +49,7 @@ class AccountsController < ApplicationController
end
def default_statuses
@account.statuses.where(visibility: [:public, :unlisted])
@account.statuses.not_local_only.where(visibility: [:public, :unlisted])
end
def only_media_scope

View File

@ -23,6 +23,7 @@
# account_id :integer not null
# application_id :integer
# in_reply_to_account_id :integer
# local_only :boolean
#
class Status < ApplicationRecord
@ -74,6 +75,8 @@ class Status < ApplicationRecord
scope :not_excluded_by_account, ->(account) { where.not(account_id: account.excluded_from_timeline_account_ids) }
scope :not_domain_blocked_by_account, ->(account) { account.excluded_from_timeline_domains.blank? ? left_outer_joins(:account) : left_outer_joins(:account).where('accounts.domain IS NULL OR accounts.domain NOT IN (?)', account.excluded_from_timeline_domains) }
scope :not_local_only, -> { where(local_only: [false, nil]) }
cache_associated :account, :application, :media_attachments, :tags, :stream_entry, mentions: :account, reblog: [:account, :application, :stream_entry, :tags, :media_attachments, mentions: :account], thread: :account
delegate :domain, to: :account, prefix: true
@ -138,6 +141,8 @@ class Status < ApplicationRecord
around_create Mastodon::Snowflake::Callbacks
before_create :set_locality
before_validation :prepare_contents, if: :local?
before_validation :set_reblog
before_validation :set_visibility
@ -218,7 +223,7 @@ class Status < ApplicationRecord
visibility = [:public, :unlisted]
if account.nil?
where(visibility: visibility)
where(visibility: visibility).not_local_only
elsif target_account.blocking?(account) # get rid of blocked peeps
none
elsif account.id == target_account.id # author can see own stuff
@ -257,7 +262,7 @@ class Status < ApplicationRecord
end
def filter_timeline_default(query)
query.excluding_silenced_accounts
query.not_local_only.excluding_silenced_accounts
end
def account_silencing_filter(account)
@ -269,9 +274,13 @@ class Status < ApplicationRecord
end
end
def local_only?
def marked_local_only?
# match both with and without U+FE0F (the emoji variation selector)
/👁\ufe0f?\z/.match?(content)
/#{local_only_emoji}\ufe0f?\z/.match?(content)
end
def local_only_emoji
'👁'
end
private
@ -299,6 +308,12 @@ class Status < ApplicationRecord
self.sensitive = sensitive || spoiler_text.present?
end
def set_locality
if account.domain.nil? && !attribute_changed?(:local_only)
self.local_only = marked_local_only?
end
end
def set_conversation
self.reply = !(in_reply_to_id.nil? && thread.nil?) unless reply

View File

@ -40,8 +40,7 @@ class PostStatusService < BaseService
LinkCrawlWorker.perform_async(status.id) unless status.spoiler_text?
DistributionWorker.perform_async(status.id)
# match both with and without U+FE0F (the emoji variation selector)
unless /👁\ufe0f?\z/.match?(status.content)
unless status.local_only?
Pubsubhubbub::DistributionWorker.perform_async(status.stream_entry.id)
ActivityPub::DistributionWorker.perform_async(status.id)
ActivityPub::ReplyDistributionWorker.perform_async(status.id) if status.reply? && status.thread.account.local?

View File

@ -21,7 +21,7 @@ class ReblogService < BaseService
DistributionWorker.perform_async(reblog.id)
unless /👁$/.match?(reblogged_status.content)
unless reblogged_status.local_only?
Pubsubhubbub::DistributionWorker.perform_async(reblog.stream_entry.id)
ActivityPub::DistributionWorker.perform_async(reblog.id)
end