From 1a3c16eb6e6db82cf5aedb849f2cd7499b9e0e84 Mon Sep 17 00:00:00 2001 From: Brad Koehn Date: Sun, 7 Jan 2018 14:14:56 -0600 Subject: update to support 280 character Twitter closes #7694 closes #7662 fixes #7661 --- Changelog.md | 1 + app/models/services/twitter.rb | 2 +- spec/models/services/twitter_spec.rb | 14 +++++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index 60c8b62f1..d6931d4e8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,7 @@ ## Refactor * Work on the data downloads: Fixed general layout of buttons, added a timestamp and implemented auto-deletion of old exports [#7684](https://github.com/diaspora/diaspora/pull/7684) +* Increase Twitter character limit to 280 [#7694](https://github.com/diaspora/diaspora/pull/7694) ## Bug fixes * Fix notifications when people remove their birthday date [#7691](https://github.com/diaspora/diaspora/pull/7691) diff --git a/app/models/services/twitter.rb b/app/models/services/twitter.rb index b14791736..7b54c392e 100644 --- a/app/models/services/twitter.rb +++ b/app/models/services/twitter.rb @@ -3,7 +3,7 @@ class Services::Twitter < Service include Rails.application.routes.url_helpers - MAX_CHARACTERS = 140 + MAX_CHARACTERS = 280 SHORTENED_URL_LENGTH = 21 LINK_PATTERN = %r{https?://\S+} diff --git a/spec/models/services/twitter_spec.rb b/spec/models/services/twitter_spec.rb index a2b10c617..28c9d2aaf 100644 --- a/spec/models/services/twitter_spec.rb +++ b/spec/models/services/twitter_spec.rb @@ -41,8 +41,8 @@ describe Services::Twitter, :type => :model do describe "message size limits" do before :each do - @long_message_start = SecureRandom.hex(25) - @long_message_end = SecureRandom.hex(25) + @long_message_start = SecureRandom.hex(165) + @long_message_end = SecureRandom.hex(165) end it "should not truncate a short message" do @@ -52,7 +52,7 @@ describe Services::Twitter, :type => :model do end it "should truncate a long message" do - long_message = SecureRandom.hex(220) + long_message = SecureRandom.hex(360) long_post = double(message: double(plain_text_without_markdown: long_message), id: 1, photos: []) expect(@service.send(:build_twitter_post, long_post).length).to be < long_message.length end @@ -67,7 +67,9 @@ describe Services::Twitter, :type => :model do end it "should not cut links when truncating a post" do - long_message = SecureRandom.hex(40) + " http://joindiaspora.com/a-very-long-url-name-that-will-be-shortened.html " + SecureRandom.hex(55) + long_message = SecureRandom.hex(40) + + " http://joindiaspora.com/a-very-long-url-name-that-will-be-shortened.html " + + SecureRandom.hex(195) long_post = double(message: double(plain_text_without_markdown: long_message), id: 1, photos: []) answer = @service.send(:build_twitter_post, long_post) @@ -76,7 +78,9 @@ describe Services::Twitter, :type => :model do end it "should append the otherwise-cut link when truncating a post" do - long_message = "http://joindiaspora.com/a-very-long-decoy-url.html " + SecureRandom.hex(20) + " http://joindiaspora.com/a-very-long-url-name-that-will-be-shortened.html " + SecureRandom.hex(55) + " http://joindiaspora.com/a-very-long-decoy-url-part-2.html" + long_message = "http://joindiaspora.com/a-very-long-decoy-url.html " + SecureRandom.hex(20) + + " http://joindiaspora.com/a-very-long-url-name-that-will-be-shortened.html " + SecureRandom.hex(195) + + " http://joindiaspora.com/a-very-long-decoy-url-part-2.html" long_post = double(message: double(plain_text_without_markdown: long_message), id: 1, photos: []) answer = @service.send(:build_twitter_post, long_post) -- cgit v1.2.3