2014-04-23 12:27:49 +00:00
|
|
|
class ApiChatsController < ApiController
|
|
|
|
|
|
|
|
|
|
before_filter :api_signed_in_user, :check_session
|
|
|
|
|
|
|
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
|
|
def create
|
2016-04-06 02:23:15 +00:00
|
|
|
|
2016-04-21 14:23:29 +00:00
|
|
|
@chat_msg = ChatMessage.create(current_user, @music_session, params[:message], params[:channel], params[:client_id], @target_user, @lesson_session)
|
2014-04-23 12:27:49 +00:00
|
|
|
|
|
|
|
|
respond_with_model(@chat_msg)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def index
|
2014-05-02 16:30:56 +00:00
|
|
|
data = ChatMessage.index(current_user, params)
|
|
|
|
|
@chats = data[0]
|
|
|
|
|
@next = data[1]
|
|
|
|
|
render "api_chats/index", :layout => nil
|
2014-04-23 12:27:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_session
|
2016-02-01 20:14:06 +00:00
|
|
|
if params.has_key?(:music_session) || params[:channel] == 'session'
|
2016-01-30 22:08:54 +00:00
|
|
|
@music_session = ActiveMusicSession.find(params[:music_session])
|
|
|
|
|
if @music_session.nil?
|
|
|
|
|
raise ArgumentError, 'specified session not found'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
unless @music_session.access? current_user
|
|
|
|
|
raise JamPermissionError, 'not allowed to join the specified session'
|
|
|
|
|
end
|
2014-04-23 12:27:49 +00:00
|
|
|
end
|
|
|
|
|
|
2016-04-21 14:23:29 +00:00
|
|
|
if params.has_key?(:lesson_session)
|
|
|
|
|
@lesson_session = LessonSession.find(params[:lesson_session])
|
|
|
|
|
if @lesson_session.nil?
|
|
|
|
|
raise ArgumentError, 'specified lesson session not found'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
unless @lesson_session.access? current_user
|
|
|
|
|
raise JamPermissionError, 'not allowed to join the specified lesson session'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@target_user = User.find(params[:target_user]) if params[:target_user]
|
|
|
|
|
end
|
|
|
|
|
|
2014-04-23 12:27:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|