From c1b9b8dbc5b497d0af81a00167ab512978e446e6 Mon Sep 17 00:00:00 2001 From: noellabo Date: Tue, 1 Sep 2020 08:18:12 +0900 Subject: [PATCH] Fix fan-out-on-write service --- app/services/fan_out_on_write_service.rb | 28 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 9273f4c3a..1aad92065 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -18,14 +18,20 @@ class FanOutOnWriteService < BaseService deliver_to_lists(status) end - if status.account.group? && status.reblog? - render_anonymous_reblog_payload(status) + if status.account.group? + if status.reblog? + render_anonymous_reblog_payload(status) + else + render_anonymous_payload(status) + end deliver_to_group(status) end return if status.account.silenced? || !status.public_visibility? + render_anonymous_payload(status) + if !status.reblog? && (!status.reply? || status.in_reply_to_account_id == status.account_id) deliver_to_public(status) deliver_to_media(status) if status.media_attachments.any? @@ -37,8 +43,6 @@ class FanOutOnWriteService < BaseService return if status.reblog? - render_anonymous_payload(status) - deliver_to_hashtags(status) deliver_to_hashtag_followers(status) deliver_to_keyword_subscribers(status) @@ -158,11 +162,15 @@ class FanOutOnWriteService < BaseService end def render_anonymous_payload(status) + return @payload if defined?(@payload) + @payload = InlineRenderer.render(status, nil, :status) @payload = Oj.dump(event: :update, payload: @payload) end def render_anonymous_reblog_payload(status) + return @reblog_payload if defined?(@reblog_payload) + @reblog_payload = InlineRenderer.render(status.reblog, nil, :status) @reblog_payload = Oj.dump(event: :update, payload: @reblog_payload) end @@ -195,19 +203,21 @@ class FanOutOnWriteService < BaseService end def deliver_to_group(status) - Rails.logger.debug "Delivering status #{status.reblog.id} to group timeline" + Rails.logger.debug "Delivering status #{status.id} to group timeline" - Redis.current.publish("timeline:group:#{status.account.id}", @reblog_payload) + payload = status.reblog? ? @reblog_payload : @payload + + Redis.current.publish("timeline:group:#{status.account.id}", payload) status.tags.pluck(:name).each do |hashtag| - Redis.current.publish("timeline:group:#{status.account.id}:#{hashtag.mb_chars.downcase}", @reblog_payload) + Redis.current.publish("timeline:group:#{status.account.id}:#{hashtag.mb_chars.downcase}", payload) end if status.media_attachments.any? - Redis.current.publish("timeline:group:media:#{status.account.id}", @reblog_payload) + Redis.current.publish("timeline:group:media:#{status.account.id}", payload) status.tags.pluck(:name).each do |hashtag| - Redis.current.publish("timeline:group:media:#{status.account.id}:#{hashtag.mb_chars.downcase}", @reblog_payload) + Redis.current.publish("timeline:group:media:#{status.account.id}:#{hashtag.mb_chars.downcase}", payload) end end end