Skip to content

Commit

Permalink
Fixes status behavior (still perfetible though)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric de Villamil committed Aug 7, 2013
1 parent fd9f783 commit 0ec9868
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions app/models/status.rb
Expand Up @@ -57,18 +57,23 @@ def send_to_twitter(user)
message = self.body.strip_html

length = calculate_real_length(message)

if length > 126
message = "#{message[0..126]} [...] #{shortened_url}"
return length
if length > 113

message = "#{message[0..116]}... #{shortened_url}"
else
message = "#{message} #{shortened_url}"
end

begin
tweet = twitter.update(message)
self.twitter_id = tweet.attrs[:id_str]
self.save

tweet = twitter.update(message)
self.twitter_id = tweet.attrs[:id_str]
self.save

user.update_twitter_profile_image(tweet.attrs[:user][:profile_image_url])
user.update_twitter_profile_image(tweet.attrs[:user][:profile_image_url])
rescue
flash[:error] = "Oooops something wrong happened"
end
end

content_fields :body
Expand All @@ -88,17 +93,13 @@ def permalink_url(anchor=nil, only_path=false)
end

private
def calculate_real_length(message)
link_length = 21 # t.co URL length
length = message.length

uris = URI.extract(message)

def calculate_real_length(message)
uris = URI.extract(message, ['http', 'https', 'ftp'])
uris.each do |uri|
length = length - (uri.length + link_length)
message = message.gsub(uri, "---------------------")
end
return length

return message.length
end

end

0 comments on commit 0ec9868

Please sign in to comment.