about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-04-17 00:15:10 -0500
committermultiple creatures <dev@multiple-creature.party>2019-05-21 03:16:22 -0500
commit3bfa72cbce8521676f931676089169b9e105daa4 (patch)
tree2945bb90b18a15490480cc5baa7401f216e1c136 /app
parentcdacbb3c4c80c32b5845d3f1492c207ac3481375 (diff)
Dedicated `network` DB column for marking whether a roar is a part of the local network; rewrite posts from `FORCE_*` domains at create time instead of dynamically.
Diffstat (limited to 'app')
-rw-r--r--app/models/account.rb6
-rw-r--r--app/models/status.rb22
2 files changed, 14 insertions, 14 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 28a7aa500..ec49d9308 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -67,6 +67,8 @@ class Account < ApplicationRecord
   MAX_NOTE_LENGTH = (ENV['MAX_BIO_CHARS'] || 500).to_i
   MAX_FIELDS = (ENV['MAX_PROFILE_FIELDS'] || 4).to_i
 
+  LOCAL_DOMAINS = ENV.fetch('LOCAL_DOMAINS', '').chomp.split(/\.?\s+/).freeze
+
   enum protocol: [:ostatus, :activitypub]
 
   validates :username, presence: true
@@ -127,6 +129,10 @@ class Account < ApplicationRecord
     domain.nil?
   end
 
+  def network?
+    local? || domain.in?(LOCAL_DOMAINS)
+  end
+
   def moved?
     moved_to_account_id.present?
   end
diff --git a/app/models/status.rb b/app/models/status.rb
index 2e4808cb5..cc878d7f5 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -27,6 +27,7 @@
 #  tsv                    :tsvector
 #  curated                :boolean
 #  sharekey               :string
+#  network                :boolean
 #
 
 class Status < ApplicationRecord
@@ -38,7 +39,6 @@ class Status < ApplicationRecord
   include StatusThreadingConcern
 
   LOCAL_DOMAINS = ENV.fetch('LOCAL_DOMAINS', '').chomp.split(/\.?\s+/).freeze
-  LOCAL_URIS = LOCAL_DOMAINS.map { |domain| "https://#{domain}/%" }.freeze
   FORCE_SENSITIVE = ENV.fetch('FORCE_SENSITIVE', '').chomp.split(/\.?\s+/).freeze
   FORCE_UNLISTED = ENV.fetch('FORCE_UNLISTED', '').chomp.split(/\.?\s+/).freeze
 
@@ -91,7 +91,7 @@ class Status < ApplicationRecord
   scope :recent, -> { reorder(id: :desc) }
   scope :remote, -> { where(local: false).or(where.not(uri: nil)) }
   scope :local,  -> { where(local: true).or(where(uri: nil)) }
-  scope :network, -> { where(local: true).or(where(uri: nil)).or(where('statuses.uri LIKE ANY (array[?])', LOCAL_URIS)) }
+  scope :network, -> { where(network: true) }
   scope :curated, -> { where(curated: true) }
 
   scope :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') }
@@ -175,7 +175,7 @@ class Status < ApplicationRecord
   end
 
   def network?
-    attributes['local'] || uri.nil? || account.domain.in?(LOCAL_DOMAINS)
+    attributes['network'] || local? || account.domain.in?(LOCAL_DOMAINS)
   end
 
   def relayed?
@@ -298,8 +298,6 @@ class Status < ApplicationRecord
   after_create :set_poll_id
   after_create :process_bangtags, if: :local?
 
-  after_find :limit_domain_visibility
-
   class << self
     def search_for(term, limit = 66, account = nil)
       pattern = sanitize_sql_like(term)
@@ -462,7 +460,7 @@ class Status < ApplicationRecord
     private
 
     def timeline_scope(local_only = false)
-      starting_scope = local_only ? Status.local : Status
+      starting_scope = local_only ? Status.network : Status
       starting_scope = starting_scope.with_public_visibility
       if Setting.show_reblogs_in_public_timelines
         starting_scope
@@ -472,7 +470,7 @@ class Status < ApplicationRecord
     end
 
     def browsable_timeline_scope(local_only = false)
-      starting_scope = local_only ? Status.local : Status
+      starting_scope = local_only ? Status.network : Status
       starting_scope
         .public_browsable
         .without_reblogs
@@ -547,16 +545,11 @@ class Status < ApplicationRecord
   def set_visibility
     self.visibility = reblog.visibility if reblog? && visibility.nil?
     self.visibility = (account.locked? ? :private : :public) if visibility.nil?
+    self.visibility = :unlisted if visibility == :public && account.domain.in?(FORCE_UNLISTED)
+    self.sensitive  = true if account.domain.in?(FORCE_SENSITIVE)
     self.sensitive  = false if sensitive.nil?
   end
 
-  def limit_domain_visibility
-    return unless has_attribute?(:uri) && !uri.nil?
-    domain = Addressable::URI.parse(uri).host
-    self.sensitive = true if domain.in?(FORCE_SENSITIVE)
-    self.visibility = :unlisted if public_visibility? && domain.in?(FORCE_UNLISTED)
-  end
-
   def set_locality
     if account.domain.nil? && !attribute_changed?(:local_only)
       self.local_only = marked_local_only?
@@ -939,6 +932,7 @@ class Status < ApplicationRecord
 
   def set_local
     self.local = account.local?
+    self.network = account.network?
   end
 
   def update_statistics