Index: doc/user-guide/commands.xml
===================================================================
--- doc/user-guide/commands.xml (revision d2abcae711eb4aca5b67e405607f40156ba0a29a)
+++ doc/user-guide/commands.xml (revision 7d27962b17487ec1c783dc9e028859b01a20e6f0)
@@ -1032,4 +1032,19 @@
+
+
+ 20
+
+
+
+ Twitter replaces every URL with fixed-length t.co URLs. BitlBee is able to take t.co urls into account when calculating message_length replacing the actual URL length with target_url_length. Setting target_url_length to 0 disables this feature.
+
+
+
+ This setting is disabled for identica accounts by default and will not affect anything other than message safety checks (i.e. Twitter will still replace your URLs with t.co links, even if that makes them longer).
+
+
+
+
Index: protocols/twitter/twitter.c
===================================================================
--- protocols/twitter/twitter.c (revision d2abcae711eb4aca5b67e405607f40156ba0a29a)
+++ protocols/twitter/twitter.c (revision 7d27962b17487ec1c783dc9e028859b01a20e6f0)
@@ -197,9 +197,38 @@
}
+int twitter_url_len_diff(gchar *msg, unsigned int target_len)
+{
+ int url_len_diff = 0;
+
+ static GRegex *regex = NULL;
+ GMatchInfo *match_info;
+
+ if (regex == NULL)
+ regex = g_regex_new("(^|\\s)(http(s)?://[^\\s$]+)", 0, 0, NULL);
+
+ g_regex_match(regex, msg, 0, &match_info);
+ while (g_match_info_matches(match_info)) {
+ gchar *url = g_match_info_fetch(match_info, 2);
+ url_len_diff += target_len - g_utf8_strlen(url, -1);
+ if (g_match_info_fetch(match_info, 3) != NULL)
+ url_len_diff += 1;
+ g_free(url);
+ g_match_info_next(match_info, NULL);
+ }
+ g_match_info_free(match_info);
+
+ return url_len_diff;
+}
+
static gboolean twitter_length_check(struct im_connection *ic, gchar * msg)
{
int max = set_getint(&ic->acc->set, "message_length"), len;
-
- if (max == 0 || (len = g_utf8_strlen(msg, -1)) <= max)
+ int target_len = set_getint(&ic->acc->set, "target_url_length");
+ int url_len_diff = 0;
+
+ if (target_len > 0)
+ url_len_diff = twitter_url_len_diff(msg, target_len);
+
+ if (max == 0 || (len = g_utf8_strlen(msg, -1) + url_len_diff) <= max)
return TRUE;
@@ -214,11 +243,14 @@
char *def_url;
char *def_oauth;
+ char *def_tul;
if (strcmp(acc->prpl->name, "twitter") == 0) {
def_url = TWITTER_API_URL;
def_oauth = "true";
+ def_tul = "20";
} else { /* if( strcmp( acc->prpl->name, "identica" ) == 0 ) */
def_url = IDENTICA_API_URL;
def_oauth = "true";
+ def_tul = "0";
}
@@ -236,4 +268,6 @@
s = set_add(&acc->set, "message_length", "140", set_eval_int, acc);
+
+ s = set_add(&acc->set, "target_url_length", def_tul, set_eval_int, acc);
s = set_add(&acc->set, "mode", "chat", set_eval_mode, acc);