From 67fc4b3157140536cb26e6ebf275889c5d1c22ef Mon Sep 17 00:00:00 2001 From: maxwell Date: Wed, 12 Jan 2011 10:35:05 -0800 Subject: [PATCH] IZ MS fix a nasty bug where status messages with posts were not persisted in a users aspects stream. also, fixed the code link for joindiaspora.com --- app/controllers/photos_controller.rb | 4 +++- app/controllers/status_messages_controller.rb | 10 +++++----- app/models/user.rb | 11 +++++------ lib/postzord/dispatch.rb | 1 + spec/controllers/status_message_controller_spec.rb | 2 +- spec/models/user/posting_spec.rb | 7 ++++--- spec/support/user_methods.rb | 5 +++-- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index f01e71a91..ee5ed172e 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -53,7 +53,9 @@ class PhotosController < ApplicationController if @photo.save raise 'MongoMapper failed to catch a failed save' unless @photo.id - current_user.add_to_streams(@photo, params[:photo][:aspect_ids]) + + aspects = current_user.aspects_from_ids(params[:photo][:aspect_ids]) + current_user.add_to_streams(@photo, aspects) current_user.dispatch_post(@photo, :to => params[:photo][:aspect_ids]) unless @photo.pending if params[:photo][:set_profile_photo] diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 0856aa73c..265a5adec 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -17,21 +17,21 @@ class StatusMessagesController < ApplicationController public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false params[:status_message][:public] = public_flag @status_message = current_user.build_post(:status_message, params[:status_message]) - + aspects = current_user.aspects_from_ids(params[:aspect_ids]) if photos || @status_message.save!(:safe => true) raise 'MongoMapper failed to catch a failed save' unless @status_message.id @status_message.photos += photos unless photos.nil? - current_user.add_to_streams(@status_message, params[:status_message][:aspect_ids]) - current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids], :url => post_url(@status_message)) + current_user.add_to_streams(@status_message, aspects) + current_user.dispatch_post(@status_message, :url => post_url(@status_message)) for photo in photos photo.public = public_flag photo.save - current_user.add_to_streams(photo, params[:status_message][:aspect_ids]) - current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids]) + current_user.add_to_streams(photo, aspects) + current_user.dispatch_post(photo) end respond_to do |format| diff --git a/app/models/user.rb b/app/models/user.rb index 6b1eacaf3..10e9099bb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -156,19 +156,18 @@ class User Rails.logger.debug("Saving post: #{post}") post.user_refs += 1 post.save - aspects = self.aspects_with_person(post.person) - self.add_to_streams(post, aspects.map{|x| x.id} ) + aspects_to_insert = self.aspects_with_person(post.person) + self.add_to_streams(post, aspects_to_insert) post end - def add_to_streams(post, aspect_ids) + def add_to_streams(post, aspects_to_insert) self.raw_visible_posts << post self.save - post.socket_to_uid(self, :aspect_ids => aspect_ids) if post.respond_to? :socket_to_uid - target_aspects = aspects_from_ids(aspect_ids) - target_aspects.each do |aspect| + post.socket_to_uid(self, :aspect_ids => aspects_to_insert.map{|x| x.id}) if post.respond_to? :socket_to_uid + aspects_to_insert.each do |aspect| aspect.posts << post aspect.save end diff --git a/lib/postzord/dispatch.rb b/lib/postzord/dispatch.rb index 96db24f0e..0a8d0ed13 100644 --- a/lib/postzord/dispatch.rb +++ b/lib/postzord/dispatch.rb @@ -33,6 +33,7 @@ class Postzord::Dispatch end protected + def deliver_to_remote(people) people.each do |person| enc_xml = @salmon_factory.xml_for(person) diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index cd3497dc6..65509c217 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -30,7 +30,7 @@ describe StatusMessagesController do message = user1.build_post :status_message, :message => @url, :to => aspect1.id message[:youtube_titles]= {@video_id => "title"} message.save! - user1.add_to_streams(message, aspect1.id) + user1.add_to_streams(message, [aspect1]) user1.dispatch_post message, :to => aspect1.id get :show, :id => message.id diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 8750736a6..ca2aaf23c 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -22,24 +22,25 @@ describe User do @post = user.build_post(:status_message, @params) @post.save @aspect_ids = @params[:to] + @aspects = user.aspects_from_ids(@aspect_ids) end it 'saves post into visible post ids' do proc { - user.add_to_streams(@post, @aspect_ids) + user.add_to_streams(@post, @aspects) }.should change(user.raw_visible_posts, :count).by(1) user.reload.raw_visible_posts.should include @post end it 'saves post into each aspect in aspect_ids' do - user.add_to_streams(@post, @aspect_ids) + user.add_to_streams(@post, @aspects) aspect.reload.post_ids.should include @post.id aspect1.reload.post_ids.should include @post.id end it 'sockets the post to the poster' do @post.should_receive(:socket_to_uid).with(user, anything) - user.add_to_streams(@post, @aspect_ids) + user.add_to_streams(@post, @aspects) end end diff --git a/spec/support/user_methods.rb b/spec/support/user_methods.rb index d0288d7fa..b5facc06d 100644 --- a/spec/support/user_methods.rb +++ b/spec/support/user_methods.rb @@ -21,8 +21,9 @@ class User raise 'MongoMapper failed to catch a failed save' unless p.id self.aspects.reload - - add_to_streams(p, opts[:to]) + + aspects = self.aspects_from_ids(opts[:to]) + add_to_streams(p, aspects) dispatch_post(p, :to => opts[:to]) end p