Class: Api::V1::MessagesController

Inherits:
BaseController show all
Defined in:
app/controllers/api/v1/messages_controller.rb

Instance Attribute Summary

Attributes included from OpenidConnect::ProtectedResourceEndpoint

#current_token

Instance Method Summary collapse

Methods included from OpenidConnect::ProtectedResourceEndpoint

#access_token?, #require_access_token

Instance Method Details

#createObject


14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/api/v1/messages_controller.rb', line 14

def create
  conversation = conversation_service.find!(params.require(:conversation_id))
  text = params.require(:body)
  message = current_user.build_message(conversation, text: text)
  message.save!
  Diaspora::Federation::Dispatcher.defer_dispatch(current_user, message)
  render json: message_json(message), status: :created
rescue ActionController::ParameterMissing
  render_error 422, "Couldn’t accept or process the conversation"
end

#indexObject


25
26
27
28
29
30
# File 'app/controllers/api/v1/messages_controller.rb', line 25

def index
  conversation = conversation_service.find!(params.require(:conversation_id))
  messages_page = index_pager(conversation.messages).response
  messages_page[:data] = messages_page[:data].map {|x| message_json(x) }
  render_paged_api_response messages_page
end