From 0e2d577d43fa72a3b0c7c5fce895066c712fe88e Mon Sep 17 00:00:00 2001 From: Pranav Date: Tue, 14 Jul 2026 16:40:17 -0700 Subject: [PATCH] refactor(captain): tidy comments and naming in assistant engagement code --- enterprise/app/models/captain/assistant.rb | 12 +++--------- enterprise/app/models/enterprise/message.rb | 6 +++--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/enterprise/app/models/captain/assistant.rb b/enterprise/app/models/captain/assistant.rb index 1b1b05c87..462ad8134 100644 --- a/enterprise/app/models/captain/assistant.rb +++ b/enterprise/app/models/captain/assistant.rb @@ -58,30 +58,24 @@ class Captain::Assistant < ApplicationRecord name end - # Whether this assistant should engage the given conversation right now — combines the audience - # filter (who) and the schedule (when). def engages?(contact, conversation) responds_to_audience?(contact, conversation) && available_now?(conversation) end - # Whether this assistant should engage the given contact, based on its audience filter. - # No audience configured => responds to everyone (back-compat). def responds_to_audience?(contact, conversation) return true if config['audience'].blank? Captain::AudienceMatcher.new(config['audience']).matches?(contact, conversation) end - # Whether the assistant is on duty for this conversation based on the response window. - # Inboxes without business hours configured are always covered (fail open). def available_now?(conversation) - window = config['response_window'] - return true if window.blank? || window == 'always' + response_window = config['response_window'] + return true if response_window.blank? || response_window == 'always' inbox = conversation.inbox return true unless inbox.working_hours_enabled? - window == 'business_hours' ? !inbox.out_of_office? : inbox.out_of_office? + response_window == 'business_hours' ? !inbox.out_of_office? : inbox.out_of_office? end def available_agent_tools diff --git a/enterprise/app/models/enterprise/message.rb b/enterprise/app/models/enterprise/message.rb index b5386a16c..6a73e0e0a 100644 --- a/enterprise/app/models/enterprise/message.rb +++ b/enterprise/app/models/enterprise/message.rb @@ -16,11 +16,11 @@ module Enterprise::Message private def reopen_resolved_conversation - captain_assistant = conversation.inbox.captain_assistant + assistant = conversation.inbox.captain_assistant - return super if captain_assistant.blank? + return super if assistant.blank? - return conversation.open! unless captain_assistant.engages?(conversation.contact, conversation) + return conversation.open! unless assistant.engages?(conversation.contact, conversation) super end