chore: Use Round Robin service for team assignment (#4237)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Sojan Jose
2022-03-28 14:38:07 +05:30
committed by GitHub
parent e8bc30e3c6
commit 823c0ab6a7
6 changed files with 86 additions and 22 deletions

View File

@@ -12,18 +12,19 @@ module AssignmentHandler
def ensure_assignee_is_from_team
return unless team_id_changed?
ensure_current_assignee_team
self.assignee_id ||= find_team_assignee_id_for_inbox if team&.allow_auto_assign.present?
validate_current_assignee_team
self.assignee ||= find_assignee_from_team
end
def ensure_current_assignee_team
def validate_current_assignee_team
self.assignee_id = nil if team&.members&.exclude?(assignee)
end
def find_team_assignee_id_for_inbox
members = inbox.members.ids & team.members.ids
# TODO: User round robin to determine the next agent instead of using sample
members.sample
def find_assignee_from_team
return if team&.allow_auto_assign.blank?
team_members = inbox.members.ids & team.members.ids
::RoundRobin::AssignmentService.new(conversation: self, allowed_member_ids: team_members).find_assignee
end
def notify_assignment_change