VRFS-2465 use new table for text messages

This commit is contained in:
Brian Smith 2015-01-12 22:37:07 -05:00
parent 825a293c30
commit 54d0f36319
6 changed files with 23 additions and 24 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -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