-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f1cc5d
commit 1fceae6
Showing
5 changed files
with
70 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
class ActionService | ||
def initialize(conversation) | ||
@conversation = conversation | ||
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? | ||
|
||
@conversation.add_labels(labels) | ||
end | ||
|
||
def assign_best_agent(agent_ids = []) | ||
return unless agent_belongs_to_account?(agent_ids) | ||
|
||
@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 | ||
|
||
private | ||
|
||
def agent_belongs_to_account?(agent_ids) | ||
@account.agents.pluck(:id).include?(agent_ids[0]) | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters