mirror of
https://github.com/mastodon/mastodon
synced 2025-04-12 00:56:38 +02:00
[WiP] Quote post filtering
This commit is contained in:
parent
3720fa691c
commit
0ce69bd466
@ -6,6 +6,8 @@ class StatusCacheHydrator
|
||||
end
|
||||
|
||||
def hydrate(account_id)
|
||||
# TODO: handle quotes
|
||||
|
||||
# The cache of the serialized hash is generated by the fan-out-on-write service
|
||||
payload = Rails.cache.fetch("fan-out/#{@status.id}") { InlineRenderer.render(@status, nil, :status) }
|
||||
|
||||
|
@ -348,6 +348,10 @@ class Status < ApplicationRecord
|
||||
end
|
||||
|
||||
class << self
|
||||
def quoted_status_ids(status_ids)
|
||||
Quote.where(status_id: status_ids).pluck(:quoted_status_id).compact
|
||||
end
|
||||
|
||||
def favourites_map(status_ids, account_id)
|
||||
Favourite.select(:status_id).where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |f, h| h[f.status_id] = true }
|
||||
end
|
||||
|
@ -17,6 +17,9 @@ class StatusRelationshipsPresenter
|
||||
else
|
||||
statuses = statuses.compact
|
||||
status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact
|
||||
quoted_ids = Status.quoted_status_ids(status_ids)
|
||||
status_ids = (status_ids + quoted_ids).uniq
|
||||
# TODO: pinnable_status_ids, conversation_ids, and filters_map are not built with quoted_ids at this point
|
||||
conversation_ids = statuses.filter_map(&:conversation_id).uniq
|
||||
pinnable_status_ids = statuses.map(&:proper).filter_map { |s| s.id if s.account_id == current_account_id && PINNABLE_VISIBILITIES.include?(s.visibility) }
|
||||
|
||||
|
@ -6,6 +6,12 @@ class REST::QuoteSerializer < ActiveModel::Serializer
|
||||
has_one :quoted_status, serializer: REST::ShallowStatusSerializer
|
||||
|
||||
def quoted_status
|
||||
object.quoted_status if object.accepted?
|
||||
return unless object.accepted?
|
||||
|
||||
quoted_status = object.quoted_status
|
||||
return if quoted_status.nil?
|
||||
|
||||
status_filter = StatusFilter.new(quoted_status, current_user&.account, instance_options[:relationships] || {})
|
||||
quoted_status unless status_filter.filtered?
|
||||
end
|
||||
end
|
||||
|
@ -4,6 +4,12 @@ class REST::ShallowQuoteSerializer < ActiveModel::Serializer
|
||||
attributes :state, :quoted_status_id
|
||||
|
||||
def quoted_status_id
|
||||
object.quoted_status&.id&.to_s if object.accepted?
|
||||
return unless object.accepted?
|
||||
|
||||
quoted_status = object.quoted_status
|
||||
return if quoted_status.nil?
|
||||
|
||||
status_filter = StatusFilter.new(quoted_status, current_user&.account, instance_options[:relationships] || {})
|
||||
quoted_status.id.to_s unless status_filter.filtered?
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user