diff --git a/src/async/ComposeJob.vala b/src/async/ComposeJob.vala index e0a5cf41f..dbad3bf31 100644 --- a/src/async/ComposeJob.vala +++ b/src/async/ComposeJob.vala @@ -125,7 +125,12 @@ class ComposeJob : GLib.Object { Cb.MiniTweet mt = quoted_tweet.retweeted_tweet ?? quoted_tweet.source_tweet; var quoted_url = "https://twitter.com/%s/status/%s".printf (mt.author.screen_name, mt.id.to_string ()); - call.add_param ("attachment_url", quoted_url); + + if (media_ids == null || media_ids.length == 0) { + call.add_param ("attachment_url", quoted_url); + } else { + this.text += " " + quoted_url; + } } call.add_param ("status", this.text); diff --git a/src/util/TweetUtils.vala b/src/util/TweetUtils.vala index 259e8b248..15b7aa2aa 100644 --- a/src/util/TweetUtils.vala +++ b/src/util/TweetUtils.vala @@ -160,16 +160,20 @@ namespace TweetUtils { * Calculates the length of a tweet. * * @param text The text to calculate the length for + * @param add_url Whether to add a Twitter URL to the calculation * * @return The length of the tweet, taking Twitter's rules for * tweet length into account. */ - public int calc_tweet_length (string text, int media_count = 0) { + public int calc_tweet_length (string text, bool add_url = false) { int length = 0; + if (add_url) + length += 1 + Twitter.short_url_length_https; + /* trailing & laeding whitespace don't count unless there's other text */ if (text.strip ().length == 0) { - return 0; + return length; } unichar c; diff --git a/src/window/ComposeTweetWindow.vala b/src/window/ComposeTweetWindow.vala index 05f9fe6e8..82fa3f2c3 100644 --- a/src/window/ComposeTweetWindow.vala +++ b/src/window/ComposeTweetWindow.vala @@ -142,6 +142,8 @@ class ComposeTweetWindow : Gtk.ApplicationWindow { if (this.compose_image_manager.n_images == 0) this.compose_image_manager.hide (); + + this.recalc_tweet_length(); }); this.add_accel_group (ag); @@ -161,10 +163,16 @@ class ComposeTweetWindow : Gtk.ApplicationWindow { tweet_text.buffer.get_bounds (out start, out end); string text = tweet_text.buffer.get_text (start, end, true); - int length = TweetUtils.calc_tweet_length (text); + bool add_url = false; + //We can only add an image or a quoted URL as an attachment, so if we + //have both then the quoted tweet must become an inline URL + if (compose_image_manager.n_images > 0 && mode == Mode.QUOTE) + add_url = true; + + int length = TweetUtils.calc_tweet_length (text, add_url); length_label.label = (Cb.Tweet.MAX_LENGTH - length).to_string (); - if (length > 0 && length <= Cb.Tweet.MAX_LENGTH) + if ((length > 0 && length <= Cb.Tweet.MAX_LENGTH) || (compose_image_manager.n_images > 0 && length == 0)) send_button.sensitive = true; else send_button.sensitive = false; @@ -295,6 +303,7 @@ class ComposeTweetWindow : Gtk.ApplicationWindow { } } filechooser.destroy (); + this.recalc_tweet_length(); }); var filter = new Gtk.FileFilter ();