diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 9a090992dbffdc646a50a8a89dd41ab981038e88..04f019fc1bdd5d94c8efadef5c8fb20f5937ce2f 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -34,6 +34,11 @@ class PhotosController < ApplicationController def create begin + + if params[:photo][:aspect_ids] == "all" + params[:photo][:aspect_ids] = current_user.aspects.collect{|x| x.id} + end + params[:photo][:user_file] = file_handler(params) @photo = current_user.build_post(:photo, params[:photo]) @@ -41,7 +46,7 @@ class PhotosController < ApplicationController if @photo.save raise 'MongoMapper failed to catch a failed save' unless @photo.id - current_user.dispatch_post(@photo, :to => params[:photo][:to]) unless @photo.pending + current_user.dispatch_post(@photo, :to => params[:photo][:aspect_ids]) unless @photo.pending respond_to do |format| format.json{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )} end diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 1581df0de06c11318c5cca2202b6f2d697e45588..88ec060267fe1d15389c4e378b6f1d1758a5579c 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -9,6 +9,11 @@ class StatusMessagesController < ApplicationController respond_to :json, :only => :show def create + + if params[:status_message][:aspect_ids] == "all" + params[:status_message][:aspect_ids] = current_user.aspects.collect{|x| x.id} + end + photos = Photo.all(:id.in => [*params[:photos]], :diaspora_handle => current_user.person.diaspora_handle) public_flag = params[:status_message][:public] @@ -21,10 +26,10 @@ class StatusMessagesController < ApplicationController raise 'MongoMapper failed to catch a failed save' unless @status_message.id @status_message.photos += photos unless photos.nil? - current_user.dispatch_post(@status_message, :to => params[:status_message][:to]) + current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids]) for photo in photos - current_user.dispatch_post(photo, :to => params[:status_message][:to]) + current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids]) end respond_to do |format| diff --git a/app/models/post.rb b/app/models/post.rb index 1037cc3fe7b6dcde69fd07592cb74a7d3aebd962..d6c251540ab221623987599007edbc418a1427cf 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -21,8 +21,10 @@ class Post key :diaspora_handle, String key :user_refs, Integer, :default => 0 key :pending, Boolean, :default => false + key :aspect_ids, Array, :typecast => 'ObjectId' many :comments, :class_name => 'Comment', :foreign_key => :post_id, :order => 'created_at ASC' + many :aspects, :in => :aspect_ids, :class_name => 'Aspect' belongs_to :person, :class_name => 'Person' timestamps! @@ -38,6 +40,7 @@ class Post def self.instantiate params new_post = self.new params.to_hash new_post.person = params[:person] + new_post.aspect_ids = params[:aspect_ids] new_post.public = params[:public] new_post.pending = params[:pending] new_post.diaspora_handle = new_post.person.diaspora_handle diff --git a/app/views/photos/_new_photo.haml b/app/views/photos/_new_photo.haml index f17a3a0b424ac195fce896a22143e9f5da6180c3..2276cf02ac9a62ebc39f43e0ef93f25f3592f285 100644 --- a/app/views/photos/_new_photo.haml +++ b/app/views/photos/_new_photo.haml @@ -6,7 +6,7 @@ function createUploader(){ var uploader = new qq.FileUploaderBasic({ element: document.getElementById('file-upload'), - params: {'photo' : {'pending' : 'true', 'to' : "#{aspect_id}"}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"}, + params: {'photo' : {'pending' : 'true', 'aspect_ids' : "#{aspect_id}"}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"}, allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'], action: "#{photos_path}", debug: true, diff --git a/app/views/shared/_author_info.html.haml b/app/views/shared/_author_info.html.haml index 1679c1bc249e4b5ac98d262d3773a3cd572ab4ee..da8d30184c85e227345a63df05385a99c5a9e9fd 100644 --- a/app/views/shared/_author_info.html.haml +++ b/app/views/shared/_author_info.html.haml @@ -10,7 +10,7 @@ - if post.public? =t('the_world') - else - - for aspect in current_user.aspects_with_post( post.id ) + - for aspect in post.aspects %li= link_to aspect.name, aspect #person_nav_links diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index b5896bee0df65cbcddd8406b91344165f9e54dc7..ab6af1300b509c5cf64aa3459d506a9d69131c31 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -47,7 +47,7 @@ = status.label :message, t('.post_a_message_to', :aspect => (aspect == :all ? t('.all_contacts') : aspect)) = status.text_area :message, :rows => 2, :value => params[:prefill] - = status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id) + = status.hidden_field :aspect_ids, :value => (aspect == :all ? aspect : aspect.id) .options_and_submit diff --git a/app/views/shared/_reshare.haml b/app/views/shared/_reshare.haml index a479dddefcc8570fa320d167e02802ecdaf70e31..71625f7cf42ff61f2dc39952b2ef4f74622f13e2 100644 --- a/app/views/shared/_reshare.haml +++ b/app/views/shared/_reshare.haml @@ -2,16 +2,11 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -- unless current_user.aspects.size == current_user.aspects_with_post(post.id).size - .reshare_pane - %span.reshare_button - = link_to t('.reshare'), "#" +.reshare_pane + %span.reshare_button + = link_to t('.reshare'), "#" + + %ul.reshare_box + - for aspect in current_user.aspects + %li.aspect_to_share= link_to aspect, :controller => "aspects", :action => "show", :id => aspect.id, :prefill => post.message - %ul.reshare_box - - for aspect in current_user.aspects - - unless aspect.posts.include? post - %li.aspect_to_share= link_to aspect, :controller => "aspects", :action => "show", :id => aspect.id, :prefill => post.message -- else - .reshare_pane - %span.reshare_button - = link_to t('.reshare'), "#", :class => "inactive" diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 6fcd30826d045068e862dcfb0f412c6de5b12cfc..524bd465eabd8d6d0eae8ad48203c11d8906f9b4 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -17,7 +17,7 @@ - if post.public? %li= t('the_world') - else - - for aspect in aspects.select{|a| a.post_ids.include?(post.id)} + - for aspect in post.aspects %li= link_to aspect.name, aspect .right diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index 77408d3d26fc9837caea00a58775190345133008..3d87eeb9907da0f87073c9db5719709c519a74a1 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -25,7 +25,7 @@ describe StatusMessagesController do {:status_message =>{ :public =>"true", :message =>"facebook, is that you?", - :to =>"#{aspect.id}"}} + :aspect_ids =>"#{aspect.id}"}} } it "doesn't overwrite person_id" do