feat: add activity message for priority change (#6933)
* feat: add priority const * feat: add toggle priority method * feat: update controller route and specs * refactor: status change method * refactor: abstract label change and mute activity * feat: add priority change_activity * fix: interpolation for previous_changes * refactor: reduce cognitive complexity of priority_change_activity * refactor: move priority activity message handler to a separate module * refactor: move typing logic to a service * refactor: tests to reduce complexity * fix: typo * fix: constants * fix: priority conditions * fix: add a response * fix: argument destructuring in I18n.t --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
33
app/models/concerns/priority_activity_message_handler.rb
Normal file
33
app/models/concerns/priority_activity_message_handler.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
module PriorityActivityMessageHandler
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
private
|
||||
|
||||
def priority_change_activity(user_name)
|
||||
old_priority, new_priority = previous_changes.values_at('priority')[0]
|
||||
return unless priority_change?(old_priority, new_priority)
|
||||
|
||||
user = Current.executed_by.instance_of?(AutomationRule) ? 'Automation System' : user_name
|
||||
content = build_priority_change_content(user, old_priority, new_priority)
|
||||
|
||||
::Conversations::ActivityMessageJob.perform_later(self, activity_message_params(content)) if content
|
||||
end
|
||||
|
||||
def priority_change?(old_priority, new_priority)
|
||||
old_priority.present? || new_priority.present?
|
||||
end
|
||||
|
||||
def build_priority_change_content(user_name, old_priority = nil, new_priority = nil)
|
||||
change_type = get_priority_change_type(old_priority, new_priority)
|
||||
|
||||
I18n.t("conversations.activity.priority.#{change_type}", user_name: user_name, new_priority: new_priority, old_priority: old_priority)
|
||||
end
|
||||
|
||||
def get_priority_change_type(old_priority, new_priority)
|
||||
case [old_priority.present?, new_priority.present?]
|
||||
when [true, true] then 'updated'
|
||||
when [false, true] then 'added'
|
||||
when [true, false] then 'removed'
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user