community world tl + networked home tl
parent
9a94d5e2c5
commit
a7aa2544e4
|
@ -35,6 +35,9 @@ class Status < ApplicationRecord
|
|||
include Cacheable
|
||||
include StatusThreadingConcern
|
||||
|
||||
LOCAL_DOMAINS = ENV.fetch('LOCAL_DOMAINS', '').chomp.split(/\.?\s+/).freeze
|
||||
LOCAL_URIS = LOCAL_DOMAINS.map { |domain| "https://#{domain}/%" }.freeze
|
||||
|
||||
# If `override_timestamps` is set at creation time, Snowflake ID creation
|
||||
# will be based on current time instead of `created_at`
|
||||
attr_accessor :override_timestamps
|
||||
|
@ -84,9 +87,11 @@ 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 :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') }
|
||||
scope :without_reblogs, -> { where('statuses.reblog_of_id IS NULL') }
|
||||
scope :reblogs, -> { where('statuses.reblog_of_id IS NOT NULL') } # all reblogs
|
||||
scope :with_public_visibility, -> { where(visibility: :public) }
|
||||
scope :tagged_with, ->(tag) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag }) }
|
||||
scope :excluding_silenced_accounts, -> { left_outer_joins(:account).where(accounts: { silenced_at: nil }) }
|
||||
|
@ -163,6 +168,14 @@ class Status < ApplicationRecord
|
|||
attributes['local'] || uri.nil?
|
||||
end
|
||||
|
||||
def network?
|
||||
attributes['local'] || uri.nil? || account.domain.in?(LOCAL_DOMAINS)
|
||||
end
|
||||
|
||||
def relayed?
|
||||
account.username == :relay && account.actor_type.in?(Set[:Application, :Service])
|
||||
end
|
||||
|
||||
def reblog?
|
||||
!reblog_of_id.nil?
|
||||
end
|
||||
|
@ -333,8 +346,26 @@ class Status < ApplicationRecord
|
|||
end
|
||||
|
||||
def as_public_timeline(account = nil, local_only = false)
|
||||
query = timeline_scope(local_only)
|
||||
query = query.without_replies unless Setting.show_replies_in_public_timelines
|
||||
# instead of our ftl being a noisy irrelevant firehose
|
||||
# only show public stuff boosted by the community
|
||||
query = Status.network
|
||||
if local_only then
|
||||
# we don't want to change the ltl
|
||||
query = query
|
||||
.with_public_visibility
|
||||
.without_replies
|
||||
.without_reblogs
|
||||
else # but on the ftl
|
||||
query = query.without_replies unless Setting.show_replies_in_public_timelines
|
||||
# grab the stuff we boosted
|
||||
subquery = query.reblogs.select(:reblog_of_id)
|
||||
.reorder(nil)
|
||||
.distinct
|
||||
# map those ids to actual statuses
|
||||
# THIS QUERY IS EXPENSIVE AS FUCK!!!!!!!
|
||||
# but it does the job
|
||||
query = Status.where(id: subquery).with_public_visibility
|
||||
end
|
||||
|
||||
apply_timeline_filters(query, account, local_only)
|
||||
end
|
||||
|
|
|
@ -21,15 +21,29 @@ class FanOutOnWriteService < BaseService
|
|||
deliver_to_lists(status)
|
||||
end
|
||||
|
||||
return if status.account.silenced? || !status.public_visibility?
|
||||
return if status.reblog? && !Setting.show_reblogs_in_public_timelines
|
||||
return if status.account.silenced?
|
||||
|
||||
deliver_to_hashtags(status)
|
||||
deliver_to_hashtags(status) if !status.reblog? && status.distributable?
|
||||
|
||||
# we want to let community users decide what goes on the ftl with boosts
|
||||
return unless status.network? || status.relayed?
|
||||
deliver_to_local = true
|
||||
|
||||
if status.reblog? then
|
||||
status = Status.find(status.reblog_of_id)
|
||||
render_anonymous_payload(status)
|
||||
deliver_to_local = status.network?
|
||||
end
|
||||
|
||||
return if status.account.silenced? || !status.public_visibility?
|
||||
return if status.reply? && status.in_reply_to_account_id != status.account_id && !Setting.show_replies_in_public_timelines
|
||||
|
||||
deliver_to_public(status)
|
||||
deliver_to_media(status) if status.media_attachments.any?
|
||||
if deliver_to_local then
|
||||
deliver_to_local(status)
|
||||
else
|
||||
deliver_to_public(status)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -85,14 +99,15 @@ class FanOutOnWriteService < BaseService
|
|||
Rails.logger.debug "Delivering status #{status.id} to public timeline"
|
||||
|
||||
Redis.current.publish('timeline:public', @payload)
|
||||
Redis.current.publish('timeline:public:local', @payload) if status.local?
|
||||
Redis.current.publish('timeline:public:media', @payload) if status.media_attachments.any?
|
||||
end
|
||||
|
||||
def deliver_to_media(status)
|
||||
Rails.logger.debug "Delivering status #{status.id} to media timeline"
|
||||
def deliver_to_local(status)
|
||||
Rails.logger.debug "Delivering status #{status.id} to local timeline"
|
||||
|
||||
Redis.current.publish('timeline:public:media', @payload)
|
||||
Redis.current.publish('timeline:public:local:media', @payload) if status.local?
|
||||
return unless status.network?
|
||||
Redis.current.publish('timeline:public:local', @payload)
|
||||
Redis.current.publish('timeline:public:local:media', @payload) if status.media_attachments.any?
|
||||
end
|
||||
|
||||
def deliver_to_direct_timelines(status)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class ProcessHashtagsService < BaseService
|
||||
def call(status, tags = [])
|
||||
tags = Extractor.extract_hashtags(status.text) if status.local?
|
||||
tags = Extractor.extract_hashtags(status.text) if status.network?
|
||||
records = []
|
||||
|
||||
tags.map { |str| str.mb_chars.downcase }.uniq(&:to_s).each do |name|
|
||||
|
@ -11,7 +11,7 @@ class ProcessHashtagsService < BaseService
|
|||
status.tags << tag
|
||||
records << tag
|
||||
|
||||
TrendingTags.record_use!(tag, status.account, status.created_at) if status.public_visibility?
|
||||
TrendingTags.record_use!(tag, status.account, status.created_at) if status.distributable?
|
||||
end
|
||||
|
||||
return unless status.public_visibility? || status.unlisted_visibility?
|
||||
|
|
Loading…
Reference in New Issue