Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/async/ComposeJob.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/util/TweetUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions src/window/ComposeTweetWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -295,6 +303,7 @@ class ComposeTweetWindow : Gtk.ApplicationWindow {
}
}
filechooser.destroy ();
this.recalc_tweet_length();
});

var filter = new Gtk.FileFilter ();
Expand Down