Class: OpportunityBriefing::BroadcastUpdate

Inherits:
Object
  • Object
show all
Includes:
Service
Defined in:
app/services/opportunity_briefing/broadcast_update.rb

Overview

Pushes the canonical briefing state back to open Opportunity and Quote pages.

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Service

#attributes_used, #build_result, call, #logger

Methods included from Service::Initializer

#initialize

Class Method Details

.stream_for(opportunity:) ⇒ String

Parameters:

Returns:

  • (String)


16
17
18
# File 'app/services/opportunity_briefing/broadcast_update.rb', line 16

def stream_for(opportunity:)
  "opportunity_ai_briefing:#{opportunity.id}"
end

.target_for(opportunity:, focus_quote: nil) ⇒ String

Parameters:

Returns:

  • (String)


23
24
25
26
# File 'app/services/opportunity_briefing/broadcast_update.rb', line 23

def target_for(opportunity:, focus_quote: nil)
  suffix = focus_quote ? "quote-#{focus_quote.id}" : 'opportunity'
  "opportunity-ai-briefing-#{opportunity.id}-#{suffix}"
end

Instance Method Details

#callObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/opportunity_briefing/broadcast_update.rb', line 29

def call
  return Result.new unless opportunity

  focus_quote = opportunity.quotes.find_by(id: conversation.opportunity_briefing_focus_quote_id)
  pages = [nil]
  pages << focus_quote if focus_quote

  pages.each do |page_focus_quote|
    broadcast(page_focus_quote)
  end

  Result.new(broadcast_count: pages.size)
end