From b996dbb5a4e1b10a23ac81ffb97983cb228aa687 Mon Sep 17 00:00:00 2001 From: IBBoard Date: Wed, 5 Oct 2016 20:51:43 +0100 Subject: [PATCH 1/4] Fix "quote with image" to count a URL if we have both Under "long tweet" rules, quotes are attachments, so quote plus images means too many attachments. The easiest way to fix this is to add the quoted URL inline (old style quote) if we also have images to upload. --- src/async/ComposeJob.vala | 7 ++++++- src/util/TweetUtils.vala | 6 +++++- src/window/ComposeTweetWindow.vala | 9 ++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) 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..040451ad8 100644 --- a/src/util/TweetUtils.vala +++ b/src/util/TweetUtils.vala @@ -160,11 +160,12 @@ 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; /* trailing & laeding whitespace don't count unless there's other text */ @@ -203,6 +204,9 @@ namespace TweetUtils { cur = next; } + if (add_url) + length += 1 + Twitter.short_url_length_https; + return length; } diff --git a/src/window/ComposeTweetWindow.vala b/src/window/ComposeTweetWindow.vala index 05f9fe6e8..73f47792b 100644 --- a/src/window/ComposeTweetWindow.vala +++ b/src/window/ComposeTweetWindow.vala @@ -161,7 +161,13 @@ 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) @@ -295,6 +301,7 @@ class ComposeTweetWindow : Gtk.ApplicationWindow { } } filechooser.destroy (); + this.recalc_tweet_length(); }); var filter = new Gtk.FileFilter (); From 9e1e941930b4f39e13f3e06fb547879ad1153300 Mon Sep 17 00:00:00 2001 From: IBBoard Date: Wed, 5 Oct 2016 20:56:12 +0100 Subject: [PATCH 2/4] Make sure that we also recalculate tweet length on image removal If we don't do this then adding and removing an image leaves the user with a 23 character shorter message limit! --- src/window/ComposeTweetWindow.vala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/window/ComposeTweetWindow.vala b/src/window/ComposeTweetWindow.vala index 73f47792b..63cdf5d85 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); From 662b9059814cbecb1c8761dbe56924f145d8ff71 Mon Sep 17 00:00:00 2001 From: IBBoard Date: Wed, 5 Oct 2016 21:04:01 +0100 Subject: [PATCH 3/4] Make sure we count URL for "quote with image and no text" --- src/util/TweetUtils.vala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/TweetUtils.vala b/src/util/TweetUtils.vala index 040451ad8..15b7aa2aa 100644 --- a/src/util/TweetUtils.vala +++ b/src/util/TweetUtils.vala @@ -168,9 +168,12 @@ namespace TweetUtils { 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; @@ -204,9 +207,6 @@ namespace TweetUtils { cur = next; } - if (add_url) - length += 1 + Twitter.short_url_length_https; - return length; } From 745da77c1bb47058fd28baae9098bcee659943b2 Mon Sep 17 00:00:00 2001 From: IBBoard Date: Sat, 17 Dec 2016 20:38:38 +0000 Subject: [PATCH 4/4] Make sure that we can tweet zero-length messages with images This is allowed on the web UI, even though the URL will now be in the additional metadata rather than the message text --- src/window/ComposeTweetWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window/ComposeTweetWindow.vala b/src/window/ComposeTweetWindow.vala index 63cdf5d85..82fa3f2c3 100644 --- a/src/window/ComposeTweetWindow.vala +++ b/src/window/ComposeTweetWindow.vala @@ -172,7 +172,7 @@ class ComposeTweetWindow : Gtk.ApplicationWindow { 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;