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.
parent
cdacbb3c4c
commit
3bfa72cbce
|
@ -67,6 +67,8 @@ class Account < ApplicationRecord
|
||||||
MAX_NOTE_LENGTH = (ENV['MAX_BIO_CHARS'] || 500).to_i
|
MAX_NOTE_LENGTH = (ENV['MAX_BIO_CHARS'] || 500).to_i
|
||||||
MAX_FIELDS = (ENV['MAX_PROFILE_FIELDS'] || 4).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]
|
enum protocol: [:ostatus, :activitypub]
|
||||||
|
|
||||||
validates :username, presence: true
|
validates :username, presence: true
|
||||||
|
@ -127,6 +129,10 @@ class Account < ApplicationRecord
|
||||||
domain.nil?
|
domain.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def network?
|
||||||
|
local? || domain.in?(LOCAL_DOMAINS)
|
||||||
|
end
|
||||||
|
|
||||||
def moved?
|
def moved?
|
||||||
moved_to_account_id.present?
|
moved_to_account_id.present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
# tsv :tsvector
|
# tsv :tsvector
|
||||||
# curated :boolean
|
# curated :boolean
|
||||||
# sharekey :string
|
# sharekey :string
|
||||||
|
# network :boolean
|
||||||
#
|
#
|
||||||
|
|
||||||
class Status < ApplicationRecord
|
class Status < ApplicationRecord
|
||||||
|
@ -38,7 +39,6 @@ class Status < ApplicationRecord
|
||||||
include StatusThreadingConcern
|
include StatusThreadingConcern
|
||||||
|
|
||||||
LOCAL_DOMAINS = ENV.fetch('LOCAL_DOMAINS', '').chomp.split(/\.?\s+/).freeze
|
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_SENSITIVE = ENV.fetch('FORCE_SENSITIVE', '').chomp.split(/\.?\s+/).freeze
|
||||||
FORCE_UNLISTED = ENV.fetch('FORCE_UNLISTED', '').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 :recent, -> { reorder(id: :desc) }
|
||||||
scope :remote, -> { where(local: false).or(where.not(uri: nil)) }
|
scope :remote, -> { where(local: false).or(where.not(uri: nil)) }
|
||||||
scope :local, -> { where(local: true).or(where(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 :curated, -> { where(curated: true) }
|
||||||
|
|
||||||
scope :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') }
|
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
|
end
|
||||||
|
|
||||||
def network?
|
def network?
|
||||||
attributes['local'] || uri.nil? || account.domain.in?(LOCAL_DOMAINS)
|
attributes['network'] || local? || account.domain.in?(LOCAL_DOMAINS)
|
||||||
end
|
end
|
||||||
|
|
||||||
def relayed?
|
def relayed?
|
||||||
|
@ -298,8 +298,6 @@ class Status < ApplicationRecord
|
||||||
after_create :set_poll_id
|
after_create :set_poll_id
|
||||||
after_create :process_bangtags, if: :local?
|
after_create :process_bangtags, if: :local?
|
||||||
|
|
||||||
after_find :limit_domain_visibility
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def search_for(term, limit = 66, account = nil)
|
def search_for(term, limit = 66, account = nil)
|
||||||
pattern = sanitize_sql_like(term)
|
pattern = sanitize_sql_like(term)
|
||||||
|
@ -462,7 +460,7 @@ class Status < ApplicationRecord
|
||||||
private
|
private
|
||||||
|
|
||||||
def timeline_scope(local_only = false)
|
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
|
starting_scope = starting_scope.with_public_visibility
|
||||||
if Setting.show_reblogs_in_public_timelines
|
if Setting.show_reblogs_in_public_timelines
|
||||||
starting_scope
|
starting_scope
|
||||||
|
@ -472,7 +470,7 @@ class Status < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def browsable_timeline_scope(local_only = false)
|
def browsable_timeline_scope(local_only = false)
|
||||||
starting_scope = local_only ? Status.local : Status
|
starting_scope = local_only ? Status.network : Status
|
||||||
starting_scope
|
starting_scope
|
||||||
.public_browsable
|
.public_browsable
|
||||||
.without_reblogs
|
.without_reblogs
|
||||||
|
@ -547,16 +545,11 @@ class Status < ApplicationRecord
|
||||||
def set_visibility
|
def set_visibility
|
||||||
self.visibility = reblog.visibility if reblog? && visibility.nil?
|
self.visibility = reblog.visibility if reblog? && visibility.nil?
|
||||||
self.visibility = (account.locked? ? :private : :public) if 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?
|
self.sensitive = false if sensitive.nil?
|
||||||
end
|
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
|
def set_locality
|
||||||
if account.domain.nil? && !attribute_changed?(:local_only)
|
if account.domain.nil? && !attribute_changed?(:local_only)
|
||||||
self.local_only = marked_local_only?
|
self.local_only = marked_local_only?
|
||||||
|
@ -939,6 +932,7 @@ class Status < ApplicationRecord
|
||||||
|
|
||||||
def set_local
|
def set_local
|
||||||
self.local = account.local?
|
self.local = account.local?
|
||||||
|
self.network = account.network?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_statistics
|
def update_statistics
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddNetworkToStatus < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :statuses, :network, :boolean
|
||||||
|
end
|
||||||
|
end
|
|
@ -642,6 +642,7 @@ ActiveRecord::Schema.define(version: 2019_05_19_130537) do
|
||||||
t.tsvector "tsv"
|
t.tsvector "tsv"
|
||||||
t.boolean "curated"
|
t.boolean "curated"
|
||||||
t.string "sharekey"
|
t.string "sharekey"
|
||||||
|
t.boolean "network"
|
||||||
t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20180106", order: { id: :desc }
|
t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20180106", order: { id: :desc }
|
||||||
t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id"
|
t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id"
|
||||||
t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id"
|
t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id"
|
||||||
|
|
Loading…
Reference in New Issue