diff --git a/app/controllers/reshares_controller.rb b/app/controllers/reshares_controller.rb index d1511f634..856426ef7 100644 --- a/app/controllers/reshares_controller.rb +++ b/app/controllers/reshares_controller.rb @@ -4,7 +4,7 @@ class ResharesController < ApplicationController def create @reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid]) - if @reshare.save! + if @reshare.save current_user.add_to_streams(@reshare, current_user.aspects) current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author) end diff --git a/app/helpers/reshares_helper.rb b/app/helpers/reshares_helper.rb index f1b23f522..8c6cf0ea6 100644 --- a/app/helpers/reshares_helper.rb +++ b/app/helpers/reshares_helper.rb @@ -1,2 +1,9 @@ module ResharesHelper + def reshare_error_message(reshare) + if @reshare.errors[:root_guid].present? + escape_javascript(@reshare.errors[:root_guid].first) + else + escape_javascript(t('reshares.create.failure')) + end + end end diff --git a/app/views/reshares/create.js.erb b/app/views/reshares/create.js.erb index ec6f7e515..f56a8218c 100644 --- a/app/views/reshares/create.js.erb +++ b/app/views/reshares/create.js.erb @@ -1,4 +1,9 @@ -$('.stream_element#<%=params[:root_guid]%>').addClass('reshared'); -ContentUpdater.addPostToStream( - "<%= escape_javascript(render(:partial => 'shared/stream_element', :locals => {:post => @reshare }))=%>" -); +<% if @reshare.persisted? %> + $('.stream_element#<%=params[:root_guid]%>').addClass('reshared'); + ContentUpdater.addPostToStream( + "<%= escape_javascript(render(:partial => 'shared/stream_element', :locals => {:post => @reshare }))=%>" + ); + <% else %> + Diaspora.widgets.flashes.render({success:false, + notice: "<%= reshare_error_message(@reshare) %>"}); +<% end %> diff --git a/config/locales/diaspora/en-US.yml b/config/locales/diaspora/en-US.yml index 55523b72a..8cb2569f2 100644 --- a/config/locales/diaspora/en-US.yml +++ b/config/locales/diaspora/en-US.yml @@ -26,3 +26,4 @@ attributes: from_id: taken: "is a duplicate of a pre-existing request." + diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index b08d09126..3ca403ccf 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -65,8 +65,10 @@ en: attributes: from_id: taken: "is a duplicate of a pre-existing request." - - + reshare: + attributes: + root_guid: + taken: "You've already reshared that post!" error_messages: helper: invalid_fields: "Invalid Fields" @@ -579,7 +581,9 @@ en: few: "%{count} new requests!" many: "%{count} new requests!" other: "%{count} new requests!" - + reshares: + create: + failure: "There was an error resharing this post." services: index: logged_in_as: "logged in as" diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index 41e44f1db..bd393d873 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -47,3 +47,5 @@ en: comments: show: "show all comments" hide: "hide comments" + reshares: + duplicate:"You've already reshared that post!"