diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 3e6605866..8572f7090 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -66,11 +66,6 @@ class StatusMessage < Post write_attribute(:text, text) end - def attach_photos_by_ids(photo_ids) - return [] unless photo_ids.present? - self.photos << Photo.where(:id => photo_ids, :author_id => self.author_id) - end - def nsfw self.raw_message.match(/#nsfw/i) || super end @@ -110,24 +105,6 @@ class StatusMessage < Post self.mentions.where(:person_id => person.id).first.try(:notify_recipient) end - def after_dispatch(sender) - self.update_and_dispatch_attached_photos(sender) - end - - def update_and_dispatch_attached_photos(sender) - if self.photos.any? - logger.info "dispatch photos for StatusMessage:#{guid}" - Photo.where(status_message_guid: guid).update_all(:public => self.public) - self.photos.each do |photo| - if photo.pending - sender.add_to_streams(photo, self.aspects) - sender.dispatch_post(photo) - end - end - Photo.where(status_message_guid: guid).update_all(:pending => false) - end - end - def comment_email_subject message.title end diff --git a/app/services/status_message_creation_service.rb b/app/services/status_message_creation_service.rb index 9c06d2687..12bd8fbae 100644 --- a/app/services/status_message_creation_service.rb +++ b/app/services/status_message_creation_service.rb @@ -42,8 +42,13 @@ class StatusMessageCreationService end def add_photos(status_message, photos) - status_message.attach_photos_by_ids(photos) - status_message.photos.each {|photo| photo.public = status_message.public } + if photos.present? + status_message.photos << Photo.where(id: photos, author_id: status_message.author_id) + status_message.photos.each do |photo| + photo.public = status_message.public + photo.pending = false + end + end end def process(status_message, aspect_ids, services) @@ -55,6 +60,7 @@ class StatusMessageCreationService def add_to_streams(status_message, aspect_ids) aspects = user.aspects_from_ids(aspect_ids) user.add_to_streams(status_message, aspects) + status_message.photos.each {|photo| user.add_to_streams(photo, aspects) } end def dispatch(status_message, services) diff --git a/lib/diaspora/federated/base.rb b/lib/diaspora/federated/base.rb index 8c60edc16..73ec9adff 100644 --- a/lib/diaspora/federated/base.rb +++ b/lib/diaspora/federated/base.rb @@ -42,11 +42,6 @@ module Diaspora def subscribers raise 'You must override subscribers in order to enable federation on this model' end - - # @param [User] sender - # @note this is a hook(optional) - def after_dispatch(sender) - end end end end diff --git a/lib/postzord/dispatcher.rb b/lib/postzord/dispatcher.rb index 527f3a0f2..a287b8608 100644 --- a/lib/postzord/dispatcher.rb +++ b/lib/postzord/dispatcher.rb @@ -64,18 +64,11 @@ class Postzord::Dispatcher def post self.deliver_to_services(@opts[:url], @opts[:services] || []) self.post_to_subscribers if @subscribers.present? - self.process_after_dispatch_hooks @object end protected - # @return [Object] - def process_after_dispatch_hooks - @object.after_dispatch(@sender) - @object - end - def post_to_subscribers remote_people, local_people = @subscribers.partition{ |person| person.owner_id.nil? } diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 15bcb3b8e..85538fe0b 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -222,7 +222,6 @@ describe StatusMessagesController, :type => :controller do end it "sets the pending bit of referenced photos" do - skip # TODO inlined_jobs do post :create, @hash end diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 4ab506290..613b21c1e 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -361,28 +361,6 @@ describe StatusMessage, type: :model do end end - describe "#after_dispatch" do - before do - @photos = [alice.build_post(:photo, pending: true, user_file: File.open(photo_fixture_name)), - alice.build_post(:photo, pending: true, user_file: File.open(photo_fixture_name))] - @photos.each(&:save!) - @status_message = alice.build_post(:status_message, text: "the best pebble.") - @status_message.photos << @photos - @status_message.save! - alice.add_to_streams(@status_message, alice.aspects) - end - - it "sets pending to false on any attached photos" do - @status_message.after_dispatch(alice) - expect(@photos.all? {|p| p.reload.pending }).to be false - end - - it "dispatches any attached photos" do - expect(alice).to receive(:dispatch_post).twice - @status_message.after_dispatch(alice) - end - end - describe "oembed" do let(:youtube_url) { "https://www.youtube.com/watch?v=3PtFwlKfvHI" } let(:message_text) { "#{youtube_url} is so cool. so is this link -> https://joindiaspora.com" } diff --git a/spec/services/status_message_creation_service_spec.rb b/spec/services/status_message_creation_service_spec.rb index f9d2db2c0..1fa3f035a 100644 --- a/spec/services/status_message_creation_service_spec.rb +++ b/spec/services/status_message_creation_service_spec.rb @@ -99,24 +99,58 @@ describe StatusMessageCreationService do expect(photos.map(&:id).map(&:to_s)).to match_array(photo_ids) end - it "it marks the photos as non-public if the post is non-public" do - status_message = StatusMessageCreationService.new(alice).create(params.merge(photos: photo_ids, public: false)) - status_message.photos.each do |photo| - expect(photo.public).to be_falsey - end - end - - it "it marks the photos as public if the post is public" do - status_message = StatusMessageCreationService.new(alice).create(params.merge(photos: photo_ids, public: true)) - status_message.photos.each do |photo| - expect(photo.public).to be_truthy - end - end - it "does not attach photos without photos param" do status_message = StatusMessageCreationService.new(alice).create(params) expect(status_message.photos).to be_empty end + + context "with aspect_ids" do + it "it marks the photos as non-public if the post is non-public" do + status_message = StatusMessageCreationService.new(alice).create(params.merge(photos: photo_ids)) + status_message.photos.each do |photo| + expect(photo.public).to be_falsey + end + end + + it "creates aspect_visibilities for the Photo" do + alice.aspects.create(name: "another aspect") + + status_message = StatusMessageCreationService.new(alice).create(params.merge(photos: photo_ids)) + status_message.photos.each do |photo| + expect(photo.aspect_visibilities.map(&:aspect)).to eq([aspect]) + end + end + + it "does not create aspect_visibilities if the post is public" do + status_message = StatusMessageCreationService.new(alice).create(params.merge(photos: photo_ids, public: true)) + status_message.photos.each do |photo| + expect(photo.aspect_visibilities).to be_empty + end + end + + it "sets pending to false on any attached photos" do + status_message = StatusMessageCreationService.new(alice).create(params.merge(photos: photo_ids)) + status_message.photos.each do |photo| + expect(photo.reload.pending).to be_falsey + end + end + end + + context "with public" do + it "it marks the photos as public if the post is public" do + status_message = StatusMessageCreationService.new(alice).create(params.merge(photos: photo_ids, public: true)) + status_message.photos.each do |photo| + expect(photo.public).to be_truthy + end + end + + it "sets pending to false on any attached photos" do + status_message = StatusMessageCreationService.new(alice).create(params.merge(photos: photo_ids, public: true)) + status_message.photos.each do |photo| + expect(photo.reload.pending).to be_falsey + end + end + end end context "dispatch" do