Use backend from glitch-soc for instance-only toots

This commit is contained in:
Renato "Lond" Cerqueira
2018-08-23 19:30:09 +02:00
parent ccc2f608c5
commit ffaa814bbe
11 changed files with 90 additions and 11 deletions

View File

@ -35,7 +35,7 @@ class AccountsController < ApplicationController
end
format.rss do
@statuses = cache_collection(default_statuses.without_reblogs.without_replies.limit(PAGE_SIZE), Status)
@statuses = cache_collection(default_statuses.without_local_only.without_reblogs.without_replies.limit(PAGE_SIZE), Status)
render xml: RSS::AccountSerializer.render(@account, @statuses)
end

View File

@ -19,7 +19,7 @@ class StreamEntriesController < ApplicationController
end
format.atom do
unless @stream_entry.hidden?
unless @stream_entry.hidden? || @stream_entry.local_only?
skip_session!
expires_in 3.minutes, public: true
end
@ -53,7 +53,7 @@ class StreamEntriesController < ApplicationController
@type = @stream_entry.activity_type.downcase
raise ActiveRecord::RecordNotFound if @stream_entry.activity.nil?
authorize @stream_entry.activity, :show? if @stream_entry.hidden?
authorize @stream_entry.activity, :show? if @stream_entry.hidden? || @stream_entry.local_only?
rescue Mastodon::NotPermittedError
# Reraise in order to get a 404
raise ActiveRecord::RecordNotFound

View File

@ -21,6 +21,7 @@
# account_id :bigint(8) not null
# application_id :bigint(8)
# in_reply_to_account_id :bigint(8)
# local_only :boolean
#
class Status < ApplicationRecord
@ -73,6 +74,7 @@ class Status < ApplicationRecord
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 :without_local_only, -> { where(local_only: [false, nil]) }
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: false }) }
@ -336,7 +338,7 @@ class Status < ApplicationRecord
visibility = [:public, :unlisted]
if account.nil?
where(visibility: visibility)
where(visibility: visibility).without_local_only
elsif target_account.blocking?(account) # get rid of blocked peeps
none
elsif account.id == target_account.id # author can see own stuff
@ -379,7 +381,7 @@ class Status < ApplicationRecord
end
def filter_timeline_default(query)
query.excluding_silenced_accounts
query.without_local_only.excluding_silenced_accounts
end
def account_silencing_filter(account)

View File

@ -27,7 +27,7 @@ class StreamEntry < ApplicationRecord
scope :recent, -> { reorder(id: :desc) }
scope :with_includes, -> { includes(:account, status: STATUS_INCLUDES) }
delegate :target, :title, :content, :thread,
delegate :target, :title, :content, :thread, :local_only?,
to: :status,
allow_nil: true

View File

@ -12,6 +12,8 @@ class StatusPolicy < ApplicationPolicy
end
def show?
return false if local_only? && (current_account.nil? || !current_account.local?)
if direct?
owned? || mention_exists?
elsif private?
@ -84,4 +86,8 @@ class StatusPolicy < ApplicationPolicy
def author
record.account
end
def local_only?
record.local_only?
end
end

View File

@ -39,9 +39,12 @@ class PostStatusService < BaseService
LinkCrawlWorker.perform_async(status.id) unless status.spoiler_text?
DistributionWorker.perform_async(status.id)
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?
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?
end
if options[:idempotency].present?
redis.setex("idempotency:status:#{account.id}:#{options[:idempotency]}", 3_600, status.id)

View File

@ -20,8 +20,11 @@ class ReblogService < BaseService
reblog = account.statuses.create!(reblog: reblogged_status, text: '')
DistributionWorker.perform_async(reblog.id)
Pubsubhubbub::DistributionWorker.perform_async(reblog.stream_entry.id)
ActivityPub::DistributionWorker.perform_async(reblog.id)
unless reblogged_status.local_only?
Pubsubhubbub::DistributionWorker.perform_async(reblog.stream_entry.id)
ActivityPub::DistributionWorker.perform_async(reblog.id)
end
create_notification(reblog)
bump_potential_friendship(account, reblog)