From cfcbe707e3cdafad4b6d2ffc3aa10cdaf0d03ccb Mon Sep 17 00:00:00 2001 From: Pranav Date: Tue, 14 Jul 2026 16:30:03 -0700 Subject: [PATCH] refactor(captain): simplify reopen engagement check in Enterprise::Message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The respond_to?(:captain_assistant) guard was redundant — the enterprise message override and the inbox concern defining the association are loaded under the same enterprise gate, so the association always exists here. --- enterprise/app/models/enterprise/message.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/enterprise/app/models/enterprise/message.rb b/enterprise/app/models/enterprise/message.rb index 69b4db8fe..b5386a16c 100644 --- a/enterprise/app/models/enterprise/message.rb +++ b/enterprise/app/models/enterprise/message.rb @@ -15,22 +15,16 @@ module Enterprise::Message private - # On reopen, a Captain inbox would normally re-pend the conversation for the bot. When the - # assistant won't engage (contact outside audience, or off-schedule), route to the human queue - # (open) instead of pending. def reopen_resolved_conversation - return conversation.open! if captain_should_not_engage? + captain_assistant = conversation.inbox.captain_assistant + + return super if captain_assistant.blank? + + return conversation.open! unless captain_assistant.engages?(conversation.contact, conversation) super end - def captain_should_not_engage? - inbox = conversation.inbox - inbox.respond_to?(:captain_assistant) && - inbox.captain_assistant.present? && - !inbox.captain_assistant.engages?(conversation.contact, conversation) - end - def mark_pending_conversation_as_open_for_human_response return unless captain_pending_conversation? return unless human_response?