diff --git a/db/manifest b/db/manifest index 0fc258a88..e51930a82 100755 --- a/db/manifest +++ b/db/manifest @@ -242,3 +242,4 @@ active_jam_track.sql bpms_on_tap_in.sql jamtracks_job.sql text_messages.sql +text_message_migration.sql \ No newline at end of file diff --git a/db/up/text_message_migration.sql b/db/up/text_message_migration.sql new file mode 100644 index 000000000..c4603c307 --- /dev/null +++ b/db/up/text_message_migration.sql @@ -0,0 +1,5 @@ +insert into text_messages(source_user_id, target_user_id, message, created_at, updated_at) ( + select source_user_id, target_user_id, message, created_at, updated_at + from notifications + where description='TEXT_MESSAGE' +); \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/text_message.rb b/ruby/lib/jam_ruby/models/text_message.rb index 64ef56e4c..c4a3a3d07 100644 --- a/ruby/lib/jam_ruby/models/text_message.rb +++ b/ruby/lib/jam_ruby/models/text_message.rb @@ -41,9 +41,10 @@ module JamRuby tm.message = sanitized_text tm.target_user_id = target_user_id tm.source_user_id = source_user_id + tm.save # send notification - @notification = Notification.send_text_message(sanitized_text, source_user_id, User.find_by_id(target_user_id)) + @notification = Notification.send_text_message(sanitized_text, User.find(source_user_id), User.find(target_user_id)) tm end diff --git a/web/app/assets/javascripts/dialog/textMessageDialog.js b/web/app/assets/javascripts/dialog/textMessageDialog.js index 62b3b68f9..d83f0efb5 100644 --- a/web/app/assets/javascripts/dialog/textMessageDialog.js +++ b/web/app/assets/javascripts/dialog/textMessageDialog.js @@ -37,14 +37,14 @@ } function buildParams() { - return { type: 'TEXT_MESSAGE', receiver: otherId, offset: offset, limit: LIMIT}; + return { target_user_id: otherId, offset: offset, limit: LIMIT}; } function buildMessage() { var message = {}; message['message'] = $textBox.val(); - message['receiver'] = otherId; + message['target_user_id'] = otherId; return message; } @@ -66,17 +66,17 @@ $sendTextMessage.text('SENDING...') rest.createTextMessage(buildMessage()) - .done(function() { - $textBox.val(''); - renderMessage(msg, user.id, user.name, new Date().toISOString(), true); - }) - .fail(function(jqXHR) { - app.notifyServerError(jqXHR, 'Unable to Send Message'); - }) - .always(function() { - sendingMessage = false; - $sendTextMessage.text('SEND'); - }) + .done(function() { + $textBox.val(''); + renderMessage(msg, user.id, user.name, new Date().toISOString(), true); + }) + .fail(function(jqXHR) { + app.notifyServerError(jqXHR, 'Unable to Send Message'); + }) + .always(function() { + sendingMessage = false; + $sendTextMessage.text('SEND'); + }); } return false; @@ -163,8 +163,7 @@ } $sendTextMessage.click(sendMessage); - // TODO: PULL FROM NEW TABLE - rest.getNotifications(buildParams()) + rest.getTextMessages(buildParams()) .done(function (response) { context._.each(response, function (textMessage) { renderMessage(textMessage.message, textMessage.source_user_id, userLookup[textMessage.source_user_id].name, textMessage.created_at); diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index 37951e687..29b5fe284 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -1258,12 +1258,11 @@ }); } - // TODO: push into new table function createTextMessage(options) { var id = getId(options); return $.ajax({ type: "POST", - url: '/api/users/' + id + '/notifications', + url: '/api/text_messages', dataType: "json", contentType: 'application/json', data: JSON.stringify(options) @@ -1275,7 +1274,7 @@ var id = getId(options); return $.ajax({ type: "GET", - url: '/api/users/' + id + '/text_messages?' + $.param(options), + url: '/api/text_messages?' + $.param(options), dataType: "json", contentType: 'application/json' }); @@ -1587,6 +1586,7 @@ this.tweet = tweet; this.createFbInviteUrl = createFbInviteUrl; this.createTextMessage = createTextMessage; + this.getTextMessages = getTextMessages; this.getNotifications = getNotifications; this.createChatMessage = createChatMessage; this.getChatMessages = getChatMessages; diff --git a/web/app/controllers/api_text_messages_controller.rb b/web/app/controllers/api_text_messages_controller.rb index 79496988b..2cf919690 100644 --- a/web/app/controllers/api_text_messages_controller.rb +++ b/web/app/controllers/api_text_messages_controller.rb @@ -2,17 +2,17 @@ require 'sanitize' class ApiTextMessagesController < ApiController before_filter :api_signed_in_user - before_filter :auth_user, :only => [:index, :create] respond_to :json def index - @text_messages = TextMessage.index(params[:target_user_id], @user.id, {:offset => params[:offset]}) + @text_messages = TextMessage.index(params[:target_user_id], current_user.id, {:offset => params[:offset]}) respond_with @text_messages, responder: ApiResponder, :status => 200 end def create - + @text_message = TextMessage.create(params[:message], params[:target_user_id], current_user.id) + respond_with_model(@text_message, new: true) end end \ No newline at end of file diff --git a/web/app/views/api_text_messages/create.rabl b/web/app/views/api_text_messages/create.rabl deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/spec/features/find_sessions_spec.rb b/web/spec/features/find_sessions_spec.rb index 043fdd2ab..5853c13ce 100644 --- a/web/spec/features/find_sessions_spec.rb +++ b/web/spec/features/find_sessions_spec.rb @@ -194,7 +194,7 @@ describe "Find Session", :js => true, :type => :feature, :capybara_feature => tr describe "start session behavior" do before(:each) do - stub_const("APP_CONFIG", web_config) + @music_session = FactoryGirl.create(:music_session, creator: user) @invited_user = FactoryGirl.create(:user) @@ -209,7 +209,6 @@ describe "Find Session", :js => true, :type => :feature, :capybara_feature => tr it "should always show start session link for session creator" do pending - # sign in as creator fast_signin(user, Nav.find_session) find("#sessions-scheduled .rsvp-msg span.text a.start", text: "Start session now?") fast_signout