about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorbeatrix <beatrix.bitrot@gmail.com>2017-12-16 09:26:48 -0500
committerGitHub <noreply@github.com>2017-12-16 09:26:48 -0500
commite202efdf8a11a5e2fdcc029c46f972ca517f452e (patch)
tree213e59a42600c81edce0beec1f0ae9870cbdbaf5 /app
parent5325c2ab3e11652e7620f45954ef025e1ac9d833 (diff)
parent82b2e224a26765caf743b24844912faa2de9873a (diff)
Merge pull request #253 from glitch-soc/prevent-local-only-federation
prevent federation of local-only statuses
Diffstat (limited to 'app')
-rw-r--r--app/controllers/accounts_controller.rb2
-rw-r--r--app/models/status.rb23
-rw-r--r--app/services/post_status_service.rb3
-rw-r--r--app/services/reblog_service.rb2
4 files changed, 22 insertions, 8 deletions
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 309cb65da..31144fe05 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -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
diff --git a/app/models/status.rb b/app/models/status.rb
index 70cfdc1c7..db3072571 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -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
 
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index 59531a76c..6b6a37676 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -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?
diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb
index 52e3ba0e0..8d8b15a41 100644
--- a/app/services/reblog_service.rb
+++ b/app/services/reblog_service.rb
@@ -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