2019-08-14 09:48:44 +00:00
|
|
|
class Api::V1::ConversationsController < Api::BaseController
|
2020-02-17 10:27:57 +00:00
|
|
|
before_action :set_conversation, except: [:index]
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
result = conversation_finder.perform
|
|
|
|
@conversations = result[:conversations]
|
|
|
|
@conversations_count = result[:count]
|
|
|
|
end
|
|
|
|
|
2020-03-08 16:38:25 +00:00
|
|
|
def show; end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
def toggle_status
|
|
|
|
@status = @conversation.toggle_status
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_last_seen
|
|
|
|
@conversation.agent_last_seen_at = parsed_last_seen_at
|
|
|
|
@conversation.save!
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parsed_last_seen_at
|
2019-10-20 08:47:26 +00:00
|
|
|
DateTime.strptime(params[:agent_last_seen_at].to_s, '%s')
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_conversation
|
|
|
|
@conversation ||= current_account.conversations.find_by(display_id: params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def conversation_finder
|
|
|
|
@conversation_finder ||= ConversationFinder.new(current_user, params)
|
|
|
|
end
|
|
|
|
end
|