Chatwoot/app/controllers/api/v1/conversations_controller.rb
Tim Lange fc23a10a99
Chore: Added tests for conversations_controller (#508)
* Chore: Added tests for conversations_controller
* Chore: Remove get_messages function from conversations
2020-02-17 15:57:57 +05:30

41 lines
938 B
Ruby

class Api::V1::ConversationsController < Api::BaseController
before_action :set_conversation, except: [:index]
def index
result = conversation_finder.perform
@conversations = result[:conversations]
@conversations_count = result[:count]
end
def show
@messages = messages_finder.perform
end
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
DateTime.strptime(params[:agent_last_seen_at].to_s, '%s')
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
def messages_finder
@message_finder ||= MessageFinder.new(@conversation, params)
end
end