fix: Include waiting on agent conversations to unattended view (#7667)
Updating the `unattended` tab to include conversations where the customer responded and is awaiting an agent's response. Previously it showed only the conversations where the first response was pending. Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -72,7 +72,7 @@ class Conversation < ApplicationRecord
|
||||
scope :unassigned, -> { where(assignee_id: nil) }
|
||||
scope :assigned, -> { where.not(assignee_id: nil) }
|
||||
scope :assigned_to, ->(agent) { where(assignee_id: agent.id) }
|
||||
scope :unattended, -> { where(first_reply_created_at: nil) }
|
||||
scope :unattended, -> { where(first_reply_created_at: nil).or(where.not(waiting_since: nil)) }
|
||||
scope :resolvable, lambda { |auto_resolve_duration|
|
||||
return none if auto_resolve_duration.to_i.zero?
|
||||
|
||||
@@ -218,7 +218,7 @@ class Conversation < ApplicationRecord
|
||||
end
|
||||
|
||||
def ensure_waiting_since
|
||||
self.waiting_since = Time.now.utc
|
||||
self.waiting_since = created_at
|
||||
end
|
||||
|
||||
def validate_additional_attributes
|
||||
@@ -242,7 +242,8 @@ class Conversation < ApplicationRecord
|
||||
|
||||
def allowed_keys?
|
||||
(
|
||||
previous_changes.keys.intersect?(%w[team_id assignee_id status snoozed_until custom_attributes label_list first_reply_created_at priority]) ||
|
||||
previous_changes.keys.intersect?(%w[team_id assignee_id status snoozed_until custom_attributes label_list waiting_since first_reply_created_at
|
||||
priority]) ||
|
||||
(previous_changes['additional_attributes'].present? && previous_changes['additional_attributes'][1].keys.intersect?(%w[conversation_language]))
|
||||
)
|
||||
end
|
||||
|
||||
@@ -247,7 +247,6 @@ class Message < ApplicationRecord
|
||||
send_reply
|
||||
execute_message_template_hooks
|
||||
update_contact_activity
|
||||
update_waiting_since
|
||||
end
|
||||
|
||||
def update_contact_activity
|
||||
@@ -261,7 +260,7 @@ class Message < ApplicationRecord
|
||||
)
|
||||
conversation.update(waiting_since: nil)
|
||||
end
|
||||
conversation.update(waiting_since: Time.now.utc) if incoming? && conversation.waiting_since.blank?
|
||||
conversation.update(waiting_since: created_at) if incoming? && conversation.waiting_since.blank?
|
||||
end
|
||||
|
||||
def human_response?
|
||||
@@ -276,8 +275,12 @@ class Message < ApplicationRecord
|
||||
|
||||
def dispatch_create_events
|
||||
Rails.configuration.dispatcher.dispatch(MESSAGE_CREATED, Time.zone.now, message: self, performed_by: Current.executed_by)
|
||||
|
||||
if valid_first_reply?
|
||||
Rails.configuration.dispatcher.dispatch(FIRST_REPLY_CREATED, Time.zone.now, message: self, performed_by: Current.executed_by)
|
||||
conversation.update(first_reply_created_at: created_at, waiting_since: nil)
|
||||
else
|
||||
update_waiting_since
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user