parent
7313bafe86
commit
2ce98b49d7
9 changed files with 27 additions and 15 deletions
2
Gemfile
2
Gemfile
|
|
@ -105,8 +105,8 @@ gem 'messagebus_ruby_api', '1.0.3'
|
||||||
# Parsing
|
# Parsing
|
||||||
|
|
||||||
gem 'nokogiri', '1.6.1'
|
gem 'nokogiri', '1.6.1'
|
||||||
gem 'rails_autolink', '1.1.6'
|
|
||||||
gem 'redcarpet', '3.2.0'
|
gem 'redcarpet', '3.2.0'
|
||||||
|
gem 'twitter-text', '1.9.2'
|
||||||
gem 'roxml', '3.1.6'
|
gem 'roxml', '3.1.6'
|
||||||
gem 'ruby-oembed', '0.8.10'
|
gem 'ruby-oembed', '0.8.10'
|
||||||
gem 'opengraph_parser', '0.2.3'
|
gem 'opengraph_parser', '0.2.3'
|
||||||
|
|
|
||||||
|
|
@ -399,8 +399,6 @@ GEM
|
||||||
remotipart (~> 1.0)
|
remotipart (~> 1.0)
|
||||||
safe_yaml (~> 1.0)
|
safe_yaml (~> 1.0)
|
||||||
sass-rails (~> 4.0)
|
sass-rails (~> 4.0)
|
||||||
rails_autolink (1.1.6)
|
|
||||||
rails (> 3.1)
|
|
||||||
railties (4.1.6)
|
railties (4.1.6)
|
||||||
actionpack (= 4.1.6)
|
actionpack (= 4.1.6)
|
||||||
activesupport (= 4.1.6)
|
activesupport (= 4.1.6)
|
||||||
|
|
@ -498,6 +496,8 @@ GEM
|
||||||
faraday (~> 0.8, < 0.10)
|
faraday (~> 0.8, < 0.10)
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
simple_oauth (~> 0.2)
|
simple_oauth (~> 0.2)
|
||||||
|
twitter-text (1.9.2)
|
||||||
|
unf (~> 0.1.0)
|
||||||
typhoeus (0.6.9)
|
typhoeus (0.6.9)
|
||||||
ethon (>= 0.7.1)
|
ethon (>= 0.7.1)
|
||||||
tzinfo (1.2.2)
|
tzinfo (1.2.2)
|
||||||
|
|
@ -601,7 +601,6 @@ DEPENDENCIES
|
||||||
rails-i18n (= 4.0.3)
|
rails-i18n (= 4.0.3)
|
||||||
rails-timeago (= 2.11.0)
|
rails-timeago (= 2.11.0)
|
||||||
rails_admin (= 0.6.5)
|
rails_admin (= 0.6.5)
|
||||||
rails_autolink (= 1.1.6)
|
|
||||||
rb-fsevent (= 0.9.4)
|
rb-fsevent (= 0.9.4)
|
||||||
rb-inotify (= 0.9.5)
|
rb-inotify (= 0.9.5)
|
||||||
redcarpet (= 3.2.0)
|
redcarpet (= 3.2.0)
|
||||||
|
|
@ -620,6 +619,7 @@ DEPENDENCIES
|
||||||
test_after_commit (= 0.3.0)
|
test_after_commit (= 0.3.0)
|
||||||
timecop (= 0.7.1)
|
timecop (= 0.7.1)
|
||||||
twitter (= 4.8.1)
|
twitter (= 4.8.1)
|
||||||
|
twitter-text (= 1.9.2)
|
||||||
typhoeus (= 0.6.9)
|
typhoeus (= 0.6.9)
|
||||||
uglifier (= 2.5.3)
|
uglifier (= 2.5.3)
|
||||||
unicorn (= 4.8.3)
|
unicorn (= 4.8.3)
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class Services::Facebook < Service
|
||||||
|
|
||||||
{message: message,
|
{message: message,
|
||||||
access_token: access_token,
|
access_token: access_token,
|
||||||
link: URI.extract(message, ['https', 'http']).first
|
link: post.message.urls.first
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,13 +148,13 @@ class StatusMessage < Post
|
||||||
end
|
end
|
||||||
|
|
||||||
def contains_oembed_url_in_text?
|
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? }
|
self.oembed_url = urls.find{ |url| !TRUSTED_OEMBED_PROVIDERS.find(url).nil? }
|
||||||
end
|
end
|
||||||
|
|
||||||
def contains_open_graph_url_in_text?
|
def contains_open_graph_url_in_text?
|
||||||
return nil if self.contains_oembed_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
|
end
|
||||||
|
|
||||||
def address
|
def address
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module Diaspora
|
||||||
include ActionView::Helpers::TextHelper
|
include ActionView::Helpers::TextHelper
|
||||||
|
|
||||||
def autolink link, type
|
def autolink link, type
|
||||||
auto_link(link, link: :urls, html: { target: "_blank" })
|
Twitter::Autolink.auto_link_urls(link, url_target: "_blank")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,12 @@ module Diaspora
|
||||||
end
|
end
|
||||||
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
|
def raw
|
||||||
@raw_message
|
@raw_message
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,11 @@ describe NotifierHelper, :type => :helper do
|
||||||
describe '#post_message' do
|
describe '#post_message' do
|
||||||
before do
|
before do
|
||||||
# post for truncate test
|
# post for truncate test
|
||||||
@post = FactoryGirl.create(:status_message)
|
@post = FactoryGirl.create(:status_message, text: "hi dude! "*10)
|
||||||
@post.text = "hi dude! "*10
|
|
||||||
@truncated_post = "hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi du..."
|
@truncated_post = "hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi du..."
|
||||||
# post for markdown test
|
# post for markdown test
|
||||||
@markdown_post = FactoryGirl.create(:status_message)
|
@markdown_post = FactoryGirl.create(:status_message,
|
||||||
@markdown_post.text = "[link](http://diasporafoundation.org) **bold text** *other text*"
|
text: "[link](http://diasporafoundation.org) **bold text** *other text*")
|
||||||
@striped_markdown_post = "link (http://diasporafoundation.org) bold text other text"
|
@striped_markdown_post = "link (http://diasporafoundation.org) bold text other text"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ describe Diaspora::MessageRenderer do
|
||||||
it 'should process text with both a hashtag and a link' do
|
it 'should process text with both a hashtag and a link' do
|
||||||
expect(
|
expect(
|
||||||
message("Test #tag?\nhttps://joindiaspora.com\n").markdownified
|
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
|
end
|
||||||
|
|
||||||
it 'should process text with a header' do
|
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
|
expect(message(text).plain_text_without_markdown).to eq text
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ describe Services::Facebook, :type => :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'removes text formatting markdown from post text' do
|
it 'removes text formatting markdown from post text' do
|
||||||
message = double
|
message = double(urls: [])
|
||||||
expect(message).to receive(:plain_text_without_markdown).and_return("")
|
expect(message).to receive(:plain_text_without_markdown).and_return("")
|
||||||
post = double(message: message, photos: [])
|
post = double(message: message, photos: [])
|
||||||
post_params = @service.create_post_params(post)
|
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
|
it 'does not add post link when no photos' do
|
||||||
message = "Some text."
|
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)
|
post_params = @service.create_post_params(post)
|
||||||
expect(post_params[:message]).not_to include "http"
|
expect(post_params[:message]).not_to include "http"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue