fix: assignee_changed callback not getting triggered during conversation creation (#9334)
The reload method in our callback was refreshing the object and hence the saved_change_to_assignee_id? Method wasn't working in the following callbacks. This impacted the listeners subscribing to the event `ASSIGNEE_CHANGE`, `TEAM_CHANGE` etc
This commit is contained in:
@@ -10,14 +10,15 @@ class AsyncDispatcher < BaseDispatcher
|
||||
|
||||
def listeners
|
||||
[
|
||||
AutomationRuleListener.instance,
|
||||
CampaignListener.instance,
|
||||
CsatSurveyListener.instance,
|
||||
HookListener.instance,
|
||||
InstallationWebhookListener.instance,
|
||||
NotificationListener.instance,
|
||||
ParticipationListener.instance,
|
||||
ReportingEventListener.instance,
|
||||
WebhookListener.instance,
|
||||
AutomationRuleListener.instance
|
||||
WebhookListener.instance
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
8
app/listeners/participation_listener.rb
Normal file
8
app/listeners/participation_listener.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class ParticipationListener < BaseListener
|
||||
include Events::Types
|
||||
|
||||
def assignee_changed(event)
|
||||
conversation, _account = extract_conversation_and_account(event)
|
||||
conversation.conversation_participants.find_or_create_by!(user_id: conversation.assignee_id) if conversation.assignee_id.present?
|
||||
end
|
||||
end
|
||||
@@ -38,7 +38,6 @@ module AssignmentHandler
|
||||
|
||||
def process_assignment_changes
|
||||
process_assignment_activities
|
||||
process_participant_assignment
|
||||
end
|
||||
|
||||
def process_assignment_activities
|
||||
@@ -49,10 +48,4 @@ module AssignmentHandler
|
||||
create_assignee_change_activity(user_name)
|
||||
end
|
||||
end
|
||||
|
||||
def process_participant_assignment
|
||||
return unless saved_change_to_assignee_id? && assignee_id.present?
|
||||
|
||||
conversation_participants.find_or_create_by!(user_id: assignee_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,6 @@ module AutoAssignmentHandler
|
||||
return unless should_run_auto_assignment?
|
||||
|
||||
::AutoAssignment::AgentAssignmentService.new(conversation: self, allowed_agent_ids: inbox.member_ids_with_assignment_capacity).perform
|
||||
conversation_participants.find_or_create_by(user_id: assignee_id) if assignee_id.present?
|
||||
end
|
||||
|
||||
def should_run_auto_assignment?
|
||||
|
||||
@@ -110,7 +110,7 @@ class Conversation < ApplicationRecord
|
||||
|
||||
after_update_commit :execute_after_update_commit_callbacks
|
||||
after_create_commit :notify_conversation_creation
|
||||
after_commit :set_display_id, unless: :display_id?
|
||||
after_create_commit :load_attributes_created_by_db_triggers
|
||||
|
||||
delegate :auto_resolve_duration, to: :account
|
||||
|
||||
@@ -257,8 +257,13 @@ class Conversation < ApplicationRecord
|
||||
assignee_id.present? && Current.user&.id == assignee_id
|
||||
end
|
||||
|
||||
def set_display_id
|
||||
reload
|
||||
def load_attributes_created_by_db_triggers
|
||||
# Display id is set via a trigger in the database
|
||||
# So we need to specifically fetch it after the record is created
|
||||
# We can't use reload because it will clear the previous changes, which we need for the dispatcher
|
||||
obj_from_db = self.class.find(id)
|
||||
self[:display_id] = obj_from_db[:display_id]
|
||||
self[:uuid] = obj_from_db[:uuid]
|
||||
end
|
||||
|
||||
def notify_status_change
|
||||
|
||||
Reference in New Issue
Block a user