mirror of
https://github.com/glitch-soc/mastodon
synced 2025-04-24 17:44:50 +00:00
Hydrate reactions on streaming API
This commit is contained in:
parent
d23aff436d
commit
6db8e1f319
3 changed files with 18 additions and 6 deletions
|
@ -61,6 +61,7 @@ class StatusCacheHydrator
|
|||
payload[:filtered] = payload[:reblog][:filtered]
|
||||
payload[:favourited] = payload[:reblog][:favourited]
|
||||
payload[:reblogged] = payload[:reblog][:reblogged]
|
||||
payload[:reactions] = payload[:reblog][:reactions]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,6 +72,7 @@ class StatusCacheHydrator
|
|||
payload[:bookmarked] = Bookmark.exists?(account_id: account_id, status_id: status.id)
|
||||
payload[:pinned] = StatusPin.exists?(account_id: account_id, status_id: status.id) if status.account_id == account_id
|
||||
payload[:filtered] = mapped_applied_custom_filter(account_id, status)
|
||||
payload[:reactions] = serialized_reactions(account_id)
|
||||
payload[:quote] = hydrate_quote_payload(payload[:quote], status.quote, account_id) if payload[:quote]
|
||||
end
|
||||
|
||||
|
@ -103,6 +105,16 @@ class StatusCacheHydrator
|
|||
).as_json
|
||||
end
|
||||
|
||||
def serialized_reactions(account_id)
|
||||
reactions = @status.reactions(account_id)
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
reactions,
|
||||
each_serializer: REST::ReactionSerializer,
|
||||
scope: account_id, # terrible
|
||||
scope_name: :current_user
|
||||
).as_json
|
||||
end
|
||||
|
||||
def payload_application
|
||||
@status.application.present? ? serialized_status_application_json : nil
|
||||
end
|
||||
|
|
|
@ -278,10 +278,10 @@ class Status < ApplicationRecord
|
|||
@emojis = CustomEmoji.from_text(fields.join(' '), account.domain)
|
||||
end
|
||||
|
||||
def reactions(account = nil)
|
||||
def reactions(account_id = nil)
|
||||
grouped_ordered_status_reactions.select(
|
||||
[:name, :custom_emoji_id, 'COUNT(*) as count'].tap do |values|
|
||||
values << value_for_reaction_me_column(account)
|
||||
values << value_for_reaction_me_column(account_id)
|
||||
end
|
||||
).to_a.tap do |records|
|
||||
ActiveRecord::Associations::Preloader.new(records: records, associations: :custom_emoji).call
|
||||
|
@ -469,15 +469,15 @@ class Status < ApplicationRecord
|
|||
)
|
||||
end
|
||||
|
||||
def value_for_reaction_me_column(account)
|
||||
if account.nil?
|
||||
def value_for_reaction_me_column(account_id)
|
||||
if account_id.nil?
|
||||
'FALSE AS me'
|
||||
else
|
||||
<<~SQL.squish
|
||||
EXISTS(
|
||||
SELECT 1
|
||||
FROM status_reactions inner_reactions
|
||||
WHERE inner_reactions.account_id = #{account.id}
|
||||
WHERE inner_reactions.account_id = #{account_id}
|
||||
AND inner_reactions.status_id = status_reactions.status_id
|
||||
AND inner_reactions.name = status_reactions.name
|
||||
AND (
|
||||
|
|
|
@ -161,7 +161,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
|||
end
|
||||
|
||||
def reactions
|
||||
object.reactions(current_user&.account)
|
||||
object.reactions(current_user&.account&.id)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Add table
Reference in a new issue