diff --git a/Gemfile.lock b/Gemfile.lock index aadcf8be6..966f201cd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -142,7 +142,11 @@ GEM childprocess (0.1.4) ffi (~> 0.6.3) closure-compiler (0.3.3) +<<<<<<< HEAD cloudfiles (1.4.10) +======= + cloudfiles (1.4.9) +>>>>>>> DG MS; status messages can now have photos. mime-types (>= 1.16) columnize (0.3.2) configuration (1.2.0) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 101901daa..1bfabcdc3 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -9,7 +9,7 @@ class AspectsController < ApplicationController respond_to :json, :only => :show def index - @posts = current_user.visible_posts(:by_members_of => :all, :pending => false).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC' + @posts = current_user.visible_posts.paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC' @aspect = :all if current_user.getting_started == true diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 764dcebb6..c4a796462 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -9,7 +9,6 @@ class StatusMessagesController < ApplicationController respond_to :json, :only => :show def create - photos = Photo.all(:id.in => [*params[:photos]]) public_flag = params[:status_message][:public] @@ -17,11 +16,14 @@ class StatusMessagesController < ApplicationController params[:status_message][:public] = public_flag @status_message = current_user.build_post(:status_message, params[:status_message]) - @status_message.photos += photos unless photos.nil? - - puts "got it" if @status_message.save(:safe => true) raise 'MongoMapper failed to catch a failed save' unless @status_message.id + + @status_message.photos += photos unless photos.nil? + for photo in photos + current_user.dispatch_post(photo, :to => params[:status_message][:to]) + end + current_user.dispatch_post(@status_message, :to => params[:status_message][:to]) end diff --git a/app/models/photo.rb b/app/models/photo.rb index 156cba8f7..fc637c284 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -9,19 +9,28 @@ class Photo < Post xml_accessor :remote_photo xml_accessor :caption + xml_reader :status_message_id key :caption, String key :remote_photo_path key :remote_photo_name key :random_string - timestamps! + belongs_to :status_message + attr_accessible :caption + validate :ownership_of_status_message before_destroy :ensure_user_picture + def ownership_of_status_message + if status_message_id + self.diaspora_handle == StatusMessage.find_by_id(self.status_message_id).diaspora_handle + end + end + def self.instantiate(params = {}) photo = super(params) image_file = params.delete(:user_file) diff --git a/app/models/status_message.rb b/app/models/status_message.rb index ecaf49514..c859b165a 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -6,7 +6,7 @@ class StatusMessage < Post validates_length_of :message, :maximum => 1000, :message => "please make your status messages less than 1000 characters" xml_name :status_message - xml_accessor :message + xml_reader :message key :message, String many :photos, :class => Photo diff --git a/app/models/user.rb b/app/models/user.rb index e23e8051e..01862c09f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -161,7 +161,7 @@ class User self.save Rails.logger.info("Pushing: #{post.inspect} out to aspects") push_to_aspects(post, aspect_ids) - post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) + post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) && !post.pending if post.public self.services.each do |service| self.send("post_to_#{service.provider}".to_sym, service, post.message) diff --git a/app/views/photos/_new_photo.haml b/app/views/photos/_new_photo.haml index fd593b52a..f723bedf1 100644 --- a/app/views/photos/_new_photo.haml +++ b/app/views/photos/_new_photo.haml @@ -12,17 +12,23 @@ debug: true, button: document.getElementById('file-upload'), sizeLimit: 5000048, + + onSubmit: function(id, fileName){ - $('#file-upload').text("loading"); + $('#file-upload').addClass("loading"); + $('#publisher').find("input[type='submit']").attr('disabled','disabled'); + $("#publisher .options_and_submit").fadeIn(50); + $("#publisher_spinner").fadeIn(100); }, - onComplete: function(id, fileName, responseJSON){ - $('#file-upload').text("add photos"); + $("#publisher_spinner").fadeOut(100); + $('#file-upload').removeClass("loading"); var id = responseJSON.data.photo.id; var url = responseJSON.data.photo.url; $('#new_status_message').append(""); $('#photodropzone').append("
  • "); + $('#publisher').find("input[type='submit']").removeAttr('disabled'); } }); diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml index 385d85314..9ca39bffa 100644 --- a/app/views/photos/_photo.haml +++ b/app/views/photos/_photo.haml @@ -4,6 +4,9 @@ = link_to (image_tag post.url(:thumb_large)), object_path(post), :class => 'stream_photo' +%h1 + = post.pending + %p.photo_description = post.caption diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index 65e922a07..11bda4b7e 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -11,13 +11,13 @@ }; }); - //$("#publisher textarea, #publisher input").live("focus", function(evt){ - // $("#publisher .options_and_submit").fadeIn(50); - //}); + $("#publisher textarea, #publisher input").live("focus", function(evt){ + $("#publisher .options_and_submit").fadeIn(50); + }); $("#publisher form").live("submit", function(evt){ $("#photodropzone").find('li').remove(); - //$("#publisher").find("input[name='photos[]']").remove(); + $("#publisher .options_and_submit").hide(); }); #publisher @@ -37,10 +37,13 @@ = status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id) .options_and_submit - - if aspect == :all - = status.submit t('.share'), :title => t('.share_with_all'), :disable_with => t('.posting') - - else - = status.submit t('.share'), :title => t('.share_with', :aspect => aspect), :disable_with => t('.posting') + + .right + = image_tag 'ajax-loader.gif', :class => 'hidden', :id => "publisher_spinner" + - if aspect == :all + = status.submit t('.share'), :title => t('.share_with_all'), :disable_with => t('.posting') + - else + = status.submit t('.share'), :title => t('.share_with', :aspect => aspect), :disable_with => t('.posting') - if aspect == :all .public_toggle @@ -57,5 +60,10 @@ .fancybox_content #question_mark_pane = render 'shared/public_explain' + + + + + #publisher_photo_upload = render 'photos/new_photo', :aspect_id => (aspect == :all ? aspect : aspect.id) diff --git a/app/views/status_messages/_status_message.haml b/app/views/status_messages/_status_message.haml index c50d4fdf5..c467cbea6 100644 --- a/app/views/status_messages/_status_message.haml +++ b/app/views/status_messages/_status_message.haml @@ -5,5 +5,4 @@ = markdownify(post.message) %br - for photo in post.photos - /= render 'photos/photo', :post => photo - = image_tag photo.url(:thumb_medium) + = link_to (image_tag photo.url(:thumb_medium)), object_path(photo) diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index d7933238a..fbdc169a7 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -12,10 +12,11 @@ module Diaspora def visible_posts( opts = {} ) opts[:order] ||= 'created_at DESC' - if opts[:by_members_of] - return raw_visible_posts if opts[:by_members_of] == :all + opts[:pending] ||= false + + if opts[:by_members_of] && opts[:by_members_of] != :all aspect = self.aspects.find_by_id( opts[:by_members_of].id ) - aspect.posts + aspect.posts.find_all_by_pending(opts[:pending], :order => opts[:order]) else self.raw_visible_posts.all(opts) end diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 646601a24..5b1278fe0 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -747,6 +747,10 @@ label :color #eee :text-shadow 0 1px 0 #333 + &.loading + :opacity 0.5 + + #publisher :color #999 :position relative @@ -799,11 +803,8 @@ label :margin :bottom -2px input[type='submit'] - :position absolute - :right 0 - :top 5px :width 75px - :z-index 5 + input :display inline diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index f0ec07d28..77408d3d2 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -28,6 +28,37 @@ describe StatusMessagesController do :to =>"#{aspect.id}"}} } + it "doesn't overwrite person_id" do + new_user = make_user + status_message_hash[:status_message][:person_id] = new_user.person.id + post :create, status_message_hash + StatusMessage.find_by_message(status_message_hash[:status_message][:message]).person_id.should == user.person.id + end + + it "doesn't overwrite id" do + old_status_message = user.post(:status_message, :message => "hello", :to => aspect.id) + status_message_hash[:status_message][:id] = old_status_message.id + lambda {post :create, status_message_hash}.should raise_error /failed save/ + old_status_message.reload.message.should == 'hello' + end + + it "dispatches all referenced photos" do + fixture_filename = 'button.png' + fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename) + + photo1 = user.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect.id) + photo2 = user.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect.id) + + photo1.save! + photo2.save! + + hash = status_message_hash + hash[:photos] = [photo1.id.to_s, photo2.id.to_s] + + user.should_receive(:dispatch_post).exactly(3).times + post :create, hash + end + context "posting out to facebook" do let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s } @@ -41,18 +72,6 @@ describe StatusMessagesController do user.should_not_receive(:post_to_facebook) post :create, status_message_hash end - it "doesn't overwrite person_id" do - new_user = make_user - status_message_hash[:status_message][:person_id] = new_user.person.id - post :create, status_message_hash - StatusMessage.find_by_message(status_message_hash[:status_message][:message]).person_id.should == user.person.id - end - it "doesn't overwrite id" do - old_status_message = user.post(:status_message, :message => "hello", :to => aspect.id) - status_message_hash[:status_message][:id] = old_status_message.id - lambda {post :create, status_message_hash}.should raise_error /failed save/ - old_status_message.reload.message.should == 'hello' - end end context "posting to twitter" do diff --git a/spec/factories.rb b/spec/factories.rb index 948f8dc93..0b30ddd4d 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -58,7 +58,6 @@ end Factory.define :photo do |p| p.image File.open( File.dirname(__FILE__) + '/fixtures/button.png') - end Factory.define :service do |service| diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 9eb7aa999..e87dcb47a 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -9,15 +9,11 @@ describe Photo do @user = make_user @aspect = @user.aspects.create(:name => "losers") - @fixture_filename = 'button.png' - @fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename) + @fixture_filename = 'button.png' + @fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename) @fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml') -# @photo = Photo.new - #@photo.person = @user.person - #@photo.diaspora_handle = @user.person.diaspora_handle - @photo = @user.post(:photo, :user_file=> File.open(@fixture_name), :to => @aspect.id) - + @photo = @user.post(:photo, :user_file=> File.open(@fixture_name), :to => @aspect.id) @photo2 = @user.post(:photo, :user_file=> File.open(@fixture_name), :to => @aspect.id) end diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 47d8eb54b..d1f17aadd 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -74,6 +74,13 @@ describe User do user.should_receive(:post_to_facebook).exactly(0).times user.post :status_message, :message => "hi", :to => "all" end + + + it 'should not socket a pending post' do + sm = user.build_post(:status_message, :message => "your mom", :to => aspect.id, :pending => true) + sm.should_not_receive(:socket_to_uid) + user.dispatch_post(sm, :to => aspect.id) + end end describe '#post' do diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index c6ab423cc..9b19ecca5 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -9,17 +9,20 @@ describe User do let(:user) {make_user} let!(:aspect) { user.aspects.create(:name => "cats")} let!(:user2) { Factory(:user_with_aspect) } + let!(:aspect2) { user2.aspects.first } + let(:person_one) { Factory.create :person } let(:person_two) { Factory.create :person } let(:person_three) { Factory.create :person } context 'with two posts' do - let!(:status_message1) { user2.post :status_message, :message => "hi", :to => user2.aspects.first.id } - let!(:status_message2) { user2.post :status_message, :message => "hey", :public => true , :to => user2.aspects.first.id } - let!(:status_message4) { user2.post :status_message, :message => "blah", :public => true , :to => user2.aspects.first.id } - let!(:status_message3) { user.post :status_message, :message => "hey", :public => true , :to => user.aspects.first.id } + let!(:status_message1) { user2.post :status_message, :message => "hi", :to => aspect2.id } + let!(:status_message2) { user2.post :status_message, :message => "hey", :public => true , :to => aspect2.id } + let!(:status_message4) { user2.post :status_message, :message => "blah", :public => true , :to => aspect2.id } + let!(:status_message3) { user.post :status_message, :message => "hey", :public => true , :to => aspect.id } + let!(:pending_status_message) { user2.post :status_message, :message => "hey", :public => true , :to => aspect2.id, :pending => true } describe "#visible_posts" do it "queries by person id" do @@ -44,6 +47,13 @@ describe User do user2.visible_posts(:message => "hi").include?(status_message1).should == true end + it "does not return pending posts" do + pending_status_message.pending.should be_true + user2.visible_posts.should_not include pending_status_message + + user2.visible_posts(:by_members_of => aspect2).should_not include pending_status_message + end + context 'with two users' do let!(:first_aspect) {user.aspects.create(:name => 'bruisers')} let!(:second_aspect) {user.aspects.create(:name => 'losers')}