private message sending changed to ajax

added specs for change in controller

one form of hash used in single line of code

rendering create response on sending message

redirect user to conversation page if message sent successfully

removed deprecated way of rendering file

conversations create for mobile fixed

minor code style change

updated changelog
This commit is contained in:
kevivmatrix 2013-06-15 13:59:35 +05:30
parent 091951a929
commit 6623e86a5a
6 changed files with 49 additions and 9 deletions

View file

@ -44,6 +44,7 @@
* Leaving the `to` field blank when sending a private message causes a server error [#4227](https://github.com/diaspora/diaspora/issues/4227) * Leaving the `to` field blank when sending a private message causes a server error [#4227](https://github.com/diaspora/diaspora/issues/4227)
* Fix hashtags that start a line when posting to Facebook or Twitter [#3768](https://github.com/diaspora/diaspora/issues/3768) [#4154](https://github.com/diaspora/diaspora/issues/4154) * Fix hashtags that start a line when posting to Facebook or Twitter [#3768](https://github.com/diaspora/diaspora/issues/3768) [#4154](https://github.com/diaspora/diaspora/issues/4154)
* Show avatar of recent user in conversation list [#4237](https://github.com/diaspora/diaspora/issues/4237) * Show avatar of recent user in conversation list [#4237](https://github.com/diaspora/diaspora/issues/4237)
* Private message fails if contact not entered correctly [#4210](https://github.com/diaspora/diaspora/issues/4210)
## Features ## Features

View file

@ -29,7 +29,7 @@ var View = {
/* Clear forms after successful submit, this is some legacy dan hanson stuff, do we still want it? */ /* Clear forms after successful submit, this is some legacy dan hanson stuff, do we still want it? */
$.fn.clearForm = function() { $.fn.clearForm = function() {
return this.each(function() { return this.each(function() {
if ($(this).is('form')) { if ($(this).is('form') && !$(this).hasClass('form_do_not_clear')) {
return $(':input', this).clearForm(); return $(':input', this).clearForm();
} }
if ($(this).hasClass('clear_on_submit') || $(this).is(':text') || $(this).is(':password') || $(this).is('textarea')) { if ($(this).hasClass('clear_on_submit') || $(this).is(':text') || $(this).is(':password') || $(this).is('textarea')) {

View file

@ -39,20 +39,22 @@ class ConversationsController < ApplicationController
message_text = params[:conversation].delete(:text) message_text = params[:conversation].delete(:text)
params[:conversation][:messages_attributes] = [ {:author => current_user.person, :text => message_text }] params[:conversation][:messages_attributes] = [ {:author => current_user.person, :text => message_text }]
@response = {}
@conversation = Conversation.new(params[:conversation]) @conversation = Conversation.new(params[:conversation])
if person_ids.present? && @conversation.save if person_ids.present? && @conversation.save
Postzord::Dispatcher.build(current_user, @conversation).post Postzord::Dispatcher.build(current_user, @conversation).post
flash[:notice] = I18n.t('conversations.create.sent') @response[:success] = true
@response[:message] = I18n.t('conversations.create.sent')
@response[:conversation_id] = @conversation.id
else else
flash[:error] = I18n.t('conversations.create.fail') @response[:success] = false
@response[:message] = I18n.t('conversations.create.fail')
if person_ids.blank? if person_ids.blank?
flash[:error] = I18n.t('conversations.create.no_contact') @response[:message] = I18n.t('conversations.create.no_contact')
end end
end end
if params[:profile] respond_to do |format|
redirect_to person_path(params[:profile]) format.js
else
redirect_to conversations_path(:conversation_id => @conversation.id)
end end
end end

View file

@ -0,0 +1,11 @@
var response = <%= raw @response.to_json %>;
<% if session[:mobile_view] %>
window.location.href = "<%= conversations_path(conversation_id: @conversation.id) %>";
<% else %>
Diaspora.page.flashMessages.render({ 'success':response.success, 'notice':response.message });
if(response.success){
$("#new_conversation").removeClass('form_do_not_clear').clearForm();
$.facebox.close();
window.location.href = "<%= conversations_path(conversation_id: @conversation.id) %>";
}
<% end %>

View file

@ -32,7 +32,7 @@
%h3 %h3
= t('conversations.index.new_message') = t('conversations.index.new_message')
= form_for Conversation.new do |conversation| = form_for Conversation.new, html: {class: "new_conversation form_do_not_clear"}, remote: true do |conversation|
.span-2 .span-2
%h4 %h4

View file

@ -97,6 +97,13 @@ describe ConversationsController do
}.should change(Message, :count).by(1) }.should change(Message, :count).by(1)
end end
it 'should set response with success to true and message to success message' do
post :create, @hash
assigns[:response][:success].should == true
assigns[:response][:message].should == I18n.t('conversations.create.sent')
assigns[:response][:conversation_id].should == Conversation.first.id
end
it 'sets the author to the current_user' do it 'sets the author to the current_user' do
@hash[:author] = FactoryGirl.create(:user) @hash[:author] = FactoryGirl.create(:user)
post :create, @hash post :create, @hash
@ -143,6 +150,13 @@ describe ConversationsController do
post :create, @hash post :create, @hash
}.should change(Message, :count).by(1) }.should change(Message, :count).by(1)
end end
it 'should set response with success to true and message to success message' do
post :create, @hash
assigns[:response][:success].should == true
assigns[:response][:message].should == I18n.t('conversations.create.sent')
assigns[:response][:conversation_id].should == Conversation.first.id
end
end end
context 'with empty text' do context 'with empty text' do
@ -167,6 +181,12 @@ describe ConversationsController do
post :create, @hash post :create, @hash
}.should_not change(Message, :count).by(1) }.should_not change(Message, :count).by(1)
end end
it 'should set response with success to false and message to create fail' do
post :create, @hash
assigns[:response][:success].should == false
assigns[:response][:message].should == I18n.t('conversations.create.fail')
end
end end
context 'with empty contact' do context 'with empty contact' do
@ -191,6 +211,12 @@ describe ConversationsController do
post :create, @hash post :create, @hash
}.should_not change(Message, :count).by(1) }.should_not change(Message, :count).by(1)
end end
it 'should set response with success to false and message to fail due to no contact' do
post :create, @hash
assigns[:response][:success].should == false
assigns[:response][:message].should == I18n.t('conversations.create.no_contact')
end
end end
context 'with nil contact' do context 'with nil contact' do