Commit 2ce98b49 authored by augier's avatar augier
Browse files

Fix issue #4416

Conflicts:
	spec/helpers/notifier_helper_spec.rb
parent 7313bafe
......@@ -105,8 +105,8 @@ gem 'messagebus_ruby_api', '1.0.3'
# Parsing
gem 'nokogiri', '1.6.1'
gem 'rails_autolink', '1.1.6'
gem 'redcarpet', '3.2.0'
gem 'twitter-text', '1.9.2'
gem 'roxml', '3.1.6'
gem 'ruby-oembed', '0.8.10'
gem 'opengraph_parser', '0.2.3'
......
......@@ -399,8 +399,6 @@ GEM
remotipart (~> 1.0)
safe_yaml (~> 1.0)
sass-rails (~> 4.0)
rails_autolink (1.1.6)
rails (> 3.1)
railties (4.1.6)
actionpack (= 4.1.6)
activesupport (= 4.1.6)
......@@ -498,6 +496,8 @@ GEM
faraday (~> 0.8, < 0.10)
multi_json (~> 1.0)
simple_oauth (~> 0.2)
twitter-text (1.9.2)
unf (~> 0.1.0)
typhoeus (0.6.9)
ethon (>= 0.7.1)
tzinfo (1.2.2)
......@@ -601,7 +601,6 @@ DEPENDENCIES
rails-i18n (= 4.0.3)
rails-timeago (= 2.11.0)
rails_admin (= 0.6.5)
rails_autolink (= 1.1.6)
rb-fsevent (= 0.9.4)
rb-inotify (= 0.9.5)
redcarpet (= 3.2.0)
......@@ -620,6 +619,7 @@ DEPENDENCIES
test_after_commit (= 0.3.0)
timecop (= 0.7.1)
twitter (= 4.8.1)
twitter-text (= 1.9.2)
typhoeus (= 0.6.9)
uglifier (= 2.5.3)
unicorn (= 4.8.3)
......
......@@ -29,7 +29,7 @@ class Services::Facebook < Service
{message: message,
access_token: access_token,
link: URI.extract(message, ['https', 'http']).first
link: post.message.urls.first
}
end
......
......@@ -148,13 +148,13 @@ class StatusMessage < Post
end
def contains_oembed_url_in_text?
urls = URI.extract(self.raw_message, ['http', 'https'])
urls = self.message.urls
self.oembed_url = urls.find{ |url| !TRUSTED_OEMBED_PROVIDERS.find(url).nil? }
end
def contains_open_graph_url_in_text?
return nil if self.contains_oembed_url_in_text?
self.open_graph_url = URI.extract(self.raw_message, ['http', 'https'])[0]
self.open_graph_url = self.message.urls[0]
end
def address
......
......@@ -4,7 +4,7 @@ module Diaspora
include ActionView::Helpers::TextHelper
def autolink link, type
auto_link(link, link: :urls, html: { target: "_blank" })
Twitter::Autolink.auto_link_urls(link, url_target: "_blank")
end
end
end
......
......@@ -213,6 +213,12 @@ module Diaspora
end
end
# Extracts all the urls from the raw message and return them in the form of a string
# Different URLs are seperated with a space
def urls
@urls ||= Twitter::Extractor.extract_urls(@raw_message)
end
def raw
@raw_message
end
......
......@@ -8,12 +8,11 @@ describe NotifierHelper, :type => :helper do
describe '#post_message' do
before do
# post for truncate test
@post = FactoryGirl.create(:status_message)
@post.text = "hi dude! "*10
@post = FactoryGirl.create(:status_message, text: "hi dude! "*10)
@truncated_post = "hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi du..."
# post for markdown test
@markdown_post = FactoryGirl.create(:status_message)
@markdown_post.text = "[link](http://diasporafoundation.org) **bold text** *other text*"
@markdown_post = FactoryGirl.create(:status_message,
text: "[link](http://diasporafoundation.org) **bold text** *other text*")
@striped_markdown_post = "link (http://diasporafoundation.org) bold text other text"
end
......
......@@ -147,7 +147,7 @@ describe Diaspora::MessageRenderer do
it 'should process text with both a hashtag and a link' do
expect(
message("Test #tag?\nhttps://joindiaspora.com\n").markdownified
).to eq %{<p>Test <a class="tag" href="/tags/tag">#tag</a>?<br>\n<a href="https://joindiaspora.com" target="_blank">https://joindiaspora.com</a></p>\n}
).to eq %{<p>Test <a class="tag" href="/tags/tag">#tag</a>?<br>\n<a href="https://joindiaspora.com" rel="nofollow" target="_blank">https://joindiaspora.com</a></p>\n}
end
it 'should process text with a header' do
......@@ -172,4 +172,11 @@ describe Diaspora::MessageRenderer do
expect(message(text).plain_text_without_markdown).to eq text
end
end
describe "#urls" do
it "extracts the urls from the raw message" do
text = "[Perdu](http://perdu.com/) and [DuckDuckGo](https://duckduckgo.com/) can help you"
expect(message(text).urls).to eql ["http://perdu.com/", "https://duckduckgo.com/"]
end
end
end
......@@ -25,7 +25,7 @@ describe Services::Facebook, :type => :model do
end
it 'removes text formatting markdown from post text' do
message = double
message = double(urls: [])
expect(message).to receive(:plain_text_without_markdown).and_return("")
post = double(message: message, photos: [])
post_params = @service.create_post_params(post)
......@@ -33,7 +33,7 @@ describe Services::Facebook, :type => :model do
it 'does not add post link when no photos' do
message = "Some text."
post = double(message: double(plain_text_without_markdown: message), photos: [])
post = double(message: double(plain_text_without_markdown: message, urls: []), photos: [])
post_params = @service.create_post_params(post)
expect(post_params[:message]).not_to include "http"
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment