diff options
author | Marius Halden <marius.h@lden.org> | 2015-11-08 16:46:16 +0100 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2016-07-20 15:13:52 +0200 |
commit | 1deca055c89a52125f6a14bca40fcf4e8004be23 (patch) | |
tree | aaa54b00a30a50a2a57a0c2303f1942fb3416cef /protocols | |
parent | f60dc5cb68ac91df714f01ef61ba819eeac584aa (diff) |
Add support for long tweet ids
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/twitter/twitter.c | 24 | ||||
-rw-r--r-- | protocols/twitter/twitter.h | 4 | ||||
-rw-r--r-- | protocols/twitter/twitter_lib.c | 15 |
3 files changed, 33 insertions, 10 deletions
diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index b2039171..fa66fbe9 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -528,6 +528,15 @@ static char *set_eval_mode(set_t * set, char *value) } } +static char *set_eval_long_ids(set_t * set, char *value) +{ + int len = atoi(value); + if (len >= 1 || len <= 4) + return value; + + return SET_INVALID; +} + static void twitter_init(account_t * acc) { set_t *s; @@ -572,6 +581,9 @@ static void twitter_init(account_t * acc) s = set_add(&acc->set, "strip_newlines", "false", set_eval_bool, acc); + s = set_add(&acc->set, "long_ids", "2", set_eval_long_ids, acc); + s->flags |= ACC_SET_OFFLINE_ONLY; + s = set_add(&acc->set, "_last_tweet", "0", NULL, acc); s->flags |= SET_HIDDEN | SET_NOSAVE; @@ -592,6 +604,7 @@ static void twitter_login(account_t * acc) char name[strlen(acc->user) + 9]; url_t url; char *s; + size_t i; if (!url_set(&url, set_getstr(&ic->acc->set, "base_url")) || (url.proto != PROTO_HTTP && url.proto != PROTO_HTTPS)) { @@ -649,7 +662,14 @@ static void twitter_login(account_t * acc) imcb_add_buddy(ic, name, NULL); imcb_buddy_status(ic, name, OPT_LOGGED_IN, NULL, NULL); - td->log = g_new0(struct twitter_log_data, TWITTER_LOG_LENGTH); + td->id_length = set_getint(&ic->acc->set, "long_ids"); + td->log_length = 0; + for (i = 0; i < td->id_length; i++) { + td->log_length = (td->log_length << 4) + 0x0F; + } + td->log_length += 1; + + td->log = g_new0(struct twitter_log_data, td->log_length); td->log_id = -1; s = set_getstr(&ic->acc->set, "mode"); @@ -894,7 +914,7 @@ static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, cha if (arg[0] == '#') { arg++; } - if (parse_int64(arg, 16, &id) && id < TWITTER_LOG_LENGTH) { + if (parse_int64(arg, 16, &id) && id < td->log_length) { bu = td->log[id].bu; id = td->log[id].id; } else if (parse_int64(arg, 10, &id)) { diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h index 86c88262..22b9d561 100644 --- a/protocols/twitter/twitter.h +++ b/protocols/twitter/twitter.h @@ -84,6 +84,9 @@ struct twitter_data { /* set show_ids */ struct twitter_log_data *log; int log_id; + + int id_length; + int log_length; }; #define TWITTER_FILTER_UPDATE_WAIT 3000 @@ -99,7 +102,6 @@ struct twitter_user_data { time_t last_time; }; -#define TWITTER_LOG_LENGTH 256 struct twitter_log_data { guint64 id; /* DANGER: bu can be a dead pointer. Check it first. diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index 77f487ae..51963d39 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -790,7 +790,7 @@ static char *twitter_msg_add_id(struct im_connection *ic, if (txs->reply_to) { int i; - for (i = 0; i < TWITTER_LOG_LENGTH; i++) { + for (i = 0; i < td->log_length; i++) { if (td->log[i].id == txs->reply_to) { reply_to = i; break; @@ -808,7 +808,7 @@ static char *twitter_msg_add_id(struct im_connection *ic, } } - td->log_id = (td->log_id + 1) % TWITTER_LOG_LENGTH; + td->log_id = (td->log_id + 1) % td->log_length; td->log[td->log_id].id = txs->id; td->log[td->log_id].bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name); @@ -823,11 +823,12 @@ static char *twitter_msg_add_id(struct im_connection *ic, if (set_getbool(&ic->acc->set, "show_ids")) { if (reply_to != -1) { - return g_strdup_printf("\002[\002%02x->%02x\002]\002 %s%s", - td->log_id, reply_to, prefix, txs->text); + return g_strdup_printf("\002[\002%0*x->%0*x\002]\002 %s%s", + td->id_length, td->log_id, td->id_length, + reply_to, prefix, txs->text); } else { - return g_strdup_printf("\002[\002%02x\002]\002 %s%s", - td->log_id, prefix, txs->text); + return g_strdup_printf("\002[\002%0*x\002]\002 %s%s", + td->id_length, td->log_id, prefix, txs->text); } } else { if (*prefix) { @@ -1092,7 +1093,7 @@ static gboolean twitter_stream_handle_status(struct im_connection *ic, struct tw struct twitter_data *td = ic->proto_data; int i; - for (i = 0; i < TWITTER_LOG_LENGTH; i++) { + for (i = 0; i < td->log_length; i++) { if (td->log[i].id == txs->id) { /* Got a duplicate (RT, probably). Drop it. */ return TRUE; |