diff --git a/Changelog.md b/Changelog.md index 61b3fa3c6..8d82d1277 100644 --- a/Changelog.md +++ b/Changelog.md @@ -21,6 +21,7 @@ * Include reshares in a users public atom feed [#1781](https://github.com/diaspora/diaspora/issues/1781) * Add the ability to upload photos from the mobile site. [#4004](https://github.com/diaspora/diaspora/issues/4004) * Show timestamp when hovering on comment time-ago string. [#4042](https://github.com/diaspora/diaspora/issues/4042) +* If sharing a post with photos to Facebook, always include URL to post [#3706](https://github.com/diaspora/diaspora/issues/3706) # 0.0.3.2 diff --git a/app/models/services/facebook.rb b/app/models/services/facebook.rb index dcdd5fd43..d5a6fb633 100644 --- a/app/models/services/facebook.rb +++ b/app/models/services/facebook.rb @@ -25,6 +25,9 @@ class Services::Facebook < Service def create_post_params(post) message = strip_markdown(post.text(:plain_text => true)) + if post.photos.any? + message += " " + Rails.application.routes.url_helpers.short_post_url(post, :protocol => AppConfig.pod_uri.scheme, :host => AppConfig.pod_uri.authority) + end {:message => message, :access_token => self.access_token, :link => URI.extract(message, ['https', 'http']).first} end diff --git a/spec/models/services/facebook_spec.rb b/spec/models/services/facebook_spec.rb index 1da9d7931..c283ffdb1 100644 --- a/spec/models/services/facebook_spec.rb +++ b/spec/models/services/facebook_spec.rb @@ -4,7 +4,7 @@ describe Services::Facebook do before do @user = alice - @post = @user.post(:status_message, :text => "hello", :to =>@user.aspects.first.id, :public =>true, :facebook_id => "23456" ) + @post = @user.post(:status_message, :text => "hello", :to =>@user.aspects.first.id, :public =>true, :facebook_id => "23456", :photos => []) @service = Services::Facebook.new(:access_token => "yeah") @user.services << @service end @@ -34,7 +34,14 @@ describe Services::Facebook do it 'removes text formatting markdown from post text' do message = "Text with some **bolded** and _italic_ parts." - post = stub(:text => message) + post = stub(:text => message, :photos => []) + post_params = @service.create_post_params(post) + post_params[:message].should match "Text with some bolded and italic parts." + end + + it 'does not add post link when no photos' do + message = "Text with some **bolded** and _italic_ parts." + post = stub(:text => message, :photos => []) post_params = @service.create_post_params(post) post_params[:message].should match "Text with some bolded and italic parts." end @@ -47,6 +54,27 @@ describe Services::Facebook do end end + + describe "with photo" 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 "should include post url in message with photos" do + post_params = @service.create_post_params(@status_message) + post_params[:message].should include 'http' + end + + end describe "#profile_photo_url" do it 'returns a large profile photo url' do