2022-07-26 07:11:22 +00:00
|
|
|
class ActionService
|
|
|
|
def initialize(conversation)
|
2022-11-10 05:23:29 +00:00
|
|
|
@conversation = conversation.reload
|
2022-07-26 07:11:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def mute_conversation(_params)
|
|
|
|
@conversation.mute!
|
|
|
|
end
|
|
|
|
|
|
|
|
def snooze_conversation(_params)
|
|
|
|
@conversation.snoozed!
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolve_conversation(_params)
|
|
|
|
@conversation.resolved!
|
|
|
|
end
|
|
|
|
|
|
|
|
def change_status(status)
|
|
|
|
@conversation.update!(status: status[0])
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_label(labels)
|
|
|
|
return if labels.empty?
|
|
|
|
|
2022-11-10 05:23:29 +00:00
|
|
|
@conversation.reload.add_labels(labels)
|
2022-07-26 07:11:22 +00:00
|
|
|
end
|
|
|
|
|
2022-11-15 07:45:27 +00:00
|
|
|
def assign_agent(agent_ids = [])
|
|
|
|
return unless agent_belongs_to_inbox?(agent_ids)
|
2022-07-26 07:11:22 +00:00
|
|
|
|
|
|
|
@agent = @account.users.find_by(id: agent_ids)
|
|
|
|
|
|
|
|
@conversation.update!(assignee_id: @agent.id) if @agent.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def assign_team(team_ids = [])
|
|
|
|
return unless team_belongs_to_account?(team_ids)
|
|
|
|
|
|
|
|
@conversation.update!(team_id: team_ids[0])
|
|
|
|
end
|
|
|
|
|
2022-10-21 02:41:48 +00:00
|
|
|
def send_email_transcript(emails)
|
|
|
|
emails.each do |email|
|
|
|
|
ConversationReplyMailer.with(account: @conversation.account).conversation_transcript(@conversation, email)&.deliver_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-26 07:11:22 +00:00
|
|
|
private
|
|
|
|
|
2022-11-15 07:45:27 +00:00
|
|
|
def agent_belongs_to_inbox?(agent_ids)
|
|
|
|
member_ids = @conversation.inbox.members.pluck(:user_id)
|
|
|
|
assignable_agent_ids = member_ids + @account.administrators.ids
|
|
|
|
|
|
|
|
assignable_agent_ids.include?(agent_ids[0])
|
2022-07-26 07:11:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def team_belongs_to_account?(team_ids)
|
|
|
|
@account.team_ids.include?(team_ids[0])
|
|
|
|
end
|
|
|
|
|
|
|
|
def conversation_a_tweet?
|
|
|
|
return false if @conversation.additional_attributes.blank?
|
|
|
|
|
|
|
|
@conversation.additional_attributes['type'] == 'tweet'
|
|
|
|
end
|
|
|
|
end
|