Added streaming of updated status from fetch_link_card_service

Sends updated status down after adding/updating/removing preview card.
This commit is contained in:
mgabdev
2019-08-28 01:26:34 -04:00
parent dc87184ef0
commit 31d4660947
3 changed files with 52 additions and 3 deletions

View File

@@ -15,7 +15,15 @@ class FetchLinkCardService < BaseService
@status = status
@url = parse_urls
return if @url.nil? || @status.preview_cards.any?
if @status.preview_cards.any?
if @url.nil?
detach_card
return
end
return if @status.preview_cards.first.url == @url
end
return if @url.nil?
@url = @url.to_s
@@ -49,13 +57,23 @@ class FetchLinkCardService < BaseService
end
end
return if @html.nil?
if @html.nil?
detach_card
return
end
attempt_oembed || attempt_opengraph
end
def attach_card
@status.preview_cards << @card
@status.preview_cards = [@card]
send_status_update_payload(@status)
Rails.cache.delete(@status)
end
def detach_card
@status.preview_cards = []
send_status_update_payload(@status)
Rails.cache.delete(@status)
end
@@ -165,4 +183,10 @@ class FetchLinkCardService < BaseService
def lock_options
{ redis: Redis.current, key: "fetch:#{@url}" }
end
def send_status_update_payload(status)
@payload = InlineRenderer.render(status, nil, :status)
@payload = Oj.dump(event: :update, payload: @payload)
Redis.current.publish('statuscard', @payload)
end
end