Chore: Minor bugfixes and housekeeping tasks (#896)
This commit is contained in:
@@ -50,13 +50,11 @@ class Conversation < ApplicationRecord
|
||||
has_many :messages, dependent: :destroy, autosave: true
|
||||
|
||||
before_create :set_display_id, unless: :display_id?
|
||||
|
||||
before_create :set_bot_conversation
|
||||
|
||||
after_create :notify_conversation_creation
|
||||
after_save :run_round_robin
|
||||
after_update :notify_status_change, :create_activity
|
||||
|
||||
after_create :notify_conversation_creation, :run_round_robin
|
||||
|
||||
acts_as_taggable_on :labels
|
||||
|
||||
def update_assignee(agent = nil)
|
||||
@@ -173,10 +171,24 @@ class Conversation < ApplicationRecord
|
||||
Rails.configuration.dispatcher.dispatch(event_name, Time.zone.now, conversation: self)
|
||||
end
|
||||
|
||||
def should_round_robin?
|
||||
return false unless inbox.enable_auto_assignment?
|
||||
|
||||
# run only if assignee is blank or doesn't have access to inbox
|
||||
assignee.blank? || inbox.members.exclude?(assignee)
|
||||
end
|
||||
|
||||
def conversation_status_changed_to_open?
|
||||
return false unless open?
|
||||
# saved_change_to_status? method only works in case of update
|
||||
return true if previous_changes.key?(:id) || saved_change_to_status?
|
||||
end
|
||||
|
||||
def run_round_robin
|
||||
return unless inbox.enable_auto_assignment
|
||||
return if assignee
|
||||
return if bot?
|
||||
# Round robin kicks in on conversation create & update
|
||||
# run it only when conversation status changes to open
|
||||
return unless conversation_status_changed_to_open?
|
||||
return unless should_round_robin?
|
||||
|
||||
inbox.next_available_agent.then { |new_assignee| update_assignee(new_assignee) }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user